commonmarker 0.23.7.pre1 → 1.0.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +70 -212
  3. data/commonmarker.gemspec +34 -31
  4. data/ext/commonmarker/Cargo.toml +12 -0
  5. data/ext/commonmarker/_util.rb +102 -0
  6. data/ext/commonmarker/extconf.rb +4 -5
  7. data/ext/commonmarker/src/comrak_options.rs +136 -0
  8. data/ext/commonmarker/src/lib.rs +29 -0
  9. data/lib/commonmarker/config.rb +57 -38
  10. data/lib/commonmarker/extension.rb +14 -0
  11. data/lib/commonmarker/renderer.rb +1 -127
  12. data/lib/commonmarker/version.rb +2 -2
  13. data/lib/commonmarker.rb +14 -29
  14. metadata +34 -178
  15. data/Rakefile +0 -109
  16. data/bin/commonmarker +0 -118
  17. data/ext/commonmarker/arena.c +0 -103
  18. data/ext/commonmarker/autolink.c +0 -456
  19. data/ext/commonmarker/autolink.h +0 -8
  20. data/ext/commonmarker/blocks.c +0 -1596
  21. data/ext/commonmarker/buffer.c +0 -278
  22. data/ext/commonmarker/buffer.h +0 -116
  23. data/ext/commonmarker/case_fold_switch.inc +0 -4327
  24. data/ext/commonmarker/chunk.h +0 -135
  25. data/ext/commonmarker/cmark-gfm-core-extensions.h +0 -54
  26. data/ext/commonmarker/cmark-gfm-extension_api.h +0 -736
  27. data/ext/commonmarker/cmark-gfm-extensions_export.h +0 -42
  28. data/ext/commonmarker/cmark-gfm.h +0 -817
  29. data/ext/commonmarker/cmark-gfm_export.h +0 -42
  30. data/ext/commonmarker/cmark-gfm_version.h +0 -7
  31. data/ext/commonmarker/cmark.c +0 -55
  32. data/ext/commonmarker/cmark_ctype.c +0 -44
  33. data/ext/commonmarker/cmark_ctype.h +0 -33
  34. data/ext/commonmarker/commonmark.c +0 -529
  35. data/ext/commonmarker/commonmarker.c +0 -1307
  36. data/ext/commonmarker/commonmarker.h +0 -16
  37. data/ext/commonmarker/config.h +0 -76
  38. data/ext/commonmarker/core-extensions.c +0 -27
  39. data/ext/commonmarker/entities.inc +0 -2138
  40. data/ext/commonmarker/ext_scanners.c +0 -879
  41. data/ext/commonmarker/ext_scanners.h +0 -24
  42. data/ext/commonmarker/footnotes.c +0 -63
  43. data/ext/commonmarker/footnotes.h +0 -27
  44. data/ext/commonmarker/houdini.h +0 -57
  45. data/ext/commonmarker/houdini_href_e.c +0 -100
  46. data/ext/commonmarker/houdini_html_e.c +0 -66
  47. data/ext/commonmarker/houdini_html_u.c +0 -149
  48. data/ext/commonmarker/html.c +0 -486
  49. data/ext/commonmarker/html.h +0 -27
  50. data/ext/commonmarker/inlines.c +0 -1716
  51. data/ext/commonmarker/inlines.h +0 -29
  52. data/ext/commonmarker/iterator.c +0 -159
  53. data/ext/commonmarker/iterator.h +0 -26
  54. data/ext/commonmarker/latex.c +0 -466
  55. data/ext/commonmarker/linked_list.c +0 -37
  56. data/ext/commonmarker/man.c +0 -278
  57. data/ext/commonmarker/map.c +0 -122
  58. data/ext/commonmarker/map.h +0 -41
  59. data/ext/commonmarker/node.c +0 -979
  60. data/ext/commonmarker/node.h +0 -125
  61. data/ext/commonmarker/parser.h +0 -58
  62. data/ext/commonmarker/plaintext.c +0 -235
  63. data/ext/commonmarker/plugin.c +0 -36
  64. data/ext/commonmarker/plugin.h +0 -34
  65. data/ext/commonmarker/references.c +0 -42
  66. data/ext/commonmarker/references.h +0 -26
  67. data/ext/commonmarker/registry.c +0 -63
  68. data/ext/commonmarker/registry.h +0 -24
  69. data/ext/commonmarker/render.c +0 -205
  70. data/ext/commonmarker/render.h +0 -62
  71. data/ext/commonmarker/scanners.c +0 -10508
  72. data/ext/commonmarker/scanners.h +0 -62
  73. data/ext/commonmarker/scanners.re +0 -341
  74. data/ext/commonmarker/strikethrough.c +0 -167
  75. data/ext/commonmarker/strikethrough.h +0 -9
  76. data/ext/commonmarker/syntax_extension.c +0 -149
  77. data/ext/commonmarker/syntax_extension.h +0 -34
  78. data/ext/commonmarker/table.c +0 -848
  79. data/ext/commonmarker/table.h +0 -12
  80. data/ext/commonmarker/tagfilter.c +0 -60
  81. data/ext/commonmarker/tagfilter.h +0 -8
  82. data/ext/commonmarker/tasklist.c +0 -156
  83. data/ext/commonmarker/tasklist.h +0 -8
  84. data/ext/commonmarker/utf8.c +0 -317
  85. data/ext/commonmarker/utf8.h +0 -35
  86. data/ext/commonmarker/xml.c +0 -181
  87. data/lib/commonmarker/node/inspect.rb +0 -47
  88. data/lib/commonmarker/node.rb +0 -83
  89. data/lib/commonmarker/renderer/html_renderer.rb +0 -252
