Created
November 6, 2023 10:58
-
-
Save KeithP/5f959ca70f0b09a1ce5b5cf4831829f6 to your computer and use it in GitHub Desktop.
MarkdownTemplateHandler fixed for Rails 7.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/markdown_template_handler.rb | |
module MarkdownTemplateHandler | |
def self.call( template, source=nil ) | |
source ||= template.source | |
# This worked prior to Rails 7.1: | |
# compiled_source = erb.call( template, source ) | |
# But with Rails 7.1 it threw "ActionView::Template::Error: wrong argument type ActionView::OutputBuffer (expected String)" | |
# Because the '.to_s' had been removed in Rails 7.1 by this commit: https://github.com/rails/rails/commit/ee68644c284aa7512d06b4b5514b1236c1b63f55 | |
# So now you need to add it back to make it work with Redcarpet 3.6: | |
compiled_source = ActionView::OutputBuffer.new( erb.call( template, source ) ) | |
compiled_source << '.to_s' | |
"Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render(begin;#{compiled_source};end).html_safe" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment