diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4237ac32c..a2a0b2e80 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,7 +7,7 @@ def block_code(code, language) end MARKDOWN_RENDERER = Redcarpet::Markdown.new( - MarkdownRenderer.new(filter_html: true, hard_wrap: true), + MarkdownRenderer.new(filter_html: true, hard_wrap: true, link_attributes: { 'data-turbo' => 'false' }), fenced_code_blocks: true, no_intra_emphasis: true, autolink: true, diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb new file mode 100644 index 000000000..621b1db99 --- /dev/null +++ b/spec/helpers/application_helper_spec.rb @@ -0,0 +1,18 @@ +require 'rails_helper' + +RSpec.describe ApplicationHelper, type: :helper do + describe '#markdown' do + it 'opts explicit links out of Turbo so they escape a surrounding turbo-frame' do + html = helper.markdown('see [example](https://example.com)') + + expect(html).to include('href="https://example.com"') + expect(html).to include('data-turbo="false"') + end + + it 'applies the same attribute to autolinked bare URLs' do + html = helper.markdown('visit https://example.com now') + + expect(html).to include('data-turbo="false"') + end + end +end