diff options
Diffstat (limited to 'spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb')
-rw-r--r-- | spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb | 55 |
1 files changed, 41 insertions, 14 deletions
diff --git a/spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb b/spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb index 4903f624469..394fcc06eba 100644 --- a/spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/plain_markdown_pipeline_spec.rb @@ -5,18 +5,7 @@ require 'spec_helper' RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do using RSpec::Parameterized::TableSyntax - describe 'backslash escapes' do - let_it_be(:project) { create(:project, :public) } - let_it_be(:issue) { create(:issue, project: project) } - - def correct_html_included(markdown, expected) - result = described_class.call(markdown, {}) - - expect(result[:output].to_html).to include(expected) - - result - end - + shared_examples_for 'renders correct markdown' do describe 'CommonMark tests', :aggregate_failures do it 'converts all reference punctuation to literals' do reference_chars = Banzai::Filter::MarkdownPreEscapeFilter::REFERENCE_CHARACTERS @@ -32,7 +21,7 @@ RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do expect(result[:escaped_literals]).to be_truthy end - it 'ensure we handle all the GitLab reference characters' do + it 'ensure we handle all the GitLab reference characters', :eager_load do reference_chars = ObjectSpace.each_object(Class).map do |klass| next unless klass.included_modules.include?(Referable) next unless klass.respond_to?(:reference_prefix) @@ -79,10 +68,19 @@ RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do end describe 'work in all other contexts, including URLs and link titles, link references, and info strings in fenced code blocks' do + let(:markdown) { %Q(``` foo\\@bar\nfoo\n```) } + + it 'renders correct html' do + if Feature.enabled?(:use_cmark_renderer) + correct_html_included(markdown, %Q(<pre data-sourcepos="1:1-3:3" lang="foo@bar"><code>foo\n</code></pre>)) + else + correct_html_included(markdown, %Q(<code lang="foo@bar">foo\n</code>)) + end + end + where(:markdown, :expected) do %q![foo](/bar\@ "\@title")! | %q(<a href="/bar@" title="@title">foo</a>) %Q![foo]\n\n[foo]: /bar\\@ "\\@title"! | %q(<a href="/bar@" title="@title">foo</a>) - %Q(``` foo\\@bar\nfoo\n```) | %Q(<code lang="foo@bar">foo\n</code>) end with_them do @@ -91,4 +89,33 @@ RSpec.describe Banzai::Pipeline::PlainMarkdownPipeline do end end end + + describe 'backslash escapes' do + let_it_be(:project) { create(:project, :public) } + let_it_be(:issue) { create(:issue, project: project) } + + def correct_html_included(markdown, expected) + result = described_class.call(markdown, {}) + + expect(result[:output].to_html).to include(expected) + + result + end + + context 'using ruby-based HTML renderer' do + before do + stub_feature_flags(use_cmark_renderer: false) + end + + it_behaves_like 'renders correct markdown' + end + + context 'using c-based HTML renderer' do + before do + stub_feature_flags(use_cmark_renderer: true) + end + + it_behaves_like 'renders correct markdown' + end + end end |