RSpec.describe Redcarpet::TrustedRenderer do let(:view_context) { ActionController::Base.new.view_context } subject(:renderer) { Redcarpet::Markdown.new(described_class.new(view_context), autolink: true) } context 'when rendering links' do it 'renders internal links without target and rel attributes' do markdown = "[Click here](/internal)" expect(renderer.render(markdown)).to include('Click here') end it 'renders external links with target="_blank" and rel="noopener noreferrer"' do markdown = "[Visit](http://example.com)" expect(renderer.render(markdown)).to include('Visit') end end context 'when rendering images' do it 'renders an image tag with lazy loading' do markdown = "![A cute cat](http://example.com/cat.jpg)" expect(renderer.render(markdown)).to include('') end it 'renders additional attribute' do markdown = "![A cute cat { aria-hidden=\"true\" }](http://example.com/cat.jpg)" expect(renderer.render(markdown)).to include('') end end context 'when autolinking' do it 'autolinks URLs' do markdown = "Visit http://example.com" expect(renderer.render(markdown)).to include('Visit http://example.com') end it 'autolinks email addresses with mailto' do markdown = "Email user@example.com" expect(renderer.render(markdown)).to include('user@example.com') end end context 'with block_quote DSFR alert' do it 'renders [!INFO] blocks as DSFR info alerts' do markdown = "> [!INFO]\n> This is an information alert with *emphasis*." expected_html = <<~HTML
This is an information alert with emphasis.
This is a warning alert.