Use Redcarpet for plain text rendering

This commit is contained in:
Jose Farias
2024-12-18 16:39:56 -06:00
parent 0139f71bf2
commit 7d83874266
3 changed files with 8 additions and 5 deletions
+3
View File
@@ -1,4 +1,7 @@
ActiveSupport.on_load :action_text_markdown do
require "markdown_renderer"
require "redcarpet/render_strip"
ActionText::Markdown.html_renderer = ->(content) { MarkdownRenderer.build.render(content) }
ActionText::Markdown.plain_text_renderer = Redcarpet::Markdown.new(Redcarpet::Render::StripDown)
end
+4 -4
View File
@@ -1,7 +1,7 @@
module ActionText
class Markdown < Record
mattr_accessor :html_renderer
mattr_accessor :plain_renderer
mattr_accessor :plain_text_renderer
belongs_to :record, polymorphic: true, touch: true
@@ -18,10 +18,10 @@ module ActionText
end
def to_plain_text
if plain_renderer.respond_to? :call
plain_renderer.call content
if plain_text_renderer.respond_to? :call
plain_text_renderer.call content
else
plain_renderer.render content
plain_text_renderer.render content
end
end
end
+1 -1
View File
@@ -10,7 +10,7 @@ class BubbleTest < ActiveSupport::TestCase
bubbles(:logo).capture Comment.new(body: "Agreed.")
end
assert_equal "Agreed.", bubbles(:logo).messages.last.messageable.body.to_plain_text
assert_equal "Agreed.", bubbles(:logo).messages.last.messageable.body.to_plain_text.chomp
end
test "boosting" do