summaryrefslogtreecommitdiff
path: root/spec/lib/banzai
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2019-01-28 17:19:23 +0000
committerRobert Speicher <rspeicher@gmail.com>2019-01-28 17:19:23 +0000
commita24551964180614bb9b19417763996043edba25f (patch)
tree543fd1d2b641ab19d2d5c72264c57efbfd737915 /spec/lib/banzai
parent4f8bdb01c7e5f02a0ae79cd2641465e45350faf6 (diff)
parent7bc0fbe22f0dd2c96b596b591ef5dbf3eaae8dd3 (diff)
downloadgitlab-ce-a24551964180614bb9b19417763996043edba25f.tar.gz
Merge branch 'bw-enable-sourcepos' into 'master'
Enable CommonMark source line position information See merge request gitlab-org/gitlab-ce!23971
Diffstat (limited to 'spec/lib/banzai')
-rw-r--r--spec/lib/banzai/filter/markdown_filter_spec.rb46
-rw-r--r--spec/lib/banzai/filter/sanitization_filter_spec.rb7
-rw-r--r--spec/lib/banzai/pipeline/description_pipeline_spec.rb4
-rw-r--r--spec/lib/banzai/pipeline/full_pipeline_spec.rb2
4 files changed, 52 insertions, 7 deletions
diff --git a/spec/lib/banzai/filter/markdown_filter_spec.rb b/spec/lib/banzai/filter/markdown_filter_spec.rb
index cf49249756a..4c4e821deab 100644
--- a/spec/lib/banzai/filter/markdown_filter_spec.rb
+++ b/spec/lib/banzai/filter/markdown_filter_spec.rb
@@ -30,21 +30,21 @@ describe Banzai::Filter::MarkdownFilter do
end
it 'adds language to lang attribute when specified' do
- result = filter("```html\nsome code\n```")
+ result = filter("```html\nsome code\n```", no_sourcepos: true)
- expect(result).to start_with("<pre><code lang=\"html\">")
+ expect(result).to start_with('<pre><code lang="html">')
end
it 'does not add language to lang attribute when not specified' do
- result = filter("```\nsome code\n```")
+ result = filter("```\nsome code\n```", no_sourcepos: true)
- expect(result).to start_with("<pre><code>")
+ expect(result).to start_with('<pre><code>')
end
it 'works with utf8 chars in language' do
- result = filter("```日\nsome code\n```")
+ result = filter("```日\nsome code\n```", no_sourcepos: true)
- expect(result).to start_with("<pre><code lang=\"日\">")
+ expect(result).to start_with('<pre><code lang="日">')
end
end
@@ -67,6 +67,38 @@ describe Banzai::Filter::MarkdownFilter do
end
end
+ describe 'source line position' do
+ context 'using CommonMark' do
+ before do
+ stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :common_mark)
+ end
+
+ it 'defaults to add data-sourcepos' do
+ result = filter('test')
+
+ expect(result).to eq '<p data-sourcepos="1:1-1:4">test</p>'
+ end
+
+ it 'disables data-sourcepos' do
+ result = filter('test', no_sourcepos: true)
+
+ expect(result).to eq '<p>test</p>'
+ end
+ end
+
+ context 'using Redcarpet' do
+ before do
+ stub_const('Banzai::Filter::MarkdownFilter::DEFAULT_ENGINE', :redcarpet)
+ end
+
+ it 'does not support data-sourcepos' do
+ result = filter('test')
+
+ expect(result).to eq '<p>test</p>'
+ end
+ end
+ end
+
describe 'footnotes in tables' do
it 'processes footnotes in table cells' do
text = <<-MD.strip_heredoc
@@ -77,7 +109,7 @@ describe Banzai::Filter::MarkdownFilter do
[^1]: a footnote
MD
- result = filter(text)
+ result = filter(text, no_sourcepos: true)
expect(result).to include('<td>foot <sup')
expect(result).to include('<section class="footnotes">')
diff --git a/spec/lib/banzai/filter/sanitization_filter_spec.rb b/spec/lib/banzai/filter/sanitization_filter_spec.rb
index 836af18e0b6..f2a5d7b2c9f 100644
--- a/spec/lib/banzai/filter/sanitization_filter_spec.rb
+++ b/spec/lib/banzai/filter/sanitization_filter_spec.rb
@@ -301,6 +301,13 @@ describe Banzai::Filter::SanitizationFilter do
expect(act.to_html).to eq exp
end
+ it 'allows the `data-sourcepos` attribute globally' do
+ exp = %q{<p data-sourcepos="1:1-1:10">foo/bar.md</p>}
+ act = filter(exp)
+
+ expect(act.to_html).to eq exp
+ end
+
describe 'footnotes' do
it 'allows correct footnote id property on links' do
exp = %q{<a href="#fn1" id="fnref1">foo/bar.md</a>}
diff --git a/spec/lib/banzai/pipeline/description_pipeline_spec.rb b/spec/lib/banzai/pipeline/description_pipeline_spec.rb
index 8cce1b96698..77cb1954ea3 100644
--- a/spec/lib/banzai/pipeline/description_pipeline_spec.rb
+++ b/spec/lib/banzai/pipeline/description_pipeline_spec.rb
@@ -13,6 +13,10 @@ describe Banzai::Pipeline::DescriptionPipeline do
output
end
+ before do
+ stub_commonmark_sourcepos_disabled
+ end
+
it 'uses a limited whitelist' do
doc = parse('# Description')
diff --git a/spec/lib/banzai/pipeline/full_pipeline_spec.rb b/spec/lib/banzai/pipeline/full_pipeline_spec.rb
index 3634655c6a5..aa503b6e1d5 100644
--- a/spec/lib/banzai/pipeline/full_pipeline_spec.rb
+++ b/spec/lib/banzai/pipeline/full_pipeline_spec.rb
@@ -54,6 +54,8 @@ describe Banzai::Pipeline::FullPipeline do
end
it 'properly adds the necessary ids and classes' do
+ stub_commonmark_sourcepos_disabled
+
expect(html.lines.map(&:strip).join("\n")).to eq filtered_footnote
end
end