Skip to content

Commit

Permalink
feat: Adds backend support for rendering tables in articles (#9526)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsivin committed May 24, 2024
1 parent eafd3ae commit 7c5e67b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chatwoot_markdown_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def render_message

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)
Expand Down
36 changes: 36 additions & 0 deletions spec/lib/chatwoot_markdown_renderer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
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
Expand All @@ -25,6 +29,38 @@
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
<p>This is a <strong>bold</strong> text and <em>italic</em> text.</p>
<table>
<thead>
<tr><th>Header1</th><th>Header2</th></tr>
</thead>
<tbody>
<tr><td><strong>Bold Cell</strong></td><td><em>Italic Cell</em></td></tr>
<tr><td>Cell3</td><td>Cell4</td></tr>
</tbody>
</table>
HTML
end

it 'renders tables in html' do
expect(rendered_content.to_s).to eq(html_content)
end
end
end

describe '#render_message' do
Expand Down

0 comments on commit 7c5e67b

Please sign in to comment.