@@ -1,181 +0,0 @@
1
- #include <stdlib.h>
2
- #include <stdio.h>
3
- #include <string.h>
4
- #include <assert.h>
5
-
6
- #include "config.h"
7
- #include "cmark-gfm.h"
8
- #include "node.h"
9
- #include "buffer.h"
10
- #include "houdini.h"
11
- #include "syntax_extension.h"
12
-
13
- #define BUFFER_SIZE 100
14
-
15
- // Functions to convert cmark_nodes to XML strings.
16
-
17
- static void escape_xml(cmark_strbuf *dest, const unsigned char *source,
18
- bufsize_t length) {
19
- houdini_escape_html0(dest, source, length, 0);
20
- }
21
-
22
- struct render_state {
23
- cmark_strbuf *xml;
24
- int indent;
25
- };
26
-
27
- static CMARK_INLINE void indent(struct render_state *state) {
28
- int i;
29
- for (i = 0; i < state->indent; i++) {
30
- cmark_strbuf_putc(state->xml, ' ');
31
- }
32
- }
33
-
34
- static int S_render_node(cmark_node *node, cmark_event_type ev_type,
35
- struct render_state *state, int options) {
36
- cmark_strbuf *xml = state->xml;
37
- bool literal = false;
38
- cmark_delim_type delim;
39
- bool entering = (ev_type == CMARK_EVENT_ENTER);
40
- char buffer[BUFFER_SIZE];
41
-
42
- if (entering) {
43
- indent(state);
44
- cmark_strbuf_putc(xml, '<');
45
- cmark_strbuf_puts(xml, cmark_node_get_type_string(node));
46
-
47
- if (options & CMARK_OPT_SOURCEPOS && node->start_line != 0) {
48
- snprintf(buffer, BUFFER_SIZE, " sourcepos=\"%d:%d-%d:%d\"",
49
- node->start_line, node->start_column, node->end_line,
50
- node->end_column);
51
- cmark_strbuf_puts(xml, buffer);
52
- }
53
-
54
- if (node->extension && node->extension->xml_attr_func) {
55
- const char* r = node->extension->xml_attr_func(node->extension, node);
56
- if (r != NULL)
57
- cmark_strbuf_puts(xml, r);
58
- }
59
-
60
- literal = false;
61
-
62
- switch (node->type) {
63
- case CMARK_NODE_DOCUMENT:
64
- cmark_strbuf_puts(xml, " xmlns=\"http://commonmark.org/xml/1.0\"");
65
- break;
66
- case CMARK_NODE_TEXT:
67
- case CMARK_NODE_CODE:
68
- case CMARK_NODE_HTML_BLOCK:
69
- case CMARK_NODE_HTML_INLINE:
70
- cmark_strbuf_puts(xml, " xml:space=\"preserve\">");
71
- escape_xml(xml, node->as.literal.data, node->as.literal.len);
72
- cmark_strbuf_puts(xml, "</");
73
- cmark_strbuf_puts(xml, cmark_node_get_type_string(node));
74
- literal = true;
75
- break;
76
- case CMARK_NODE_LIST:
77
- switch (cmark_node_get_list_type(node)) {
78
- case CMARK_ORDERED_LIST:
79
- cmark_strbuf_puts(xml, " type=\"ordered\"");
80
- snprintf(buffer, BUFFER_SIZE, " start=\"%d\"",
81
- cmark_node_get_list_start(node));
82
- cmark_strbuf_puts(xml, buffer);
83
- delim = cmark_node_get_list_delim(node);
84
- if (delim == CMARK_PAREN_DELIM) {
85
- cmark_strbuf_puts(xml, " delim=\"paren\"");
86
- } else if (delim == CMARK_PERIOD_DELIM) {
87
- cmark_strbuf_puts(xml, " delim=\"period\"");
88
- }
89
- break;
90
- case CMARK_BULLET_LIST:
91
- cmark_strbuf_puts(xml, " type=\"bullet\"");
92
- break;
93
- default:
94
- break;
95
- }
96
- snprintf(buffer, BUFFER_SIZE, " tight=\"%s\"",
97
- (cmark_node_get_list_tight(node) ? "true" : "false"));
98
- cmark_strbuf_puts(xml, buffer);
99
- break;
100
- case CMARK_NODE_HEADING:
101
- snprintf(buffer, BUFFER_SIZE, " level=\"%d\"", node->as.heading.level);
102
- cmark_strbuf_puts(xml, buffer);
103
- break;
104
- case CMARK_NODE_CODE_BLOCK:
105
- if (node->as.code.info.len > 0) {
106
- cmark_strbuf_puts(xml, " info=\"");
107
- escape_xml(xml, node->as.code.info.data, node->as.code.info.len);
108
- cmark_strbuf_putc(xml, '"');
109
- }
110
- cmark_strbuf_puts(xml, " xml:space=\"preserve\">");
111
- escape_xml(xml, node->as.code.literal.data, node->as.code.literal.len);
112
- cmark_strbuf_puts(xml, "</");
113
- cmark_strbuf_puts(xml, cmark_node_get_type_string(node));
114
- literal = true;
115
- break;
116
- case CMARK_NODE_CUSTOM_BLOCK:
117
- case CMARK_NODE_CUSTOM_INLINE:
118
- cmark_strbuf_puts(xml, " on_enter=\"");
119
- escape_xml(xml, node->as.custom.on_enter.data,
120
- node->as.custom.on_enter.len);
121
- cmark_strbuf_putc(xml, '"');
122
- cmark_strbuf_puts(xml, " on_exit=\"");
123
- escape_xml(xml, node->as.custom.on_exit.data,
124
- node->as.custom.on_exit.len);
125
- cmark_strbuf_putc(xml, '"');
126
- break;
127
- case CMARK_NODE_LINK:
128
- case CMARK_NODE_IMAGE:
129
- cmark_strbuf_puts(xml, " destination=\"");
130
- escape_xml(xml, node->as.link.url.data, node->as.link.url.len);
131
- cmark_strbuf_putc(xml, '"');
132
- cmark_strbuf_puts(xml, " title=\"");
133
- escape_xml(xml, node->as.link.title.data, node->as.link.title.len);
134
- cmark_strbuf_putc(xml, '"');
135
- break;
136
- default:
137
- break;
138
- }
139
- if (node->first_child) {
140
- state->indent += 2;
141
- } else if (!literal) {
142
- cmark_strbuf_puts(xml, " /");
143
- }
144
- cmark_strbuf_puts(xml, ">\n");
145
-
146
- } else if (node->first_child) {
147
- state->indent -= 2;
148
- indent(state);
149
- cmark_strbuf_puts(xml, "</");
150
- cmark_strbuf_puts(xml, cmark_node_get_type_string(node));
151
- cmark_strbuf_puts(xml, ">\n");
152
- }
153
-
154
- return 1;
155
- }
156
-
157
- char *cmark_render_xml(cmark_node *root, int options) {
158
- return cmark_render_xml_with_mem(root, options, cmark_node_mem(root));
159
- }
160
-
161
- char *cmark_render_xml_with_mem(cmark_node *root, int options, cmark_mem *mem) {
162
- char *result;
163
- cmark_strbuf xml = CMARK_BUF_INIT(mem);
164
- cmark_event_type ev_type;
165
- cmark_node *cur;
166
- struct render_state state = {&xml, 0};
167
-
168
- cmark_iter *iter = cmark_iter_new(root);
169
-
170
- cmark_strbuf_puts(state.xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
171
- cmark_strbuf_puts(state.xml,
172
- "<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n");
173
- while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
174
- cur = cmark_iter_get_node(iter);
175
- S_render_node(cur, ev_type, &state, options);
176
- }
177
- result = (char *)cmark_strbuf_detach(&xml);
178
-
179
- cmark_iter_free(iter);
180
- return result;
181
- }
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pp"
4
-
5
- module CommonMarker
6
- class Node
7
- module Inspect
8
- PP_INDENT_SIZE = 2
9
-
10
- def inspect
11
- PP.pp(self, +"", Float::INFINITY)
12
- end
13
-
14
- # @param printer [PrettyPrint] pp
15
- def pretty_print(printer)
16
- printer.group(PP_INDENT_SIZE, "#<#{self.class}(#{type}):", ">") do
17
- printer.breakable
18
-
19
- attrs = [:sourcepos, :string_content, :url, :title, :header_level, :list_type, :list_start, :list_tight, :fence_info].map do |name|
20
- [name, __send__(name)]
21
- rescue NodeError
22
- nil
23
- end.compact
24
-
25
- printer.seplist(attrs) do |name, value|
26
- printer.text("#{name}=")
27
- printer.pp(value)
28
- end
29
-
30
- if first_child
31
- printer.breakable
32
- printer.group(PP_INDENT_SIZE) do
33
- children = []
34
- node = first_child
35
- while node
36
- children << node
37
- node = node.next
38
- end
39
- printer.text("children=")
40
- printer.pp(children)
41
- end
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "commonmarker/node/inspect"
4
-
5
- module CommonMarker
6
- class Node
7
- include Enumerable
8
- include Inspect
9
-
10
- # Public: An iterator that "walks the tree," descending into children recursively.
11
- #
12
- # blk - A {Proc} representing the action to take for each child
13
- def walk(&block)
14
- return enum_for(:walk) unless block
15
-
16
- yield self
17
- each do |child|
18
- child.walk(&block)
19
- end
20
- end
21
-
22
- # Public: Convert the node to an HTML string.
23
- #
24
- # options - A {Symbol} or {Array of Symbol}s indicating the render options
25
- # extensions - An {Array of Symbol}s indicating the extensions to use
26
- #
27
- # Returns a {String}.
28
- def to_html(options = :DEFAULT, extensions = [])
29
- opts = Config.process_options(options, :render)
30
- _render_html(opts, extensions).force_encoding("utf-8")
31
- end
32
-
33
- # Public: Convert the node to an XML string.
34
- #
35
- # options - A {Symbol} or {Array of Symbol}s indicating the render options
36
- #
37
- # Returns a {String}.
38
- def to_xml(options = :DEFAULT)
39
- opts = Config.process_options(options, :render)
40
- _render_xml(opts).force_encoding("utf-8")
41
- end
42
-
43
- # Public: Convert the node to a CommonMark string.
44
- #
45
- # options - A {Symbol} or {Array of Symbol}s indicating the render options
46
- # width - Column to wrap the output at
47
- #
48
- # Returns a {String}.
49
- def to_commonmark(options = :DEFAULT, width = 120)
50
- opts = Config.process_options(options, :render)
51
- _render_commonmark(opts, width).force_encoding("utf-8")
52
- end
53
-
54
- # Public: Convert the node to a plain text string.
55
- #
56
- # options - A {Symbol} or {Array of Symbol}s indicating the render options
57
- # width - Column to wrap the output at
58
- #
59
- # Returns a {String}.
60
- def to_plaintext(options = :DEFAULT, width = 120)
61
- opts = Config.process_options(options, :render)
62
- _render_plaintext(opts, width).force_encoding("utf-8")
63
- end
64
-
65
- # Public: Iterate over the children (if any) of the current pointer.
66
- def each
67
- return enum_for(:each) unless block_given?
68
-
69
- child = first_child
70
- while child
71
- nextchild = child.next
72
- yield child
73
- child = nextchild
74
- end
75
- end
76
-
77
- # Deprecated: Please use `each` instead
78
- def each_child(&block)
79
- warn("[DEPRECATION] `each_child` is deprecated. Please use `each` instead.")
80
- each(&block)
81
- end
82
- end
83
- end
@@ -1,252 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CommonMarker
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, "#{sourcepos(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#{sourcepos(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#{sourcepos(node)}>\n", "</ul>") do
40
- out(:children)
41
- end
42
- else
43
- start = if node.list_start == 1
44
- "<ol#{sourcepos(node)}>\n"
45
- else
46
- "<ol start=\"#{node.list_start}\"#{sourcepos(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#{sourcepos(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#{sourcepos(node)}>\n", "</blockquote>") do
80
- out(:children)
81
- end
82
- end
83
- end
84
-
85
- def hrule(node)
86
- block do
87
- out("<hr#{sourcepos(node)} />")
88
- end
89
- end
90
-
91
- def code_block(node)
92
- block do
93
- if option_enabled?(:GITHUB_PRE_LANG)
94
- out("<pre#{sourcepos(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#{sourcepos(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 option_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 option_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 option_enabled?(:HARDBREAKS)
167
- out("<br />\n")
168
- elsif option_enabled?(:NOBREAKS)
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#{sourcepos(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#{sourcepos(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#{sourcepos(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}#{sourcepos(node)}>" : "<td#{align}#{sourcepos(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