diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/lib/banzai | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/lib/banzai')
4 files changed, 106 insertions, 1 deletions
diff --git a/spec/lib/banzai/filter/ascii_doc_sanitization_filter_spec.rb b/spec/lib/banzai/filter/ascii_doc_sanitization_filter_spec.rb new file mode 100644 index 00000000000..272b4386ec8 --- /dev/null +++ b/spec/lib/banzai/filter/ascii_doc_sanitization_filter_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Banzai::Filter::AsciiDocSanitizationFilter do + include FilterSpecHelper + + it 'preserves footnotes refs' do + result = filter('<p>This paragraph has a footnote.<sup>[<a id="_footnoteref_1" href="#_footnotedef_1" title="View footnote.">1</a>]</sup></p>').to_html + expect(result).to eq('<p>This paragraph has a footnote.<sup>[<a id="_footnoteref_1" href="#_footnotedef_1" title="View footnote.">1</a>]</sup></p>') + end + + it 'preserves footnotes defs' do + result = filter('<div id="_footnotedef_1"> +<a href="#_footnoteref_1">1</a>. This is the text of the footnote.</div>').to_html + expect(result).to eq(%(<div id="_footnotedef_1"> +<a href="#_footnoteref_1">1</a>. This is the text of the footnote.</div>)) + end + + it 'preserves user-content- prefixed ids on anchors' do + result = filter('<p><a id="user-content-cross-references"></a>A link to another location within an AsciiDoc document.</p>').to_html + expect(result).to eq(%(<p><a id="user-content-cross-references"></a>A link to another location within an AsciiDoc document.</p>)) + end + + it 'preserves user-content- prefixed ids on div (blocks)' do + html_content = <<~HTML + <div id="user-content-open-block" class="openblock"> + <div class="content"> + <div class="paragraph"> + <p>This is an open block</p> + </div> + </div> + </div> + HTML + output = <<~SANITIZED_HTML + <div id="user-content-open-block"> + <div> + <div> + <p>This is an open block</p> + </div> + </div> + </div> + SANITIZED_HTML + expect(filter(html_content).to_html).to eq(output) + end + + it 'preserves section anchor ids' do + result = filter(%(<h2 id="user-content-first-section"> +<a class="anchor" href="#user-content-first-section"></a>First section</h2>)).to_html + expect(result).to eq(%(<h2 id="user-content-first-section"> +<a class="anchor" href="#user-content-first-section"></a>First section</h2>)) + end + + it 'removes non prefixed ids' do + result = filter('<p><a id="cross-references"></a>A link to another location within an AsciiDoc document.</p>').to_html + expect(result).to eq(%(<p><a></a>A link to another location within an AsciiDoc document.</p>)) + end +end diff --git a/spec/lib/banzai/filter/kroki_filter_spec.rb b/spec/lib/banzai/filter/kroki_filter_spec.rb new file mode 100644 index 00000000000..57caba1d4d7 --- /dev/null +++ b/spec/lib/banzai/filter/kroki_filter_spec.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Banzai::Filter::KrokiFilter do + include FilterSpecHelper + + it 'replaces nomnoml pre tag with img tag if kroki is enabled' do + stub_application_setting(kroki_enabled: true, kroki_url: "http://localhost:8000") + doc = filter("<pre lang='nomnoml'><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:>[foul mouth]\n]</code></pre>") + + expect(doc.to_s).to eq '<img src="http://localhost:8000/nomnoml/svg/eNqLDsgsSixJrUmtTHXOL80rsVLwzCupKUrMTNHQtC7IzMlJTE_V0KzhUlCITkpNLEqJ1dWNLkgsKsoviUUSs7KLTssvzVHIzS8tyYjligUAMhEd0g==">' + end + + it 'replaces nomnoml pre tag with img tag if both kroki and plantuml are enabled' do + stub_application_setting(kroki_enabled: true, + kroki_url: "http://localhost:8000", + plantuml_enabled: true, + plantuml_url: "http://localhost:8080") + doc = filter("<pre lang='nomnoml'><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:>[foul mouth]\n]</code></pre>") + + expect(doc.to_s).to eq '<img src="http://localhost:8000/nomnoml/svg/eNqLDsgsSixJrUmtTHXOL80rsVLwzCupKUrMTNHQtC7IzMlJTE_V0KzhUlCITkpNLEqJ1dWNLkgsKsoviUUSs7KLTssvzVHIzS8tyYjligUAMhEd0g==">' + end + + it 'does not replace nomnoml pre tag with img tag if kroki is disabled' do + stub_application_setting(kroki_enabled: false) + doc = filter("<pre lang='nomnoml'><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:>[foul mouth]\n]</code></pre>") + + expect(doc.to_s).to eq "<pre lang=\"nomnoml\"><code>[Pirate|eyeCount: Int|raid();pillage()|\n [beard]--[parrot]\n [beard]-:>[foul mouth]\n]</code></pre>" + end + + it 'does not replace plantuml pre tag with img tag if both kroki and plantuml are enabled' do + stub_application_setting(kroki_enabled: true, + kroki_url: "http://localhost:8000", + plantuml_enabled: true, + plantuml_url: "http://localhost:8080") + doc = filter("<pre lang='plantuml'><code>Bob->Alice : hello</code></pre>") + + expect(doc.to_s).to eq '<pre lang="plantuml"><code>Bob->Alice : hello</code></pre>' + end +end diff --git a/spec/lib/banzai/filter/markdown_filter_spec.rb b/spec/lib/banzai/filter/markdown_filter_spec.rb index 8d01a651651..c5e84a0c1e7 100644 --- a/spec/lib/banzai/filter/markdown_filter_spec.rb +++ b/spec/lib/banzai/filter/markdown_filter_spec.rb @@ -46,6 +46,12 @@ RSpec.describe Banzai::Filter::MarkdownFilter do expect(result).to start_with('<pre><code lang="日">') end + + it 'works with additional language parameters' do + result = filter("```ruby:red gem\nsome code\n```", no_sourcepos: true) + + expect(result).to start_with('<pre><code lang="ruby:red gem">') + end end end diff --git a/spec/lib/banzai/pipeline/jira_import/adf_commonmark_pipeline_spec.rb b/spec/lib/banzai/pipeline/jira_import/adf_commonmark_pipeline_spec.rb index d8841a9753e..74005adf673 100644 --- a/spec/lib/banzai/pipeline/jira_import/adf_commonmark_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/jira_import/adf_commonmark_pipeline_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe Banzai::Pipeline::JiraImport::AdfCommonmarkPipeline do let_it_be(:fixtures_path) { 'lib/kramdown/atlassian_document_format' } - it 'converts text in Atlassian Document Format ' do + it 'converts text in Atlassian Document Format' do source = fixture_file(File.join(fixtures_path, 'paragraph.json')) target = fixture_file(File.join(fixtures_path, 'paragraph.md')) output = described_class.call(source, {})[:output] |