/
remark_spec.rb
184 lines (155 loc) · 6.15 KB
/
remark_spec.rb
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
require 'remark'
describe Remark do
def remark(source, options = {})
options = {:inline_links => true}.merge(options)
described_class.new(source, options).to_markdown
end
it "should let through text content" do
remark("Foo bar").should == 'Foo bar'
remark("Foo bar\nbaz").should == 'Foo bar baz'
end
it "should split paragraphs with an empty line" do
remark("<p>Foo bar</p>").should == 'Foo bar'
remark("<p>Foo bar</p><p>baz").should == "Foo bar\n\nbaz"
remark("<p>Foo bar</p>baz").should == "Foo bar\n\nbaz"
end
it "should output title syntax" do
remark("<h1>Foo bar</h1>").should == '# Foo bar'
remark("<h2>Foo bar</h2>").should == '## Foo bar'
end
it "should preserve elements in remarked blocks" do
remark("<p>Foo <ins>bar</ins></p>").should == 'Foo <ins>bar</ins>'
remark("<h2>Foo <ins>bar</ins></h2>").should == '## Foo <ins>bar</ins>'
end
it "should unescape HTML entities" do
remark("Foo&bar").should == 'Foo&bar'
remark("<p>If you’re doing all your development on the “master” branch, you’re not using git").should == "If you’re doing all your development on the “master” branch, you’re not using git"
end
it "should ignore tags without user-facing content" do
remark("<script>foo</script>").should == ''
remark("<head>foo</head>").should == ''
end
it "should leave known elements with attributes intact" do
remark("<p class='notice'>Kittens attack!</p>").should == '<p class="notice">Kittens attack!</p>'
end
it "should leave unknown elements intact" do
remark(<<-HTML).should == "Foo\n\n<table>data</table>\n\nBar"
<p>Foo</p>
<table>data</table>
<p>Bar</p>
HTML
end
it "should ignore DIVs when specified" do
remark("<p>Foo</p> <div><p>Bar</p><p>Baz</p></div>").should == "Foo\n\nBar\n\nBaz"
end
it "should strip excess whitespace" do
remark(<<-HTML).should == "Foo bar"
<p>
Foo
bar
</p>
HTML
end
it "should strip whitespace in text nodes between processed nodes" do
pending
remark(<<-HTML).should == "Foo\n\nbar\n\nBaz"
<p>Foo</p>
bar
<p>Baz</p>
HTML
end
it "should support lists" do
remark(<<-HTML).should == "* foo\n* bar"
<ul>
<li>foo</li>
<li>bar</li>
</ul>
HTML
remark(<<-HTML).should == "1. foo\n2. bar"
<ol>
<li>foo</li>
<li>bar</li>
</ol>
HTML
end
it "should support lists with nested content" do
remark(<<-HTML).should == "* foo\n \n bar\n\n* baz"
<ul>
<li><p>foo</p><p>bar</p></li>
<li><p>baz</p></li>
</ul>
HTML
end
it "should support preformatted blocks" do
remark("<pre>def foo\n bar\nend</pre>").should == " def foo\n bar\n end"
remark("<pre><code>def foo\n <bar>\nend</code></pre>").should == " def foo\n <bar>\n end"
remark("<pre>def foo\n</pre>").should == " def foo"
end
it "should remark inline elements" do
remark("<p>I'm so <strong>strong</strong></p>").should == "I'm so **strong**"
remark("<p>I'm so <em>emo</em></p>").should == "I'm so _emo_"
remark("<ul><li><em>Inline</em> stuff in <strong>lists</strong></li></ul>").should == "* _Inline_ stuff in **lists**"
remark("<h1>Headings <em>too</em></h1>").should == '# Headings _too_'
end
it "should remark inline code" do
remark("<p>Write more <code>code</code></p>").should == "Write more `code`"
remark("<p>Even with <code>`backticks`</code></p>").should == "Even with `` `backticks` ``"
remark("<p>Or HTML <code><tags></code></p>").should == "Or HTML `<tags>`"
end
it "should handle nested inline elements" do
remark("<p>I <strong>love <code>code</code></strong></p>").should == "I **love `code`**"
remark("<p>I <a href='#'>am <em>fine</em></a></p>").should == "I [am _fine_](#)"
end
it "should support hyperlinks" do
remark("<p>Click <a href='http://mislav.uniqpath.com'>here</a></p>").should ==
"Click [here](http://mislav.uniqpath.com)"
remark("<a href='/foo' title='bar'>baz</a>").should == '[baz](/foo "bar")'
end
it "should have reference-style hyperlinks" do
remark("<p>Click <a href='foo' title='mooslav'>here</a> and <a href='bar'>there</a></p>", :inline_links => false).should ==
"Click [here][1] and [there][2]\n\n[1]: foo \"mooslav\"\n[2]: bar"
remark("<p>Click <a href='foo'>here</a> and <a href='foo'>there</a></p>", :inline_links => false).should ==
"Click [here][1] and [there][1]\n\n[1]: foo"
end
it "should support blockquotes" do
remark("<blockquote>Cogito, ergo sum</blockquote>").should == '> Cogito, ergo sum'
remark("<blockquote><p>I think</p><p>therefore I am</p></blockquote>").should == "> I think\n> \n> therefore I am"
end
it "should support image tags" do
remark("<img src='moo.jpg' alt='cow'>").should == '![cow](moo.jpg)'
remark("<img src='moo.jpg' alt='cow' width='16'>").should == '<img src="moo.jpg" alt="cow" width="16" />'
end
it "should not have BR ruin all the fun" do
remark("<p>Foo<br>bar</p>").should == "Foo \nbar"
remark("<p>Foo<br>\nbar <code>baz</code></p>").should == "Foo \nbar `baz`"
remark("<p>Foo</p><br><p>Bar</p>").should == "Foo\n\nBar"
end
describe "scoping" do
before do
@html = <<-HTML
<html>
<body>
<div id="div1">
<p>Only 1 paragraph</p>
</div>
<div id="div3">
<p>Wow, 3 paragraphs</p>
<p>This must be where the content is</p>
<p>I'm sure</p>
</div>
<div id="div2">
<p>Only 2 paragraphs</p>
<p>How disappointing</p>
</div>
</body>
</html>
HTML
end
it "should scope to the most likely element that holds content" do
remark(@html).should == "Wow, 3 paragraphs\n\nThis must be where the content is\n\nI'm sure"
end
it "should scope to the explicit scope" do
remark(@html, :scope => '#div2').should == "Only 2 paragraphs\n\nHow disappointing"
end
end
end