diff --git a/lib/chatwoot_markdown_renderer.rb b/lib/chatwoot_markdown_renderer.rb index 2177f8b8f..db3e03a91 100644 --- a/lib/chatwoot_markdown_renderer.rb +++ b/lib/chatwoot_markdown_renderer.rb @@ -12,7 +12,7 @@ class ChatwootMarkdownRenderer def render_article markdown_renderer = CustomMarkdownRenderer.new - doc = CommonMarker.render_doc(@content, :DEFAULT) + doc = CommonMarker.render_doc(@content, :DEFAULT, [:table]) html = markdown_renderer.render(doc) render_as_html_safe(html) diff --git a/spec/lib/chatwoot_markdown_renderer_spec.rb b/spec/lib/chatwoot_markdown_renderer_spec.rb index cbfc4c6fe..f11568f43 100644 --- a/spec/lib/chatwoot_markdown_renderer_spec.rb +++ b/spec/lib/chatwoot_markdown_renderer_spec.rb @@ -16,6 +16,10 @@ RSpec.describe ChatwootMarkdownRenderer do end describe '#render_article' do + before do + allow(CommonMarker).to receive(:render_doc).with(markdown_content, :DEFAULT, [:table]).and_return(doc) + end + let(:rendered_content) { renderer.render_article } it 'renders the markdown content to html' do @@ -25,6 +29,38 @@ RSpec.describe ChatwootMarkdownRenderer do it 'returns an html safe string' do expect(rendered_content).to be_html_safe end + + context 'when tables in markdown' do + let(:markdown_content) do + <<~MARKDOWN + This is a **bold** text and *italic* text. + + | Header1 | Header2 | + | ------------ | ------------ | + | **Bold Cell**| *Italic Cell*| + | Cell3 | Cell4 | + MARKDOWN + end + + let(:html_content) do + <<~HTML +

This is a bold text and italic text.

+ + + + + + + + +
Header1Header2
Bold CellItalic Cell
Cell3Cell4
+ HTML + end + + it 'renders tables in html' do + expect(rendered_content.to_s).to eq(html_content) + end + end end describe '#render_message' do