diff options
Diffstat (limited to 'spec/lib/banzai/filter/ascii_doc_sanitization_filter_spec.rb')
-rw-r--r-- | spec/lib/banzai/filter/ascii_doc_sanitization_filter_spec.rb | 58 |
1 files changed, 58 insertions, 0 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 |