commonmarker 0.23.4 → 0.23.5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of commonmarker might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Rakefile +56 -55
- data/commonmarker.gemspec +26 -27
- data/ext/commonmarker/cmark-gfm_version.h +2 -2
- data/ext/commonmarker/commonmarker.c +1 -0
- data/ext/commonmarker/scanners.c +2438 -2450
- data/lib/commonmarker/config.rb +3 -3
- data/lib/commonmarker/node/inspect.rb +8 -18
- data/lib/commonmarker/node.rb +6 -6
- data/lib/commonmarker/renderer/html_renderer.rb +37 -37
- data/lib/commonmarker/renderer.rb +5 -5
- data/lib/commonmarker/version.rb +1 -1
- data/lib/commonmarker.rb +9 -9
- metadata +4 -57
- data/lib/commonmarker/errors.rb +0 -12
- data/test/benchmark.rb +0 -39
- data/test/fixtures/curly.md +0 -1
- data/test/fixtures/dingus.md +0 -10
- data/test/fixtures/strong.md +0 -1
- data/test/fixtures/table.md +0 -10
- data/test/test_attributes.rb +0 -24
- data/test/test_basics.rb +0 -35
- data/test/test_commands.rb +0 -72
- data/test/test_commonmark.rb +0 -36
- data/test/test_doc.rb +0 -130
- data/test/test_encoding.rb +0 -23
- data/test/test_extensions.rb +0 -116
- data/test/test_footnotes.rb +0 -60
- data/test/test_gc.rb +0 -47
- data/test/test_helper.rb +0 -71
- data/test/test_linebreaks.rb +0 -15
- data/test/test_maliciousness.rb +0 -262
- data/test/test_node.rb +0 -89
- data/test/test_options.rb +0 -37
- data/test/test_pathological_inputs.rb +0 -94
- data/test/test_plaintext.rb +0 -46
- data/test/test_renderer.rb +0 -47
- data/test/test_smartpunct.rb +0 -27
- data/test/test_spec.rb +0 -30
- data/test/test_tasklists.rb +0 -43
- data/test/test_xml.rb +0 -107
data/lib/commonmarker/config.rb
CHANGED
@@ -13,7 +13,7 @@ module CommonMarker
|
|
13
13
|
SMART: (1 << 10),
|
14
14
|
LIBERAL_HTML_TAG: (1 << 12),
|
15
15
|
FOOTNOTES: (1 << 13),
|
16
|
-
STRIKETHROUGH_DOUBLE_TILDE: (1 << 14)
|
16
|
+
STRIKETHROUGH_DOUBLE_TILDE: (1 << 14),
|
17
17
|
}.freeze,
|
18
18
|
render: {
|
19
19
|
DEFAULT: 0,
|
@@ -28,9 +28,9 @@ module CommonMarker
|
|
28
28
|
FOOTNOTES: (1 << 13),
|
29
29
|
STRIKETHROUGH_DOUBLE_TILDE: (1 << 14),
|
30
30
|
TABLE_PREFER_STYLE_ATTRIBUTES: (1 << 15),
|
31
|
-
FULL_INFO_STRING: (1 << 16)
|
31
|
+
FULL_INFO_STRING: (1 << 16),
|
32
32
|
}.freeze,
|
33
|
-
format:
|
33
|
+
format: [:html, :xml, :commonmark, :plaintext].freeze,
|
34
34
|
}.freeze
|
35
35
|
|
36
36
|
def self.process_options(option, type)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "pp"
|
4
4
|
|
5
5
|
module CommonMarker
|
6
6
|
class Node
|
@@ -8,33 +8,23 @@ module CommonMarker
|
|
8
8
|
PP_INDENT_SIZE = 2
|
9
9
|
|
10
10
|
def inspect
|
11
|
-
PP.pp(self, +
|
11
|
+
PP.pp(self, +"", Float::INFINITY)
|
12
12
|
end
|
13
13
|
|
14
14
|
# @param printer [PrettyPrint] pp
|
15
15
|
def pretty_print(printer)
|
16
|
-
printer.group(PP_INDENT_SIZE, "#<#{self.class}(#{type}):",
|
16
|
+
printer.group(PP_INDENT_SIZE, "#<#{self.class}(#{type}):", ">") do
|
17
17
|
printer.breakable
|
18
18
|
|
19
|
-
attrs =
|
20
|
-
sourcepos
|
21
|
-
string_content
|
22
|
-
url
|
23
|
-
title
|
24
|
-
header_level
|
25
|
-
list_type
|
26
|
-
list_start
|
27
|
-
list_tight
|
28
|
-
fence_info
|
29
|
-
].map do |name|
|
19
|
+
attrs = [:sourcepos, :string_content, :url, :title, :header_level, :list_type, :list_start, :list_tight, :fence_info].map do |name|
|
30
20
|
[name, __send__(name)]
|
31
21
|
rescue NodeError
|
32
22
|
nil
|
33
23
|
end.compact
|
34
24
|
|
35
25
|
printer.seplist(attrs) do |name, value|
|
36
|
-
printer.text
|
37
|
-
printer.pp
|
26
|
+
printer.text("#{name}=")
|
27
|
+
printer.pp(value)
|
38
28
|
end
|
39
29
|
|
40
30
|
if first_child
|
@@ -46,8 +36,8 @@ module CommonMarker
|
|
46
36
|
children << node
|
47
37
|
node = node.next
|
48
38
|
end
|
49
|
-
printer.text
|
50
|
-
printer.pp
|
39
|
+
printer.text("children=")
|
40
|
+
printer.pp(children)
|
51
41
|
end
|
52
42
|
end
|
53
43
|
end
|
data/lib/commonmarker/node.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "commonmarker/node/inspect"
|
4
4
|
|
5
5
|
module CommonMarker
|
6
6
|
class Node
|
@@ -27,7 +27,7 @@ module CommonMarker
|
|
27
27
|
# Returns a {String}.
|
28
28
|
def to_html(options = :DEFAULT, extensions = [])
|
29
29
|
opts = Config.process_options(options, :render)
|
30
|
-
_render_html(opts, extensions).force_encoding(
|
30
|
+
_render_html(opts, extensions).force_encoding("utf-8")
|
31
31
|
end
|
32
32
|
|
33
33
|
# Public: Convert the node to an XML string.
|
@@ -37,7 +37,7 @@ module CommonMarker
|
|
37
37
|
# Returns a {String}.
|
38
38
|
def to_xml(options = :DEFAULT)
|
39
39
|
opts = Config.process_options(options, :render)
|
40
|
-
_render_xml(opts).force_encoding(
|
40
|
+
_render_xml(opts).force_encoding("utf-8")
|
41
41
|
end
|
42
42
|
|
43
43
|
# Public: Convert the node to a CommonMark string.
|
@@ -48,7 +48,7 @@ module CommonMarker
|
|
48
48
|
# Returns a {String}.
|
49
49
|
def to_commonmark(options = :DEFAULT, width = 120)
|
50
50
|
opts = Config.process_options(options, :render)
|
51
|
-
_render_commonmark(opts, width).force_encoding(
|
51
|
+
_render_commonmark(opts, width).force_encoding("utf-8")
|
52
52
|
end
|
53
53
|
|
54
54
|
# Public: Convert the node to a plain text string.
|
@@ -59,7 +59,7 @@ module CommonMarker
|
|
59
59
|
# Returns a {String}.
|
60
60
|
def to_plaintext(options = :DEFAULT, width = 120)
|
61
61
|
opts = Config.process_options(options, :render)
|
62
|
-
_render_plaintext(opts, width).force_encoding(
|
62
|
+
_render_plaintext(opts, width).force_encoding("utf-8")
|
63
63
|
end
|
64
64
|
|
65
65
|
# Public: Iterate over the children (if any) of the current pointer.
|
@@ -76,7 +76,7 @@ module CommonMarker
|
|
76
76
|
|
77
77
|
# Deprecated: Please use `each` instead
|
78
78
|
def each_child(&block)
|
79
|
-
warn
|
79
|
+
warn("[DEPRECATION] `each_child` is deprecated. Please use `each` instead.")
|
80
80
|
each(&block)
|
81
81
|
end
|
82
82
|
end
|
@@ -9,8 +9,8 @@ module CommonMarker
|
|
9
9
|
|
10
10
|
def header(node)
|
11
11
|
block do
|
12
|
-
out(
|
13
|
-
|
12
|
+
out("<h", node.header_level, "#{sourcepos(node)}>", :children,
|
13
|
+
"</h", node.header_level, ">")
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -19,10 +19,10 @@ module CommonMarker
|
|
19
19
|
out(:children)
|
20
20
|
else
|
21
21
|
block do
|
22
|
-
container("<p#{sourcepos(node)}>",
|
22
|
+
container("<p#{sourcepos(node)}>", "</p>") do
|
23
23
|
out(:children)
|
24
24
|
if node.parent.type == :footnote_definition && node.next.nil?
|
25
|
-
out(
|
25
|
+
out(" ")
|
26
26
|
out_footnote_backref
|
27
27
|
end
|
28
28
|
end
|
@@ -36,16 +36,16 @@ module CommonMarker
|
|
36
36
|
|
37
37
|
block do
|
38
38
|
if node.list_type == :bullet_list
|
39
|
-
container("<ul#{sourcepos(node)}>\n",
|
39
|
+
container("<ul#{sourcepos(node)}>\n", "</ul>") do
|
40
40
|
out(:children)
|
41
41
|
end
|
42
42
|
else
|
43
43
|
start = if node.list_start == 1
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
container(start,
|
44
|
+
"<ol#{sourcepos(node)}>\n"
|
45
|
+
else
|
46
|
+
"<ol start=\"#{node.list_start}\"#{sourcepos(node)}>\n"
|
47
|
+
end
|
48
|
+
container(start, "</ol>") do
|
49
49
|
out(:children)
|
50
50
|
end
|
51
51
|
end
|
@@ -57,26 +57,26 @@ module CommonMarker
|
|
57
57
|
def list_item(node)
|
58
58
|
block do
|
59
59
|
tasklist_data = tasklist(node)
|
60
|
-
container("<li#{sourcepos(node)}#{tasklist_data}>#{
|
60
|
+
container("<li#{sourcepos(node)}#{tasklist_data}>#{" " if tasklist?(node)}", "</li>") do
|
61
61
|
out(:children)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def tasklist(node)
|
67
|
-
return
|
67
|
+
return "" unless tasklist?(node)
|
68
68
|
|
69
69
|
state = if checked?(node)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
'checked="" disabled=""'
|
71
|
+
else
|
72
|
+
'disabled=""'
|
73
|
+
end
|
74
74
|
"><input type=\"checkbox\" #{state} /"
|
75
75
|
end
|
76
76
|
|
77
77
|
def blockquote(node)
|
78
78
|
block do
|
79
|
-
container("<blockquote#{sourcepos(node)}>\n",
|
79
|
+
container("<blockquote#{sourcepos(node)}>\n", "</blockquote>") do
|
80
80
|
out(:children)
|
81
81
|
end
|
82
82
|
end
|
@@ -93,17 +93,17 @@ module CommonMarker
|
|
93
93
|
if option_enabled?(:GITHUB_PRE_LANG)
|
94
94
|
out("<pre#{sourcepos(node)}")
|
95
95
|
out(' lang="', node.fence_info.split(/\s+/)[0], '"') if node.fence_info && !node.fence_info.empty?
|
96
|
-
out(
|
96
|
+
out("><code>")
|
97
97
|
else
|
98
98
|
out("<pre#{sourcepos(node)}><code")
|
99
99
|
if node.fence_info && !node.fence_info.empty?
|
100
100
|
out(' class="language-', node.fence_info.split(/\s+/)[0], '">')
|
101
101
|
else
|
102
|
-
out(
|
102
|
+
out(">")
|
103
103
|
end
|
104
104
|
end
|
105
105
|
out(escape_html(node.string_content))
|
106
|
-
out(
|
106
|
+
out("</code></pre>")
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
@@ -112,7 +112,7 @@ module CommonMarker
|
|
112
112
|
if option_enabled?(:UNSAFE)
|
113
113
|
out(tagfilter(node.string_content))
|
114
114
|
else
|
115
|
-
out(
|
115
|
+
out("<!-- raw HTML omitted -->")
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
@@ -121,22 +121,22 @@ module CommonMarker
|
|
121
121
|
if option_enabled?(:UNSAFE)
|
122
122
|
out(tagfilter(node.string_content))
|
123
123
|
else
|
124
|
-
out(
|
124
|
+
out("<!-- raw HTML omitted -->")
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
def emph(_)
|
129
|
-
out(
|
129
|
+
out("<em>", :children, "</em>")
|
130
130
|
end
|
131
131
|
|
132
132
|
def strong(_)
|
133
|
-
out(
|
133
|
+
out("<strong>", :children, "</strong>")
|
134
134
|
end
|
135
135
|
|
136
136
|
def link(node)
|
137
|
-
out('<a href="', node.url.nil? ?
|
137
|
+
out('<a href="', node.url.nil? ? "" : escape_href(node.url), '"')
|
138
138
|
out(' title="', escape_html(node.title), '"') if node.title && !node.title.empty?
|
139
|
-
out(
|
139
|
+
out(">", :children, "</a>")
|
140
140
|
end
|
141
141
|
|
142
142
|
def image(node)
|
@@ -145,7 +145,7 @@ module CommonMarker
|
|
145
145
|
out(' alt="', :children, '"')
|
146
146
|
end
|
147
147
|
out(' title="', escape_html(node.title), '"') if node.title && !node.title.empty?
|
148
|
-
out(
|
148
|
+
out(" />")
|
149
149
|
end
|
150
150
|
|
151
151
|
def text(node)
|
@@ -153,9 +153,9 @@ module CommonMarker
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def code(node)
|
156
|
-
out(
|
156
|
+
out("<code>")
|
157
157
|
out(escape_html(node.string_content))
|
158
|
-
out(
|
158
|
+
out("</code>")
|
159
159
|
end
|
160
160
|
|
161
161
|
def linebreak(_node)
|
@@ -166,7 +166,7 @@ module CommonMarker
|
|
166
166
|
if option_enabled?(:HARDBREAKS)
|
167
167
|
out("<br />\n")
|
168
168
|
elsif option_enabled?(:NOBREAKS)
|
169
|
-
out(
|
169
|
+
out(" ")
|
170
170
|
else
|
171
171
|
out("\n")
|
172
172
|
end
|
@@ -199,17 +199,17 @@ module CommonMarker
|
|
199
199
|
|
200
200
|
def table_cell(node)
|
201
201
|
align = case @alignments[@column_index]
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
202
|
+
when :left then ' align="left"'
|
203
|
+
when :right then ' align="right"'
|
204
|
+
when :center then ' align="center"'
|
205
|
+
else; ""
|
206
|
+
end
|
207
207
|
out(@in_header ? "<th#{align}#{sourcepos(node)}>" : "<td#{align}#{sourcepos(node)}>", :children, @in_header ? "</th>\n" : "</td>\n")
|
208
208
|
@column_index += 1
|
209
209
|
end
|
210
210
|
|
211
211
|
def strikethrough(_)
|
212
|
-
out(
|
212
|
+
out("<del>", :children, "</del>")
|
213
213
|
end
|
214
214
|
|
215
215
|
def footnote_reference(node)
|
@@ -242,7 +242,7 @@ module CommonMarker
|
|
242
242
|
end
|
243
243
|
|
244
244
|
def tasklist?(node)
|
245
|
-
node.type_string ==
|
245
|
+
node.type_string == "tasklist"
|
246
246
|
end
|
247
247
|
|
248
248
|
def checked?(node)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "set"
|
4
|
+
require "stringio"
|
5
5
|
|
6
6
|
module CommonMarker
|
7
7
|
class Renderer
|
@@ -9,9 +9,9 @@ module CommonMarker
|
|
9
9
|
|
10
10
|
def initialize(options: :DEFAULT, extensions: [])
|
11
11
|
@opts = Config.process_options(options, :render)
|
12
|
-
@stream = StringIO.new(+
|
12
|
+
@stream = StringIO.new(+"")
|
13
13
|
@need_blocksep = false
|
14
|
-
@warnings = Set.new
|
14
|
+
@warnings = Set.new([])
|
15
15
|
@in_tight = false
|
16
16
|
@in_plain = false
|
17
17
|
@tagfilter = extensions.include?(:tagfilter)
|
@@ -121,7 +121,7 @@ module CommonMarker
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def sourcepos(node)
|
124
|
-
return
|
124
|
+
return "" unless option_enabled?(:SOURCEPOS)
|
125
125
|
|
126
126
|
s = node.sourcepos
|
127
127
|
" data-sourcepos=\"#{s[:start_line]}:#{s[:start_column]}-" \
|
data/lib/commonmarker/version.rb
CHANGED
data/lib/commonmarker.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
4
|
+
require "commonmarker/commonmarker"
|
5
|
+
require "commonmarker/config"
|
6
|
+
require "commonmarker/node"
|
7
|
+
require "commonmarker/renderer"
|
8
|
+
require "commonmarker/renderer/html_renderer"
|
9
|
+
require "commonmarker/version"
|
10
10
|
|
11
11
|
begin
|
12
|
-
require
|
12
|
+
require "awesome_print"
|
13
13
|
rescue LoadError; end # rubocop:disable Lint/SuppressedException
|
14
14
|
module CommonMarker
|
15
15
|
# Public: Parses a Markdown string into an HTML string.
|
@@ -23,7 +23,7 @@ module CommonMarker
|
|
23
23
|
raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
|
24
24
|
|
25
25
|
opts = Config.process_options(options, :render)
|
26
|
-
Node.markdown_to_html(text.encode(
|
26
|
+
Node.markdown_to_html(text.encode("UTF-8"), opts, extensions)
|
27
27
|
end
|
28
28
|
|
29
29
|
# Public: Parses a Markdown string into a `document` node.
|
@@ -37,7 +37,7 @@ module CommonMarker
|
|
37
37
|
raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
|
38
38
|
|
39
39
|
opts = Config.process_options(options, :parse)
|
40
|
-
text = text.encode(
|
40
|
+
text = text.encode("UTF-8")
|
41
41
|
Node.parse_document(text, text.bytesize, opts, extensions)
|
42
42
|
end
|
43
43
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commonmarker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.23.
|
4
|
+
version: 0.23.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: awesome_print
|
@@ -224,38 +224,11 @@ files:
|
|
224
224
|
- ext/commonmarker/xml.c
|
225
225
|
- lib/commonmarker.rb
|
226
226
|
- lib/commonmarker/config.rb
|
227
|
-
- lib/commonmarker/errors.rb
|
228
227
|
- lib/commonmarker/node.rb
|
229
228
|
- lib/commonmarker/node/inspect.rb
|
230
229
|
- lib/commonmarker/renderer.rb
|
231
230
|
- lib/commonmarker/renderer/html_renderer.rb
|
232
231
|
- lib/commonmarker/version.rb
|
233
|
-
- test/benchmark.rb
|
234
|
-
- test/fixtures/curly.md
|
235
|
-
- test/fixtures/dingus.md
|
236
|
-
- test/fixtures/strong.md
|
237
|
-
- test/fixtures/table.md
|
238
|
-
- test/test_attributes.rb
|
239
|
-
- test/test_basics.rb
|
240
|
-
- test/test_commands.rb
|
241
|
-
- test/test_commonmark.rb
|
242
|
-
- test/test_doc.rb
|
243
|
-
- test/test_encoding.rb
|
244
|
-
- test/test_extensions.rb
|
245
|
-
- test/test_footnotes.rb
|
246
|
-
- test/test_gc.rb
|
247
|
-
- test/test_helper.rb
|
248
|
-
- test/test_linebreaks.rb
|
249
|
-
- test/test_maliciousness.rb
|
250
|
-
- test/test_node.rb
|
251
|
-
- test/test_options.rb
|
252
|
-
- test/test_pathological_inputs.rb
|
253
|
-
- test/test_plaintext.rb
|
254
|
-
- test/test_renderer.rb
|
255
|
-
- test/test_smartpunct.rb
|
256
|
-
- test/test_spec.rb
|
257
|
-
- test/test_tasklists.rb
|
258
|
-
- test/test_xml.rb
|
259
232
|
homepage: https://github.com/gjtorikian/commonmarker
|
260
233
|
licenses:
|
261
234
|
- MIT
|
@@ -282,34 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
282
255
|
- !ruby/object:Gem::Version
|
283
256
|
version: '0'
|
284
257
|
requirements: []
|
285
|
-
rubygems_version: 3.3.
|
258
|
+
rubygems_version: 3.3.13
|
286
259
|
signing_key:
|
287
260
|
specification_version: 4
|
288
261
|
summary: CommonMark parser and renderer. Written in C, wrapped in Ruby.
|
289
|
-
test_files:
|
290
|
-
- test/benchmark.rb
|
291
|
-
- test/fixtures/curly.md
|
292
|
-
- test/fixtures/dingus.md
|
293
|
-
- test/fixtures/strong.md
|
294
|
-
- test/fixtures/table.md
|
295
|
-
- test/test_attributes.rb
|
296
|
-
- test/test_basics.rb
|
297
|
-
- test/test_commands.rb
|
298
|
-
- test/test_commonmark.rb
|
299
|
-
- test/test_doc.rb
|
300
|
-
- test/test_encoding.rb
|
301
|
-
- test/test_extensions.rb
|
302
|
-
- test/test_footnotes.rb
|
303
|
-
- test/test_gc.rb
|
304
|
-
- test/test_helper.rb
|
305
|
-
- test/test_linebreaks.rb
|
306
|
-
- test/test_maliciousness.rb
|
307
|
-
- test/test_node.rb
|
308
|
-
- test/test_options.rb
|
309
|
-
- test/test_pathological_inputs.rb
|
310
|
-
- test/test_plaintext.rb
|
311
|
-
- test/test_renderer.rb
|
312
|
-
- test/test_smartpunct.rb
|
313
|
-
- test/test_spec.rb
|
314
|
-
- test/test_tasklists.rb
|
315
|
-
- test/test_xml.rb
|
262
|
+
test_files: []
|
data/lib/commonmarker/errors.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'commonmarker/node/inspect'
|
4
|
-
|
5
|
-
module CommonMarker
|
6
|
-
class RenderError < StandardError
|
7
|
-
PREAMBLE = 'There was an error rendering'
|
8
|
-
def initialize(error)
|
9
|
-
super("#{PREAMBLE}: #{error.class} #{error.message}")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
data/test/benchmark.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'benchmark/ips'
|
4
|
-
require 'commonmarker'
|
5
|
-
require 'redcarpet'
|
6
|
-
require 'kramdown'
|
7
|
-
require 'benchmark'
|
8
|
-
|
9
|
-
benchinput = File.read('test/benchinput.md').freeze
|
10
|
-
|
11
|
-
printf("input size = %<bytes>d bytes\n\n", { bytes: benchinput.bytesize })
|
12
|
-
|
13
|
-
Benchmark.ips do |x|
|
14
|
-
x.report('redcarpet') do
|
15
|
-
Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: false, tables: false).render(benchinput)
|
16
|
-
end
|
17
|
-
|
18
|
-
x.report('commonmarker with to_html') do
|
19
|
-
CommonMarker.render_html(benchinput)
|
20
|
-
end
|
21
|
-
|
22
|
-
x.report('commonmarker with to_xml') do
|
23
|
-
CommonMarker.render_html(benchinput)
|
24
|
-
end
|
25
|
-
|
26
|
-
x.report('commonmarker with ruby HtmlRenderer') do
|
27
|
-
CommonMarker::HtmlRenderer.new.render(CommonMarker.render_doc(benchinput))
|
28
|
-
end
|
29
|
-
|
30
|
-
x.report('commonmarker with render_doc.to_html') do
|
31
|
-
CommonMarker.render_doc(benchinput, :DEFAULT, [:autolink]).to_html(:DEFAULT, [:autolink])
|
32
|
-
end
|
33
|
-
|
34
|
-
x.report('kramdown') do
|
35
|
-
Kramdown::Document.new(benchinput).to_html(benchinput)
|
36
|
-
end
|
37
|
-
|
38
|
-
x.compare!
|
39
|
-
end
|
data/test/fixtures/curly.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
This curly quote “makes commonmarker throw an exception”.
|
data/test/fixtures/dingus.md
DELETED
data/test/fixtures/strong.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
I am **strong**
|
data/test/fixtures/table.md
DELETED
data/test/test_attributes.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestAttributes < Minitest::Test
|
6
|
-
def setup
|
7
|
-
contents = fixtures_file('dingus.md')
|
8
|
-
@doc = CommonMarker.render_doc(contents.strip)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_sourcepos
|
12
|
-
sourcepos = []
|
13
|
-
|
14
|
-
@doc.walk do |node|
|
15
|
-
sourcepos << node.sourcepos
|
16
|
-
end
|
17
|
-
|
18
|
-
sourcepos.delete_if { |h| h.values.all?(&:zero?) }
|
19
|
-
|
20
|
-
result = [{ start_line: 1, start_column: 1, end_line: 10, end_column: 12 }, { start_line: 1, start_column: 1, end_line: 1, end_column: 17 }, { start_line: 1, start_column: 4, end_line: 1, end_column: 17 }, { start_line: 3, start_column: 1, end_line: 5, end_column: 36 }, { start_line: 3, start_column: 1, end_line: 3, end_column: 55 }, { start_line: 4, start_column: 1, end_line: 4, end_column: 53 }, { start_line: 4, start_column: 2, end_line: 4, end_column: 14 }, { start_line: 4, start_column: 54, end_line: 4, end_column: 58 }, { start_line: 5, start_column: 1, end_line: 5, end_column: 36 }, { start_line: 7, start_column: 1, end_line: 10, end_column: 12 }, { start_line: 7, start_column: 1, end_line: 7, end_column: 11 }, { start_line: 7, start_column: 4, end_line: 7, end_column: 11 }, { start_line: 7, start_column: 4, end_line: 7, end_column: 11 }, { start_line: 8, start_column: 1, end_line: 10, end_column: 12 }, { start_line: 8, start_column: 4, end_line: 8, end_column: 11 }, { start_line: 8, start_column: 4, end_line: 8, end_column: 11 }, { start_line: 9, start_column: 4, end_line: 10, end_column: 12 }, { start_line: 9, start_column: 4, end_line: 9, end_column: 12 }, { start_line: 9, start_column: 6, end_line: 9, end_column: 12 }, { start_line: 9, start_column: 6, end_line: 9, end_column: 12 }, { start_line: 10, start_column: 4, end_line: 10, end_column: 12 }, { start_line: 10, start_column: 6, end_line: 10, end_column: 12 }, { start_line: 10, start_column: 6, end_line: 10, end_column: 12 }]
|
21
|
-
|
22
|
-
assert_equal result, sourcepos
|
23
|
-
end
|
24
|
-
end
|
data/test/test_basics.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestBasics < Minitest::Test
|
6
|
-
def setup
|
7
|
-
@doc = CommonMarker.render_doc('Hi *there*')
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_to_html
|
11
|
-
assert_equal "<p>Hi <em>there</em></p>\n", @doc.to_html
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_markdown_to_html
|
15
|
-
html = CommonMarker.render_html('Hi *there*')
|
16
|
-
assert_equal "<p>Hi <em>there</em></p>\n", html
|
17
|
-
end
|
18
|
-
|
19
|
-
# basic test that just checks if every option is accepted & no errors are thrown
|
20
|
-
def test_accept_every_option
|
21
|
-
text = "Hello **world** -- how are _you_ today? I'm ~~fine~~, ~yourself~?"
|
22
|
-
parse_opt = %i[SOURCEPOS UNSAFE VALIDATE_UTF8 SMART LIBERAL_HTML_TAG FOOTNOTES STRIKETHROUGH_DOUBLE_TILDE]
|
23
|
-
render_opt = parse_opt + %i[HARDBREAKS NOBREAKS GITHUB_PRE_LANG TABLE_PREFER_STYLE_ATTRIBUTES FULL_INFO_STRING]
|
24
|
-
|
25
|
-
extensions = %i[table tasklist strikethrough autolink tagfilter]
|
26
|
-
|
27
|
-
assert_equal "<p>Hello <strong>world</strong> – how are <em>you</em> today? I’m <del>fine</del>, ~yourself~?</p>\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html
|
28
|
-
|
29
|
-
# NOTE: how tho the doc returned has sourcepos info, by default the renderer
|
30
|
-
# won't emit it. for that we need to pass in the render opt
|
31
|
-
assert_equal "<p data-sourcepos=\"1:1-1:65\">Hello <strong>world</strong> – how are <em>you</em> today? I’m <del>fine</del>, ~yourself~?</p>\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html(render_opt, extensions)
|
32
|
-
|
33
|
-
assert_equal "<p data-sourcepos=\"1:1-1:65\">Hello <strong>world</strong> – how are <em>you</em> today? I’m <del>fine</del>, ~yourself~?</p>\n", CommonMarker.render_html(text, parse_opt, extensions)
|
34
|
-
end
|
35
|
-
end
|