fix: Email Channel links are not working (backend) (#13898)
# Pull Request Template ## Description This PR fixes the link formatting issue on the backend by adding `:autolink` to `ChatwootMarkdownRenderer#render_message`, ensuring all URLs are converted to `<a>` tags. Fixes https://linear.app/chatwoot/issue/CW-6682/email-channel-links-are-not-working ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
@@ -5,7 +5,7 @@ class ChatwootMarkdownRenderer
|
||||
|
||||
def render_message
|
||||
markdown_renderer = BaseMarkdownRenderer.new
|
||||
doc = CommonMarker.render_doc(@content, :DEFAULT, [:strikethrough])
|
||||
doc = CommonMarker.render_doc(@content, :DEFAULT, [:strikethrough, :autolink])
|
||||
html = markdown_renderer.render(doc)
|
||||
render_as_html_safe(html)
|
||||
end
|
||||
|
||||
@@ -6,11 +6,9 @@ RSpec.describe ChatwootMarkdownRenderer do
|
||||
let(:doc) { instance_double(CommonMarker::Node) }
|
||||
let(:renderer) { described_class.new(markdown_content) }
|
||||
let(:markdown_renderer) { instance_double(CustomMarkdownRenderer) }
|
||||
let(:base_markdown_renderer) { instance_double(BaseMarkdownRenderer) }
|
||||
let(:html_content) { '<p>This is a <em>test</em> content with <sup>markdown</sup></p>' }
|
||||
|
||||
before do
|
||||
allow(CommonMarker).to receive(:render_doc).with(markdown_content, :DEFAULT, [:strikethrough]).and_return(doc)
|
||||
allow(CustomMarkdownRenderer).to receive(:new).and_return(markdown_renderer)
|
||||
allow(markdown_renderer).to receive(:render).with(doc).and_return(html_content)
|
||||
end
|
||||
@@ -64,22 +62,28 @@ RSpec.describe ChatwootMarkdownRenderer do
|
||||
end
|
||||
|
||||
describe '#render_message' do
|
||||
let(:message_html_content) { '<p>This is a <em>test</em> content with ^markdown^</p>' }
|
||||
let(:rendered_message) { renderer.render_message }
|
||||
|
||||
before do
|
||||
allow(CommonMarker).to receive(:render_html).with(markdown_content).and_return(message_html_content)
|
||||
allow(BaseMarkdownRenderer).to receive(:new).and_return(base_markdown_renderer)
|
||||
allow(base_markdown_renderer).to receive(:render).with(doc).and_return(message_html_content)
|
||||
allow(CommonMarker).to receive(:render_doc).and_call_original
|
||||
allow(BaseMarkdownRenderer).to receive(:new).and_call_original
|
||||
end
|
||||
|
||||
it 'renders the markdown message to html' do
|
||||
expect(rendered_message.to_s).to eq(message_html_content)
|
||||
expect(rendered_message.to_s).to eq("<p>This is a <em>test</em> content with ^markdown^</p>\n")
|
||||
end
|
||||
|
||||
it 'returns an html safe string' do
|
||||
expect(rendered_message).to be_html_safe
|
||||
end
|
||||
|
||||
context 'with bare URLs' do
|
||||
let(:markdown_content) { 'Visit https://example.com for details' }
|
||||
|
||||
it 'converts bare URLs to links' do
|
||||
expect(renderer.render_message.to_s).to eq("<p>Visit <a href=\"https://example.com\">https://example.com</a> for details</p>\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#render_markdown_to_plain_text' do
|
||||
|
||||
Reference in New Issue
Block a user