markly 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/bin/markly +94 -0
  3. data/ext/markly/arena.c +103 -0
  4. data/ext/markly/autolink.c +425 -0
  5. data/ext/markly/autolink.h +8 -0
  6. data/ext/markly/blocks.c +1585 -0
  7. data/ext/markly/buffer.c +278 -0
  8. data/ext/markly/buffer.h +116 -0
  9. data/ext/markly/case_fold_switch.inc +4327 -0
  10. data/ext/markly/chunk.h +135 -0
  11. data/ext/markly/cmark-gfm-core-extensions.h +54 -0
  12. data/ext/markly/cmark-gfm-extension_api.h +736 -0
  13. data/ext/markly/cmark-gfm-extensions_export.h +42 -0
  14. data/ext/markly/cmark-gfm.h +817 -0
  15. data/ext/markly/cmark-gfm_export.h +42 -0
  16. data/ext/markly/cmark-gfm_version.h +7 -0
  17. data/ext/markly/cmark.c +55 -0
  18. data/ext/markly/cmark_ctype.c +44 -0
  19. data/ext/markly/cmark_ctype.h +33 -0
  20. data/ext/markly/commonmark.c +519 -0
  21. data/ext/markly/config.h +76 -0
  22. data/ext/markly/core-extensions.c +27 -0
  23. data/ext/markly/entities.inc +2138 -0
  24. data/ext/markly/ext_scanners.c +1159 -0
  25. data/ext/markly/ext_scanners.h +24 -0
  26. data/ext/markly/extconf.rb +7 -0
  27. data/ext/markly/footnotes.c +40 -0
  28. data/ext/markly/footnotes.h +25 -0
  29. data/ext/markly/houdini.h +57 -0
  30. data/ext/markly/houdini_href_e.c +100 -0
  31. data/ext/markly/houdini_html_e.c +66 -0
  32. data/ext/markly/houdini_html_u.c +149 -0
  33. data/ext/markly/html.c +465 -0
  34. data/ext/markly/html.h +27 -0
  35. data/ext/markly/inlines.c +1633 -0
  36. data/ext/markly/inlines.h +29 -0
  37. data/ext/markly/iterator.c +159 -0
  38. data/ext/markly/iterator.h +26 -0
  39. data/ext/markly/latex.c +466 -0
  40. data/ext/markly/linked_list.c +37 -0
  41. data/ext/markly/man.c +278 -0
  42. data/ext/markly/map.c +122 -0
  43. data/ext/markly/map.h +41 -0
  44. data/ext/markly/markly.c +1226 -0
  45. data/ext/markly/markly.h +16 -0
  46. data/ext/markly/node.c +979 -0
  47. data/ext/markly/node.h +118 -0
  48. data/ext/markly/parser.h +58 -0
  49. data/ext/markly/plaintext.c +235 -0
  50. data/ext/markly/plugin.c +36 -0
  51. data/ext/markly/plugin.h +34 -0
  52. data/ext/markly/references.c +42 -0
  53. data/ext/markly/references.h +26 -0
  54. data/ext/markly/registry.c +63 -0
  55. data/ext/markly/registry.h +24 -0
  56. data/ext/markly/render.c +205 -0
  57. data/ext/markly/render.h +62 -0
  58. data/ext/markly/scanners.c +20382 -0
  59. data/ext/markly/scanners.h +62 -0
  60. data/ext/markly/scanners.re +326 -0
  61. data/ext/markly/strikethrough.c +167 -0
  62. data/ext/markly/strikethrough.h +9 -0
  63. data/ext/markly/syntax_extension.c +149 -0
  64. data/ext/markly/syntax_extension.h +34 -0
  65. data/ext/markly/table.c +803 -0
  66. data/ext/markly/table.h +12 -0
  67. data/ext/markly/tagfilter.c +60 -0
  68. data/ext/markly/tagfilter.h +8 -0
  69. data/ext/markly/tasklist.c +156 -0
  70. data/ext/markly/tasklist.h +8 -0
  71. data/ext/markly/utf8.c +317 -0
  72. data/ext/markly/utf8.h +35 -0
  73. data/ext/markly/xml.c +181 -0
  74. data/lib/markly.rb +43 -0
  75. data/lib/markly/flags.rb +37 -0
  76. data/lib/markly/markly.so +0 -0
  77. data/lib/markly/node.rb +70 -0
  78. data/lib/markly/node/inspect.rb +59 -0
  79. data/lib/markly/renderer.rb +133 -0
  80. data/lib/markly/renderer/html_renderer.rb +252 -0
  81. data/lib/markly/version.rb +5 -0
  82. metadata +211 -0
