rdiscountwl 1.0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,276 @@
1
+ # encoding: utf-8
2
+ rootdir = File.dirname(File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift "#{rootdir}/lib"
4
+
5
+ require 'test/unit'
6
+ require 'rdiscount'
7
+
8
+ class RDiscountTest < Test::Unit::TestCase
9
+ def test_that_version_looks_valid
10
+ if not /^[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?$/ =~ RDiscount::VERSION
11
+ assert false, 'Expected RDiscount::VERSION to be a 3 or 4 component version string but found ' + RDiscount::VERSION.to_s
12
+ end
13
+ end
14
+
15
+ def test_that_discount_does_not_blow_up_with_weird_formatting_case
16
+ text = (<<-TEXT).gsub(/^ {4}/, '').rstrip
17
+ 1. some text
18
+
19
+ 1.
20
+ TEXT
21
+ RDiscount.new(text).to_html
22
+ end
23
+
24
+ def test_that_smart_converts_double_quotes_to_curly_quotes
25
+ rd = RDiscount.new(%("Quoted text"), :smart)
26
+ assert_equal %(<p>&ldquo;Quoted text&rdquo;</p>\n), rd.to_html
27
+ end
28
+
29
+ def test_that_smart_converts_double_quotes_to_curly_quotes_before_a_heading
30
+ rd = RDiscount.new(%("Quoted text"\n\n# Heading), :smart)
31
+ assert_equal %(<p>&ldquo;Quoted text&rdquo;</p>\n\n<h1>Heading</h1>\n), rd.to_html
32
+ end
33
+
34
+ def test_that_smart_converts_double_quotes_to_curly_quotes_after_a_heading
35
+ rd = RDiscount.new(%(# Heading\n\n"Quoted text"), :smart)
36
+ assert_equal %(<h1>Heading</h1>\n\n<p>&ldquo;Quoted text&rdquo;</p>\n), rd.to_html
37
+ end
38
+
39
+ def test_that_smart_gives_ve_suffix_a_rsquo
40
+ rd = RDiscount.new("I've been meaning to tell you ..", :smart)
41
+ assert_equal "<p>I&rsquo;ve been meaning to tell you ..</p>\n", rd.to_html
42
+ end
43
+
44
+ def test_that_smart_gives_m_suffix_a_rsquo
45
+ rd = RDiscount.new("I'm not kidding", :smart)
46
+ assert_equal "<p>I&rsquo;m not kidding</p>\n", rd.to_html
47
+ end
48
+
49
+ def test_that_smart_gives_d_suffix_a_rsquo
50
+ rd = RDiscount.new("what'd you say?", :smart)
51
+ assert_equal "<p>what&rsquo;d you say?</p>\n", rd.to_html
52
+ end
53
+
54
+ def test_that_generate_toc_sets_toc_ids
55
+ rd = RDiscount.new("# Level 1\n\n## Level 2", :generate_toc)
56
+ assert rd.generate_toc
57
+ assert_equal %(<a name="Level.1"></a>\n<h1>Level 1</h1>\n\n<a name="Level.2"></a>\n<h2>Level 2</h2>\n), rd.to_html
58
+ end
59
+
60
+ def test_should_get_the_generated_toc
61
+ rd = RDiscount.new("# Level 1\n\n## Level 2", :generate_toc)
62
+ exp = %(<ul>\n <li><a href=\"#Level.1\">Level 1</a>\n <ul>\n <li><a href=\"#Level.2\">Level 2</a></li>\n </ul>\n </li>\n</ul>)
63
+ assert_equal exp, rd.toc_content.strip
64
+ end
65
+
66
+ def test_toc_should_escape_apostropes
67
+ rd = RDiscount.new("# A'B\n\n## C", :generate_toc)
68
+ exp = %(<ul>\n <li><a href=\"#A.B\">A'B</a>\n <ul>\n <li><a href=\"#C\">C</a></li>\n </ul>\n </li>\n</ul>)
69
+ assert_equal exp, rd.toc_content.strip
70
+ end
71
+
72
+ def test_toc_should_escape_question_marks
73
+ rd = RDiscount.new("# A?B\n\n## C", :generate_toc)
74
+ exp = %(<ul>\n <li><a href=\"#A.B\">A?B</a>\n <ul>\n <li><a href=\"#C\">C</a></li>\n </ul>\n </li>\n</ul>)
75
+ assert_equal exp, rd.toc_content.strip
76
+ end
77
+
78
+ if "".respond_to?(:encoding)
79
+ def test_should_return_string_in_same_encoding_as_input
80
+ input = "Yogācāra"
81
+ output = RDiscount.new(input).to_html
82
+ assert_equal input.encoding.name, output.encoding.name
83
+ end
84
+ end
85
+
86
+ def test_that_no_image_flag_works
87
+ rd = RDiscount.new(%(![dust mite](http://dust.mite/image.png) <img src="image.png" />), :no_image)
88
+ assert rd.to_html !~ /<img/
89
+ end
90
+
91
+ def test_that_no_links_flag_works
92
+ rd = RDiscount.new(%([This link](http://example.net/) <a href="links.html">links</a>), :no_links)
93
+ assert rd.to_html !~ /<a /
94
+ end
95
+
96
+ def test_that_no_tables_flag_works
97
+ rd = RDiscount.new(<<EOS, :no_tables)
98
+ aaa | bbbb
99
+ -----|------
100
+ hello|sailor
101
+ EOS
102
+ assert rd.to_html !~ /<table/
103
+ end
104
+
105
+ def test_that_strict_flag_works
106
+ rd = RDiscount.new("foo_bar_baz", :strict)
107
+ assert_equal "<p>foo<em>bar</em>baz</p>\n", rd.to_html
108
+ end
109
+
110
+ def test_that_autolink_flag_works
111
+ rd = RDiscount.new("http://github.com/davidfstr/rdiscount", :autolink)
112
+ assert_equal "<p><a href=\"http://github.com/davidfstr/rdiscount\">http://github.com/davidfstr/rdiscount</a></p>\n", rd.to_html
113
+ end
114
+
115
+ def test_that_safelink_flag_works
116
+ rd = RDiscount.new("[IRC](irc://chat.freenode.org/#freenode)", :safelink)
117
+ assert_equal "<p>[IRC](irc://chat.freenode.org/#freenode)</p>\n", rd.to_html
118
+ end
119
+
120
+ def test_that_no_pseudo_protocols_flag_works
121
+ rd = RDiscount.new("[foo](id:bar)", :no_pseudo_protocols)
122
+ assert_equal "<p>[foo](id:bar)</p>\n", rd.to_html
123
+ end
124
+
125
+ def test_that_no_superscript_flag_works
126
+ rd = RDiscount.new("A^B", :no_superscript)
127
+ assert_equal "<p>A^B</p>\n", rd.to_html
128
+
129
+ rd = RDiscount.new("A^B")
130
+ assert_equal "<p>A<sup>B</sup></p>\n", rd.to_html
131
+ end
132
+
133
+ def test_that_no_strikethrough_flag_works
134
+ rd = RDiscount.new("~~A~~", :no_strikethrough)
135
+ assert_equal "<p>~~A~~</p>\n", rd.to_html
136
+
137
+ rd = RDiscount.new("~~A~~")
138
+ assert_equal "<p><del>A</del></p>\n", rd.to_html
139
+ end
140
+
141
+ def test_that_tags_can_have_dashes_and_underscores
142
+ if RDiscount::VERSION.start_with? "2.0.7"
143
+ # Skip test for 2.0.7.x series due to upstream behavioral change in
144
+ # Discount 2.0.7. This test can be fixed in Discount 2.1.5 using the
145
+ # WITH_GITHUB_TAGS compile-time flag.
146
+ return
147
+ end
148
+ rd = RDiscount.new("foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b>")
149
+ assert_equal "<p>foo <asdf-qwerty>bar</asdf-qwerty> and <a_b>baz</a_b></p>\n", rd.to_html
150
+ end
151
+
152
+ def test_that_footnotes_flag_works
153
+ rd = RDiscount.new(<<EOS, :footnotes)
154
+ Obtuse text.[^1]
155
+
156
+ [^1]: Clarification
157
+ EOS
158
+ assert rd.to_html.include?('<a href="#fn:1" rel="footnote">1</a>')
159
+ end
160
+
161
+ def test_that_footnotes_in_span_works
162
+ rd = RDiscount.new(<<EOS, :footnotes)
163
+ [Obtuse text.[^1]](class:someclass)
164
+
165
+ [^1]: Clarification
166
+ EOS
167
+ assert rd.to_html.include?('<a href="#fn:1" rel="footnote">1</a>')
168
+ end
169
+
170
+ def test_that_unicode_urls_encoded_correctly
171
+ rd = RDiscount.new("[Test](http://example.com/ß)")
172
+ assert_equal "<p><a href=\"http://example.com/%C3%9F\">Test</a></p>\n", rd.to_html
173
+ end
174
+
175
+ def test_that_dashes_encoded_correctly
176
+ rd = RDiscount.new("A--B", :smart)
177
+ assert_equal "<p>A&ndash;B</p>\n", rd.to_html
178
+
179
+ rd = RDiscount.new("A---B", :smart)
180
+ assert_equal "<p>A&mdash;B</p>\n", rd.to_html
181
+ end
182
+
183
+ def test_that_superscripts_can_be_escaped
184
+ rd = RDiscount.new("A\\^B")
185
+ assert_equal "<p>A^B</p>\n", rd.to_html
186
+
187
+ rd = RDiscount.new("A^B")
188
+ assert_equal "<p>A<sup>B</sup></p>\n", rd.to_html
189
+ end
190
+
191
+ def test_that_style_tag_is_not_filtered_by_default
192
+ rd = RDiscount.new("Hello<style>p { margin: 5px; }</style>")
193
+ assert_equal "<p>Hello<style>p { margin: 5px; }</style></p>\n", rd.to_html
194
+ end
195
+
196
+ def test_that_tables_can_have_leading_and_trailing_pipes
197
+ rd = RDiscount.new(<<EOS)
198
+ | A | B |
199
+ |---|---|
200
+ | C | D |
201
+ EOS
202
+ assert_equal "<table>\n<thead>\n<tr>\n<th> A </th>\n<th> B </th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td> C </td>\n<td> D </td>\n</tr>\n</tbody>\n</table>\n\n", rd.to_html
203
+ end
204
+
205
+ def test_that_gfm_code_blocks_work
206
+ rd = RDiscount.new(<<EOS)
207
+ ```
208
+ line 1
209
+
210
+ line 2
211
+ ```
212
+ EOS
213
+ assert_equal "<pre><code>line 1\n\nline 2\n</code></pre>\n", rd.to_html
214
+ end
215
+
216
+ def test_that_gfm_code_blocks_work_with_language
217
+ rd = RDiscount.new(<<EOS)
218
+ ```ruby
219
+ line 1
220
+
221
+ line 2
222
+ ```
223
+ EOS
224
+ assert_equal "<pre><code class=\"ruby\">line 1\n\nline 2\n</code></pre>\n", rd.to_html
225
+ end
226
+
227
+ def test_that_pandoc_code_blocks_work
228
+ rd = RDiscount.new(<<EOS)
229
+ ~~~
230
+ line 1
231
+
232
+ line 2
233
+ ~~~
234
+ EOS
235
+ assert_equal "<pre><code>line 1\n\nline 2\n</code></pre>\n", rd.to_html
236
+ end
237
+
238
+ def test_that_discount_definition_lists_work
239
+ rd = RDiscount.new(<<EOS)
240
+ =tag1=
241
+ =tag2=
242
+ data.
243
+ EOS
244
+ assert_equal <<EOS, rd.to_html
245
+ <dl>
246
+ <dt>tag1</dt>
247
+ <dt>tag2</dt>
248
+ <dd>data.</dd>
249
+ </dl>
250
+ EOS
251
+ end
252
+
253
+ def test_that_extra_definition_lists_work
254
+ rd = RDiscount.new(<<EOS)
255
+ tag1
256
+ : data
257
+ EOS
258
+ assert_equal <<EOS, rd.to_html
259
+ <dl>
260
+ <dt>tag1</dt>
261
+ <dd>data</dd>
262
+ </dl>
263
+ EOS
264
+ end
265
+
266
+ def test_that_emphasis_beside_international_characters_detected
267
+ rd = RDiscount.new(%(*foo ä bar*))
268
+ assert_equal %(<p><em>foo ä bar</em></p>\n), rd.to_html
269
+
270
+ rd = RDiscount.new(%(*ä foobar*))
271
+ assert_equal %(<p><em>ä foobar</em></p>\n), rd.to_html
272
+
273
+ rd = RDiscount.new(%(*foobar ä*))
274
+ assert_equal %(<p><em>foobar ä</em></p>\n), rd.to_html
275
+ end
276
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdiscountwl
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Tomayko
8
+ - David Loren Parsons
9
+ - Andrew White
10
+ - David Foster
11
+ - Liang Sun
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+ date: 2022-05-07 00:00:00.000000000 Z
16
+ dependencies: []
17
+ description:
18
+ email: i@liangsun.org
19
+ executables:
20
+ - rdiscount
21
+ extensions:
22
+ - ext/extconf.rb
23
+ extra_rdoc_files:
24
+ - COPYING
25
+ files:
26
+ - BUILDING
27
+ - COPYING
28
+ - README.markdown
29
+ - Rakefile
30
+ - bin/rdiscount
31
+ - ext/Csio.c
32
+ - ext/VERSION
33
+ - ext/amalloc.c
34
+ - ext/amalloc.h
35
+ - ext/basename.c
36
+ - ext/blocktags
37
+ - ext/config.h
38
+ - ext/css.c
39
+ - ext/cstring.h
40
+ - ext/docheader.c
41
+ - ext/dumptree.c
42
+ - ext/emmatch.c
43
+ - ext/extconf.rb
44
+ - ext/flags.c
45
+ - ext/generate.c
46
+ - ext/github_flavoured.c
47
+ - ext/html5.c
48
+ - ext/markdown.c
49
+ - ext/markdown.h
50
+ - ext/mkdio.c
51
+ - ext/mkdio.h
52
+ - ext/mktags.c
53
+ - ext/pgm_options.c
54
+ - ext/pgm_options.h
55
+ - ext/rdiscount.c
56
+ - ext/resource.c
57
+ - ext/setup.c
58
+ - ext/tags.c
59
+ - ext/tags.h
60
+ - ext/toc.c
61
+ - ext/version.c
62
+ - ext/xml.c
63
+ - ext/xmlpage.c
64
+ - lib/markdown.rb
65
+ - lib/rdiscount.rb
66
+ - man/markdown.7
67
+ - man/rdiscount.1
68
+ - man/rdiscount.1.ronn
69
+ - rdiscount.gemspec
70
+ - test/benchmark.rb
71
+ - test/benchmark.txt
72
+ - test/markdown_test.rb
73
+ - test/rdiscount_test.rb
74
+ homepage: https://github.com/1e0ng/rdiscount
75
+ licenses:
76
+ - BSD-3-Clause
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "!="
85
+ - !ruby/object:Gem::Version
86
+ version: 1.9.2
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.1.4
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Fast Implementation of Gruber's Markdown in C With Latex Support
97
+ test_files:
98
+ - test/markdown_test.rb
99
+ - test/rdiscount_test.rb