blob: 1a76b58bc4382804e06bfdb5ee240579bc29e731 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Banzai::Filter::AsciiDocSanitizationFilter, feature_category: :wiki 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
|