@@ -0,0 +1,252 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Markly
4
+ class HtmlRenderer < Renderer
5
+ def document(_)
6
+ super
7
+ out("</ol>\n</section>\n") if @written_footnote_ix
8
+ end
9
+
10
+ def header(node)
11
+ block do
12
+ out('<h', node.header_level, "#{source_position(node)}>", :children,
13
+ '</h', node.header_level, '>')
14
+ end
15
+ end
16
+
17
+ def paragraph(node)
18
+ if @in_tight && node.parent.type != :blockquote
19
+ out(:children)
20
+ else
21
+ block do
22
+ container("<p#{source_position(node)}>", '</p>') do
23
+ out(:children)
24
+ if node.parent.type == :footnote_definition && node.next.nil?
25
+ out(' ')
26
+ out_footnote_backref
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def list(node)
34
+ old_in_tight = @in_tight
35
+ @in_tight = node.list_tight
36
+
37
+ block do
38
+ if node.list_type == :bullet_list
39
+ container("<ul#{source_position(node)}>\n", '</ul>') do
40
+ out(:children)
41
+ end
42
+ else
43
+ start = if node.list_start == 1
44
+ "<ol#{source_position(node)}>\n"
45
+ else
46
+ "<ol start=\"#{node.list_start}\"#{source_position(node)}>\n"
47
+ end
48
+ container(start, '</ol>') do
49
+ out(:children)
50
+ end
51
+ end
52
+ end
53
+
54
+ @in_tight = old_in_tight
55
+ end
56
+
57
+ def list_item(node)
58
+ block do
59
+ tasklist_data = tasklist(node)
60
+ container("<li#{source_position(node)}#{tasklist_data}>#{' ' if tasklist?(node)}", '</li>') do
61
+ out(:children)
62
+ end
63
+ end
64
+ end
65
+
66
+ def tasklist(node)
67
+ return '' unless tasklist?(node)
68
+
69
+ state = if checked?(node)
70
+ 'checked="" disabled=""'
71
+ else
72
+ 'disabled=""'
73
+ end
74
+ "><input type=\"checkbox\" #{state} /"
75
+ end
76
+
77
+ def blockquote(node)
78
+ block do
79
+ container("<blockquote#{source_position(node)}>\n", '</blockquote>') do
80
+ out(:children)
81
+ end
82
+ end
83
+ end
84
+
85
+ def hrule(node)
86
+ block do
87
+ out("<hr#{source_position(node)} />")
88
+ end
89
+ end
90
+
91
+ def code_block(node)
92
+ block do
93
+ if flag_enabled?(GITHUB_PRE_LANG)
94
+ out("<pre#{source_position(node)}")
95
+ out(' lang="', node.fence_info.split(/\s+/)[0], '"') if node.fence_info && !node.fence_info.empty?
96
+ out('><code>')
97
+ else
98
+ out("<pre#{source_position(node)}><code")
99
+ if node.fence_info && !node.fence_info.empty?
100
+ out(' class="language-', node.fence_info.split(/\s+/)[0], '">')
101
+ else
102
+ out('>')
103
+ end
104
+ end
105
+ out(escape_html(node.string_content))
106
+ out('</code></pre>')
107
+ end
108
+ end
109
+
110
+ def html(node)
111
+ block do
112
+ if flag_enabled?(UNSAFE)
113
+ out(tagfilter(node.string_content))
114
+ else
115
+ out('<!-- raw HTML omitted -->')
116
+ end
117
+ end
118
+ end
119
+
120
+ def inline_html(node)
121
+ if flag_enabled?(UNSAFE)
122
+ out(tagfilter(node.string_content))
123
+ else
124
+ out('<!-- raw HTML omitted -->')
125
+ end
126
+ end
127
+
128
+ def emph(_)
129
+ out('<em>', :children, '</em>')
130
+ end
131
+
132
+ def strong(_)
133
+ out('<strong>', :children, '</strong>')
134
+ end
135
+
136
+ def link(node)
137
+ out('<a href="', node.url.nil? ? '' : escape_href(node.url), '"')
138
+ out(' title="', escape_html(node.title), '"') if node.title && !node.title.empty?
139
+ out('>', :children, '</a>')
140
+ end
141
+
142
+ def image(node)
143
+ out('<img src="', escape_href(node.url), '"')
144
+ plain do
145
+ out(' alt="', :children, '"')
146
+ end
147
+ out(' title="', escape_html(node.title), '"') if node.title && !node.title.empty?
148
+ out(' />')
149
+ end
150
+
151
+ def text(node)
152
+ out(escape_html(node.string_content))
153
+ end
154
+
155
+ def code(node)
156
+ out('<code>')
157
+ out(escape_html(node.string_content))
158
+ out('</code>')
159
+ end
160
+
161
+ def linebreak(_node)
162
+ out("<br />\n")
163
+ end
164
+
165
+ def softbreak(_)
166
+ if flag_enabled?(HARD_BREAKS)
167
+ out("<br />\n")
168
+ elsif flag_enabled?(NO_BREAKS)
169
+ out(' ')
170
+ else
171
+ out("\n")
172
+ end
173
+ end
174
+
175
+ def table(node)
176
+ @alignments = node.table_alignments
177
+ @needs_close_tbody = false
178
+ out("<table#{source_position(node)}>\n", :children)
179
+ out("</tbody>\n") if @needs_close_tbody
180
+ out("</table>\n")
181
+ end
182
+
183
+ def table_header(node)
184
+ @column_index = 0
185
+
186
+ @in_header = true
187
+ out("<thead>\n<tr#{source_position(node)}>\n", :children, "</tr>\n</thead>\n")
188
+ @in_header = false
189
+ end
190
+
191
+ def table_row(node)
192
+ @column_index = 0
193
+ if !@in_header && !@needs_close_tbody
194
+ @needs_close_tbody = true
195
+ out("<tbody>\n")
196
+ end
197
+ out("<tr#{source_position(node)}>\n", :children, "</tr>\n")
198
+ end
199
+
200
+ def table_cell(node)
201
+ align = case @alignments[@column_index]
202
+ when :left then ' align="left"'
203
+ when :right then ' align="right"'
204
+ when :center then ' align="center"'
205
+ else; ''
206
+ end
207
+ out(@in_header ? "<th#{align}#{source_position(node)}>" : "<td#{align}#{source_position(node)}>", :children, @in_header ? "</th>\n" : "</td>\n")
208
+ @column_index += 1
209
+ end
210
+
211
+ def strikethrough(_)
212
+ out('<del>', :children, '</del>')
213
+ end
214
+
215
+ def footnote_reference(node)
216
+ out("<sup class=\"footnote-ref\"><a href=\"#fn#{node.string_content}\" id=\"fnref#{node.string_content}\">#{node.string_content}</a></sup>")
217
+ end
218
+
219
+ def footnote_definition(_)
220
+ unless @footnote_ix
221
+ out("<section class=\"footnotes\">\n<ol>\n")
222
+ @footnote_ix = 0
223
+ end
224
+
225
+ @footnote_ix += 1
226
+ out("<li id=\"fn#{@footnote_ix}\">\n", :children)
227
+ out("\n") if out_footnote_backref
228
+ out("</li>\n")
229
+ # </ol>
230
+ # </section>
231
+ end
232
+
233
+ private
234
+
235
+ def out_footnote_backref
236
+ return false if @written_footnote_ix == @footnote_ix
237
+
238
+ @written_footnote_ix = @footnote_ix
239
+
240
+ out("<a href=\"#fnref#{@footnote_ix}\" class=\"footnote-backref\">↩</a>")
241
+ true
242
+ end
243
+
244
+ def tasklist?(node)
245
+ node.type_string == 'tasklist'
246
+ end
247
+
248
+ def checked?(node)
249
+ node.tasklist_item_checked?
250
+ end
251
+ end
252
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Markly
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Garen Torikian
8
+ - Ashe Connor
9
+ - Samuel Williams
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2020-05-24 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: bake-bundler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: bake-modernize
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: minitest
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '5.6'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '5.6'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rake
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rake-compiler
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '0.9'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: '0.9'
99
+ description:
100
+ email:
101
+ executables:
102
+ - markly
103
+ extensions:
104
+ - ext/markly/extconf.rb
105
+ extra_rdoc_files: []
106
+ files:
107
+ - bin/markly
108
+ - ext/markly/arena.c
109
+ - ext/markly/autolink.c
110
+ - ext/markly/autolink.h
111
+ - ext/markly/blocks.c
112
+ - ext/markly/buffer.c
113
+ - ext/markly/buffer.h
114
+ - ext/markly/case_fold_switch.inc
115
+ - ext/markly/chunk.h
116
+ - ext/markly/cmark-gfm-core-extensions.h
117
+ - ext/markly/cmark-gfm-extension_api.h
118
+ - ext/markly/cmark-gfm-extensions_export.h
119
+ - ext/markly/cmark-gfm.h
120
+ - ext/markly/cmark-gfm_export.h
121
+ - ext/markly/cmark-gfm_version.h
122
+ - ext/markly/cmark.c
123
+ - ext/markly/cmark_ctype.c
124
+ - ext/markly/cmark_ctype.h
125
+ - ext/markly/commonmark.c
126
+ - ext/markly/config.h
127
+ - ext/markly/core-extensions.c
128
+ - ext/markly/entities.inc
129
+ - ext/markly/ext_scanners.c
130
+ - ext/markly/ext_scanners.h
131
+ - ext/markly/extconf.rb
132
+ - ext/markly/footnotes.c
133
+ - ext/markly/footnotes.h
134
+ - ext/markly/houdini.h
135
+ - ext/markly/houdini_href_e.c
136
+ - ext/markly/houdini_html_e.c
137
+ - ext/markly/houdini_html_u.c
138
+ - ext/markly/html.c
139
+ - ext/markly/html.h
140
+ - ext/markly/inlines.c
141
+ - ext/markly/inlines.h
142
+ - ext/markly/iterator.c
143
+ - ext/markly/iterator.h
144
+ - ext/markly/latex.c
145
+ - ext/markly/linked_list.c
146
+ - ext/markly/man.c
147
+ - ext/markly/map.c
148
+ - ext/markly/map.h
149
+ - ext/markly/markly.c
150
+ - ext/markly/markly.h
151
+ - ext/markly/node.c
152
+ - ext/markly/node.h
153
+ - ext/markly/parser.h
154
+ - ext/markly/plaintext.c
155
+ - ext/markly/plugin.c
156
+ - ext/markly/plugin.h
157
+ - ext/markly/references.c
158
+ - ext/markly/references.h
159
+ - ext/markly/registry.c
160
+ - ext/markly/registry.h
161
+ - ext/markly/render.c
162
+ - ext/markly/render.h
163
+ - ext/markly/scanners.c
164
+ - ext/markly/scanners.h
165
+ - ext/markly/scanners.re
166
+ - ext/markly/strikethrough.c
167
+ - ext/markly/strikethrough.h
168
+ - ext/markly/syntax_extension.c
169
+ - ext/markly/syntax_extension.h
170
+ - ext/markly/table.c
171
+ - ext/markly/table.h
172
+ - ext/markly/tagfilter.c
173
+ - ext/markly/tagfilter.h
174
+ - ext/markly/tasklist.c
175
+ - ext/markly/tasklist.h
176
+ - ext/markly/utf8.c
177
+ - ext/markly/utf8.h
178
+ - ext/markly/xml.c
179
+ - lib/markly.rb
180
+ - lib/markly/flags.rb
181
+ - lib/markly/markly.so
182
+ - lib/markly/node.rb
183
+ - lib/markly/node/inspect.rb
184
+ - lib/markly/renderer.rb
185
+ - lib/markly/renderer/html_renderer.rb
186
+ - lib/markly/version.rb
187
+ homepage: https://github.com/ioquatix/markly
188
+ licenses:
189
+ - MIT
190
+ metadata:
191
+ funding_uri: https://github.com/sponsors/ioquatix/
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '2.5'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubygems_version: 3.1.2
208
+ signing_key:
209
+ specification_version: 4
210
+ summary: CommonMark parser and renderer. Written in C, wrapped in Ruby.
211
+ test_files: []