Skip to content

Commit

Permalink
Fix Rails >=7.1 / RedCarpet incompatibility bug
Browse files Browse the repository at this point in the history
  • Loading branch information
steventux committed Feb 1, 2024
1 parent 99e76ff commit cf8a32f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/initializers/govuk_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

class MarkdownTemplate
def self.call(template, source)
source ||= template.source

# Rails >= 7.1 does not work with the Redcarpet markdown renderer.
# There is an argument mismatch where a string is expected but an OutputBuffer is provided.
# This is a workaround to convert the buffer to a string.
erb_handler = ActionView::Template.registered_template_handler(:erb)
compiled_source = erb_handler.call(template, source)
compiled_source = ActionView::OutputBuffer.new( erb_handler.call( template, source ) )
compiled_source << '.to_s'
"GovukMarkdown.render(begin;#{compiled_source};end).html_safe"
end
end
Expand Down

0 comments on commit cf8a32f

Please sign in to comment.