markly 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/conduct.md +133 -0
- data/ext/markly/arena.c +9 -8
- data/ext/markly/autolink.c +217 -134
- data/ext/markly/blocks.c +27 -2
- data/ext/markly/cmark-gfm-core-extensions.h +11 -11
- data/ext/markly/cmark-gfm-extension_api.h +1 -0
- data/ext/markly/cmark-gfm.h +18 -2
- data/ext/markly/cmark.c +3 -3
- data/ext/markly/commonmark.c +19 -34
- data/ext/markly/extconf.rb +8 -1
- data/ext/markly/html.c +22 -6
- data/ext/markly/inlines.c +148 -51
- data/ext/markly/latex.c +6 -4
- data/ext/markly/man.c +7 -11
- data/ext/markly/map.c +11 -4
- data/ext/markly/map.h +5 -2
- data/ext/markly/markly.c +582 -586
- data/ext/markly/markly.h +1 -1
- data/ext/markly/node.c +76 -10
- data/ext/markly/node.h +42 -1
- data/ext/markly/parser.h +1 -0
- data/ext/markly/plaintext.c +12 -29
- data/ext/markly/references.c +1 -0
- data/ext/markly/render.c +15 -7
- data/ext/markly/scanners.c +13916 -10380
- data/ext/markly/scanners.h +8 -0
- data/ext/markly/scanners.re +47 -8
- data/ext/markly/strikethrough.c +1 -1
- data/ext/markly/table.c +81 -31
- data/ext/markly/xml.c +2 -1
- data/lib/markly/flags.rb +16 -0
- data/lib/markly/node/inspect.rb +59 -53
- data/lib/markly/node.rb +125 -58
- data/lib/markly/renderer/generic.rb +129 -124
- data/lib/markly/renderer/html.rb +294 -275
- data/lib/markly/version.rb +7 -1
- data/lib/markly.rb +36 -30
- data/license.md +39 -0
- data/readme.md +36 -0
- data.tar.gz.sig +0 -0
- metadata +61 -29
- metadata.gz.sig +0 -0
- data/bin/markly +0 -94
- data/lib/markly/markly.bundle +0 -0
data/lib/markly/renderer/html.rb
CHANGED
@@ -1,282 +1,301 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2015-2020, by Garen Torikian.
|
5
|
+
# Copyright, 2015, by Nick Wellnhofer.
|
6
|
+
# Copyright, 2017, by Yuki Izumi.
|
7
|
+
# Copyright, 2017-2019, by Ashe Connor.
|
8
|
+
# Copyright, 2018, by Michael Camilleri.
|
9
|
+
# Copyright, 2020-2023, by Samuel Williams.
|
10
|
+
|
3
11
|
require_relative 'generic'
|
4
12
|
require 'cgi'
|
5
13
|
|
6
14
|
module Markly
|
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
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
15
|
+
module Renderer
|
16
|
+
class HTML < Generic
|
17
|
+
def initialize(ids: false, tight: false, **options)
|
18
|
+
super(**options)
|
19
|
+
|
20
|
+
@ids = ids
|
21
|
+
@section = nil
|
22
|
+
@tight = tight
|
23
|
+
|
24
|
+
@footnotes = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def document(_)
|
28
|
+
@section = false
|
29
|
+
super
|
30
|
+
out("</ol>\n</section>\n") if @written_footnote_ix
|
31
|
+
out("</section>") if @section
|
32
|
+
end
|
33
|
+
|
34
|
+
def id_for(node)
|
35
|
+
if @ids
|
36
|
+
id = node.to_plaintext.chomp.downcase.gsub(/\s+/, '-')
|
37
|
+
|
38
|
+
return " id=\"#{CGI.escape_html id}\""
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def header(node)
|
43
|
+
block do
|
44
|
+
if @ids
|
45
|
+
out('</section>') if @section
|
46
|
+
@section = true
|
47
|
+
out("<section#{id_for(node)}>")
|
48
|
+
end
|
49
|
+
|
50
|
+
out('<h', node.header_level, "#{source_position(node)}>", :children,
|
51
|
+
'</h', node.header_level, '>')
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def paragraph(node)
|
56
|
+
if @tight && node.parent.type != :blockquote
|
57
|
+
out(:children)
|
58
|
+
else
|
59
|
+
block do
|
60
|
+
container("<p#{source_position(node)}>", '</p>') do
|
61
|
+
out(:children)
|
62
|
+
if node.parent.type == :footnote_definition && node.next.nil?
|
63
|
+
out(' ')
|
64
|
+
out_footnote_backref
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def list(node)
|
72
|
+
old_tight = @tight
|
73
|
+
@tight = node.list_tight
|
74
|
+
|
75
|
+
block do
|
76
|
+
if node.list_type == :bullet_list
|
77
|
+
container("<ul#{source_position(node)}>\n", '</ul>') do
|
78
|
+
out(:children)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
start = if node.list_start == 1
|
82
|
+
"<ol#{source_position(node)}>\n"
|
83
|
+
else
|
84
|
+
"<ol start=\"#{node.list_start}\"#{source_position(node)}>\n"
|
85
|
+
end
|
86
|
+
container(start, '</ol>') do
|
87
|
+
out(:children)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
@tight = old_tight
|
93
|
+
end
|
94
|
+
|
95
|
+
def list_item(node)
|
96
|
+
block do
|
97
|
+
tasklist_data = tasklist(node)
|
98
|
+
container("<li#{source_position(node)}#{tasklist_data}>#{' ' if tasklist?(node)}", '</li>') do
|
99
|
+
out(:children)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def tasklist(node)
|
105
|
+
return '' unless tasklist?(node)
|
106
|
+
|
107
|
+
state = if checked?(node)
|
108
|
+
'checked="" disabled=""'
|
109
|
+
else
|
110
|
+
'disabled=""'
|
111
|
+
end
|
112
|
+
"><input type=\"checkbox\" #{state} /"
|
113
|
+
end
|
114
|
+
|
115
|
+
def blockquote(node)
|
116
|
+
block do
|
117
|
+
container("<blockquote#{source_position(node)}>\n", '</blockquote>') do
|
118
|
+
out(:children)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def hrule(node)
|
124
|
+
block do
|
125
|
+
out("<hr#{source_position(node)} />")
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def code_block(node)
|
130
|
+
block do
|
131
|
+
if flag_enabled?(GITHUB_PRE_LANG)
|
132
|
+
out("<pre#{source_position(node)}")
|
133
|
+
out(' lang="', node.fence_info.split(/\s+/)[0], '"') if node.fence_info && !node.fence_info.empty?
|
134
|
+
out('><code>')
|
135
|
+
else
|
136
|
+
out("<pre#{source_position(node)}><code")
|
137
|
+
if node.fence_info && !node.fence_info.empty?
|
138
|
+
out(' class="language-', node.fence_info.split(/\s+/)[0], '">')
|
139
|
+
else
|
140
|
+
out('>')
|
141
|
+
end
|
142
|
+
end
|
143
|
+
out(escape_html(node.string_content))
|
144
|
+
out('</code></pre>')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def html(node)
|
149
|
+
block do
|
150
|
+
if flag_enabled?(UNSAFE)
|
151
|
+
out(tagfilter(node.string_content))
|
152
|
+
else
|
153
|
+
out('<!-- raw HTML omitted -->')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def inline_html(node)
|
159
|
+
if flag_enabled?(UNSAFE)
|
160
|
+
out(tagfilter(node.string_content))
|
161
|
+
else
|
162
|
+
out('<!-- raw HTML omitted -->')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def emph(node)
|
167
|
+
out('<em>', :children, '</em>')
|
168
|
+
end
|
169
|
+
|
170
|
+
def strong(node)
|
171
|
+
if node.parent.nil? || node.parent.type == node.type
|
172
|
+
out(:children)
|
173
|
+
else
|
174
|
+
out('<strong>', :children, '</strong>')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def link(node)
|
179
|
+
out('<a href="', node.url.nil? ? '' : escape_href(node.url), '"')
|
180
|
+
out(' title="', escape_html(node.title), '"') if node.title && !node.title.empty?
|
181
|
+
out('>', :children, '</a>')
|
182
|
+
end
|
183
|
+
|
184
|
+
def image(node)
|
185
|
+
out('<img src="', escape_href(node.url), '"')
|
186
|
+
plain do
|
187
|
+
out(' alt="', :children, '"')
|
188
|
+
end
|
189
|
+
out(' title="', escape_html(node.title), '"') if node.title && !node.title.empty?
|
190
|
+
out(' />')
|
191
|
+
end
|
192
|
+
|
193
|
+
def text(node)
|
194
|
+
out(escape_html(node.string_content))
|
195
|
+
end
|
196
|
+
|
197
|
+
def code(node)
|
198
|
+
out('<code>')
|
199
|
+
out(escape_html(node.string_content))
|
200
|
+
out('</code>')
|
201
|
+
end
|
202
|
+
|
203
|
+
def linebreak(_node)
|
204
|
+
out("<br />\n")
|
205
|
+
end
|
206
|
+
|
207
|
+
def softbreak(_)
|
208
|
+
if flag_enabled?(HARD_BREAKS)
|
209
|
+
out("<br />\n")
|
210
|
+
elsif flag_enabled?(NO_BREAKS)
|
211
|
+
out(' ')
|
212
|
+
else
|
213
|
+
out("\n")
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
def table(node)
|
218
|
+
@alignments = node.table_alignments
|
219
|
+
@needs_close_tbody = false
|
220
|
+
out("<table#{source_position(node)}>\n", :children)
|
221
|
+
out("</tbody>\n") if @needs_close_tbody
|
222
|
+
out("</table>\n")
|
223
|
+
end
|
224
|
+
|
225
|
+
def table_header(node)
|
226
|
+
@column_index = 0
|
227
|
+
|
228
|
+
@in_header = true
|
229
|
+
out("<thead>\n<tr#{source_position(node)}>\n", :children, "</tr>\n</thead>\n")
|
230
|
+
@in_header = false
|
231
|
+
end
|
232
|
+
|
233
|
+
def table_row(node)
|
234
|
+
@column_index = 0
|
235
|
+
if !@in_header && !@needs_close_tbody
|
236
|
+
@needs_close_tbody = true
|
237
|
+
out("<tbody>\n")
|
238
|
+
end
|
239
|
+
out("<tr#{source_position(node)}>\n", :children, "</tr>\n")
|
240
|
+
end
|
241
|
+
|
242
|
+
def table_cell(node)
|
243
|
+
align = case @alignments[@column_index]
|
244
|
+
when :left then ' align="left"'
|
245
|
+
when :right then ' align="right"'
|
246
|
+
when :center then ' align="center"'
|
247
|
+
else; ''
|
248
|
+
end
|
249
|
+
out(@in_header ? "<th#{align}#{source_position(node)}>" : "<td#{align}#{source_position(node)}>", :children, @in_header ? "</th>\n" : "</td>\n")
|
250
|
+
@column_index += 1
|
251
|
+
end
|
252
|
+
|
253
|
+
def strikethrough(_)
|
254
|
+
out('<del>', :children, '</del>')
|
255
|
+
end
|
256
|
+
|
257
|
+
def footnote_reference(node)
|
258
|
+
label = node.parent_footnote_def.string_content
|
259
|
+
|
260
|
+
out("<sup class=\"footnote-ref\"><a href=\"#fn-#{label}\" id=\"fnref-#{label}\" data-footnote-ref>#{node.string_content}</a></sup>")
|
261
|
+
# out(node.to_html)
|
262
|
+
end
|
263
|
+
|
264
|
+
def footnote_definition(node)
|
265
|
+
unless @footnote_ix
|
266
|
+
out("<section class=\"footnotes\" data-footnotes>\n<ol>\n")
|
267
|
+
@footnote_ix = 0
|
268
|
+
end
|
269
|
+
|
270
|
+
@footnote_ix += 1
|
271
|
+
label = node.string_content
|
272
|
+
@footnotes[@footnote_ix] = label
|
273
|
+
|
274
|
+
out("<li id=\"fn-#{label}\">\n", :children)
|
275
|
+
out("\n") if out_footnote_backref
|
276
|
+
out("</li>\n")
|
277
|
+
# </ol>
|
278
|
+
# </section>
|
279
|
+
end
|
280
|
+
|
281
|
+
private
|
282
|
+
|
283
|
+
def out_footnote_backref
|
284
|
+
return false if @written_footnote_ix == @footnote_ix
|
285
|
+
|
286
|
+
@written_footnote_ix = @footnote_ix
|
287
|
+
|
288
|
+
out("<a href=\"#fnref-#{@footnotes[@footnote_ix]}\" class=\"footnote-backref\" data-footnote-backref data-footnote-backref-idx=\"#{@footnote_ix}\" aria-label=\"Back to reference #{@footnote_ix}\">↩</a>")
|
289
|
+
true
|
290
|
+
end
|
291
|
+
|
292
|
+
def tasklist?(node)
|
293
|
+
node.type_string == 'tasklist'
|
294
|
+
end
|
295
|
+
|
296
|
+
def checked?(node)
|
297
|
+
node.tasklist_item_checked?
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
282
301
|
end
|
data/lib/markly/version.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2015-2020, by Garen Torikian.
|
5
|
+
# Copyright, 2016-2017, by Yuki Izumi.
|
6
|
+
# Copyright, 2017-2018, by Ashe Connor.
|
7
|
+
# Copyright, 2020-2023, by Samuel Williams.
|
8
|
+
|
3
9
|
module Markly
|
4
|
-
VERSION = '0.
|
10
|
+
VERSION = '0.8.0'
|
5
11
|
end
|