commonmarker 0.10.0 → 0.11.0
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 +3 -0
- data/bin/commonmarker +19 -3
- data/ext/commonmarker/cmark/CMakeLists.txt +1 -0
- data/ext/commonmarker/cmark/COPYING +2 -24
- data/ext/commonmarker/cmark/Makefile +25 -5
- data/ext/commonmarker/cmark/README.md +1 -1
- data/ext/commonmarker/cmark/api_test/CMakeLists.txt +1 -1
- data/ext/commonmarker/cmark/api_test/main.c +25 -27
- data/ext/commonmarker/cmark/build/CMakeCache.txt +12 -9
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeCCompiler.cmake +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeCXXCompiler.cmake +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeDetermineCompilerABI_C.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeDetermineCompilerABI_CXX.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CMakeSystem.cmake +4 -4
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CompilerIdC/CMakeCCompilerId.c +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CompilerIdC/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.6.0 → 3.6.1}/CompilerIdCXX/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +6 -6
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +148 -148
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +41 -109
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile2 +66 -10
- data/ext/commonmarker/cmark/build/CMakeFiles/TargetDirectories.txt +8 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/progress.marks +1 -1
- data/ext/commonmarker/cmark/build/CTestTestfile.cmake +1 -0
- data/ext/commonmarker/cmark/build/Makefile +23 -9
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +2 -2
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/progress.marks +1 -1
- data/ext/commonmarker/cmark/build/api_test/Makefile +9 -9
- data/ext/commonmarker/cmark/build/cmake_install.cmake +1 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/CMakeDirectoryInformation.cmake +16 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/C.includecache +190 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/DependInfo.cmake +29 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/autolink.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/build.make +249 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/cmake_clean.cmake +15 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/cmake_clean_target.cmake +3 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/core-extensions.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/depend.internal +92 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/depend.make +92 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/ext_scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/flags.make +10 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/link.txt +2 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/progress.make +8 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/strikethrough.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/table.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmarkextensions_static.dir/whitelist.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/progress.marks +1 -0
- data/ext/commonmarker/cmark/build/extensions/Makefile +390 -0
- data/ext/commonmarker/cmark/build/extensions/cmake_install.cmake +29 -0
- data/ext/commonmarker/cmark/build/extensions/libcmarkextensions.a +0 -0
- data/ext/commonmarker/cmark/build/man/Makefile +9 -9
- data/ext/commonmarker/cmark/build/src/CMakeFiles/Export/lib/cmake/cmark.cmake +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/DependInfo.cmake +7 -19
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/build.make +6 -517
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmake_clean.cmake +0 -19
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/flags.make +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/progress.make +0 -19
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +9 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +112 -4
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +4 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/flags.make +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/progress.make +24 -20
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/C.includecache +144 -10
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/DependInfo.cmake +9 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/build.make +112 -4
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean.cmake +4 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.internal +74 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.make +74 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/flags.make +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/iterator.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/latex.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/linked_list.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/man.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/plugin.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/progress.make +24 -20
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/registry.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/syntax_extension.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/progress.marks +1 -1
- data/ext/commonmarker/cmark/build/src/Makefile +141 -66
- data/ext/commonmarker/cmark/build/src/cmake_install.cmake +4 -0
- data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
- data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +3 -1
- data/ext/commonmarker/cmark/build/testdir/Makefile +9 -9
- data/ext/commonmarker/cmark/extensions/CMakeLists.txt +82 -0
- data/ext/commonmarker/cmark/extensions/autolink.c +338 -0
- data/ext/commonmarker/cmark/extensions/autolink.h +8 -0
- data/ext/commonmarker/cmark/extensions/core-extensions.c +16 -0
- data/ext/commonmarker/cmark/extensions/core-extensions.h +16 -0
- data/ext/commonmarker/cmark/extensions/ext_scanners.c +585 -0
- data/ext/commonmarker/cmark/extensions/ext_scanners.h +20 -0
- data/ext/commonmarker/cmark/extensions/ext_scanners.re +65 -0
- data/ext/commonmarker/cmark/extensions/strikethrough.c +142 -0
- data/ext/commonmarker/cmark/extensions/strikethrough.h +9 -0
- data/ext/commonmarker/cmark/extensions/table.c +493 -0
- data/ext/commonmarker/cmark/extensions/table.h +8 -0
- data/ext/commonmarker/cmark/extensions/whitelist.c +59 -0
- data/ext/commonmarker/cmark/extensions/whitelist.h +8 -0
- data/ext/commonmarker/cmark/man/man3/cmark.3 +98 -34
- data/ext/commonmarker/cmark/src/CMakeLists.txt +16 -1
- data/ext/commonmarker/cmark/src/blocks.c +219 -40
- data/ext/commonmarker/cmark/src/buffer.h +36 -0
- data/ext/commonmarker/cmark/src/cmark.c +5 -1
- data/ext/commonmarker/cmark/src/cmark.h +91 -34
- data/ext/commonmarker/cmark/src/cmark_ctype.h +7 -0
- data/ext/commonmarker/cmark/src/cmark_extension_api.h +655 -0
- data/ext/commonmarker/cmark/src/commonmark.c +7 -2
- data/ext/commonmarker/cmark/src/houdini.h +12 -6
- data/ext/commonmarker/cmark/src/houdini_html_e.c +1 -1
- data/ext/commonmarker/cmark/src/html.c +102 -54
- data/ext/commonmarker/cmark/src/html.h +27 -0
- data/ext/commonmarker/cmark/src/inlines.c +261 -53
- data/ext/commonmarker/cmark/src/inlines.h +7 -2
- data/ext/commonmarker/cmark/src/iterator.c +12 -7
- data/ext/commonmarker/cmark/src/latex.c +5 -2
- data/ext/commonmarker/cmark/src/linked_list.c +37 -0
- data/ext/commonmarker/cmark/src/main.c +91 -27
- data/ext/commonmarker/cmark/src/man.c +18 -2
- data/ext/commonmarker/cmark/src/node.c +157 -58
- data/ext/commonmarker/cmark/src/node.h +23 -0
- data/ext/commonmarker/cmark/src/parser.h +19 -2
- data/ext/commonmarker/cmark/src/plugin.c +33 -0
- data/ext/commonmarker/cmark/src/plugin.h +34 -0
- data/ext/commonmarker/cmark/src/registry.c +60 -0
- data/ext/commonmarker/cmark/src/registry.h +24 -0
- data/ext/commonmarker/cmark/src/render.h +9 -0
- data/ext/commonmarker/cmark/src/scanners.c +265 -391
- data/ext/commonmarker/cmark/src/scanners.h +5 -0
- data/ext/commonmarker/cmark/src/scanners.re +2 -2
- data/ext/commonmarker/cmark/src/syntax_extension.c +110 -0
- data/ext/commonmarker/cmark/src/syntax_extension.h +27 -0
- data/ext/commonmarker/cmark/suppressions +28 -0
- data/ext/commonmarker/cmark/test/CMakeLists.txt +12 -1
- data/ext/commonmarker/cmark/test/extensions.txt +173 -0
- data/ext/commonmarker/cmark/test/regression.txt +24 -0
- data/ext/commonmarker/cmark/test/spec.txt +27 -26
- data/ext/commonmarker/cmark/toolchain-mingw32.cmake +1 -1
- data/ext/commonmarker/commonmarker.c +132 -15
- data/ext/commonmarker/commonmarker.h +4 -0
- data/ext/commonmarker/extconf.rb +12 -5
- data/lib/commonmarker.rb +8 -6
- data/lib/commonmarker/node.rb +13 -2
- data/lib/commonmarker/renderer.rb +1 -1
- data/lib/commonmarker/version.rb +1 -1
- data/test/test_commonmark.rb +34 -0
- data/test/test_encoding.rb +2 -1
- data/test/test_extensions.rb +50 -0
- data/test/test_helper.rb +2 -1
- metadata +65 -11
@@ -9,7 +9,7 @@ SET(CMAKE_RC_COMPILER i586-mingw32msvc-windres)
|
|
9
9
|
# here is the target environment located
|
10
10
|
SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc "${CMAKE_SOURCE_DIR}/windows")
|
11
11
|
|
12
|
-
# adjust the default behaviour of the
|
12
|
+
# adjust the default behaviour of the FIND_XYZ() commands:
|
13
13
|
# search headers and libraries in the target environment, search
|
14
14
|
# programs in the host environment
|
15
15
|
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
@@ -2,6 +2,10 @@
|
|
2
2
|
#include "cmark.h"
|
3
3
|
#include "houdini.h"
|
4
4
|
#include "node.h"
|
5
|
+
#include "registry.h"
|
6
|
+
#include "parser.h"
|
7
|
+
#include "syntax_extension.h"
|
8
|
+
#include "core-extensions.h"
|
5
9
|
|
6
10
|
static VALUE rb_mNodeError;
|
7
11
|
static VALUE rb_mNode;
|
@@ -91,24 +95,69 @@ static void rb_parent_removed(VALUE val) {
|
|
91
95
|
RDATA(val)->dfree = rb_free_c_struct;
|
92
96
|
}
|
93
97
|
|
98
|
+
static cmark_parser *prepare_parser(VALUE rb_options, VALUE rb_extensions) {
|
99
|
+
int options;
|
100
|
+
int extensions_len;
|
101
|
+
VALUE rb_ext_name;
|
102
|
+
int i;
|
103
|
+
|
104
|
+
Check_Type(rb_options, T_FIXNUM);
|
105
|
+
Check_Type(rb_extensions, T_ARRAY);
|
106
|
+
|
107
|
+
options = FIX2INT(rb_options);
|
108
|
+
extensions_len = RARRAY_LEN(rb_extensions);
|
109
|
+
|
110
|
+
cmark_parser *parser = cmark_parser_new(options);
|
111
|
+
for (i = 0; i < extensions_len; ++i) {
|
112
|
+
rb_ext_name = RARRAY_PTR(rb_extensions)[i];
|
113
|
+
|
114
|
+
if (!SYMBOL_P(rb_ext_name)) {
|
115
|
+
cmark_parser_free(parser);
|
116
|
+
rb_raise(rb_eTypeError, "extension names should be Symbols; got a %"PRIsVALUE"", rb_obj_class(rb_ext_name));
|
117
|
+
}
|
118
|
+
|
119
|
+
cmark_syntax_extension *syntax_extension =
|
120
|
+
cmark_find_syntax_extension(rb_id2name(SYM2ID(rb_ext_name)));
|
121
|
+
|
122
|
+
if (!syntax_extension) {
|
123
|
+
cmark_parser_free(parser);
|
124
|
+
rb_raise(rb_eArgError, "extension %s not found", rb_id2name(SYM2ID(rb_ext_name)));
|
125
|
+
}
|
126
|
+
|
127
|
+
cmark_parser_attach_syntax_extension(parser, syntax_extension);
|
128
|
+
}
|
129
|
+
|
130
|
+
return parser;
|
131
|
+
}
|
132
|
+
|
94
133
|
/*
|
95
134
|
* Internal: Parses a Markdown string into an HTML string.
|
96
135
|
*
|
97
136
|
*/
|
98
|
-
static VALUE rb_markdown_to_html(VALUE self, VALUE rb_text, VALUE rb_options) {
|
99
|
-
char *str;
|
100
|
-
int len
|
101
|
-
|
137
|
+
static VALUE rb_markdown_to_html(VALUE self, VALUE rb_text, VALUE rb_options, VALUE rb_extensions) {
|
138
|
+
char *str, *html;
|
139
|
+
int len;
|
140
|
+
cmark_parser *parser;
|
141
|
+
cmark_node *doc;
|
102
142
|
Check_Type(rb_text, T_STRING);
|
103
143
|
Check_Type(rb_options, T_FIXNUM);
|
104
144
|
|
145
|
+
parser = prepare_parser(rb_options, rb_extensions);
|
146
|
+
|
105
147
|
str = (char *)RSTRING_PTR(rb_text);
|
106
148
|
len = RSTRING_LEN(rb_text);
|
107
|
-
options = FIX2INT(rb_options);
|
108
149
|
|
109
|
-
|
110
|
-
|
150
|
+
cmark_parser_feed(parser, str, len);
|
151
|
+
doc = cmark_parser_finish(parser);
|
152
|
+
if (doc == NULL) {
|
153
|
+
rb_raise(rb_mNodeError, "error parsing document");
|
154
|
+
}
|
111
155
|
|
156
|
+
html = cmark_render_html(doc, FIX2INT(rb_options), parser->syntax_extensions);
|
157
|
+
cmark_parser_free(parser);
|
158
|
+
cmark_node_free(doc);
|
159
|
+
|
160
|
+
VALUE ruby_html = rb_str_new2(html);
|
112
161
|
free(html);
|
113
162
|
|
114
163
|
return ruby_html;
|
@@ -196,22 +245,27 @@ static VALUE rb_node_new(VALUE self, VALUE type) {
|
|
196
245
|
*
|
197
246
|
*/
|
198
247
|
static VALUE rb_parse_document(VALUE self, VALUE rb_text, VALUE rb_len,
|
199
|
-
VALUE rb_options) {
|
248
|
+
VALUE rb_options, VALUE rb_extensions) {
|
200
249
|
char *text;
|
201
250
|
int len, options;
|
251
|
+
cmark_parser *parser;
|
202
252
|
cmark_node *doc;
|
203
253
|
Check_Type(rb_text, T_STRING);
|
204
254
|
Check_Type(rb_len, T_FIXNUM);
|
205
255
|
Check_Type(rb_options, T_FIXNUM);
|
206
256
|
|
257
|
+
parser = prepare_parser(rb_options, rb_extensions);
|
258
|
+
|
207
259
|
text = (char *)RSTRING_PTR(rb_text);
|
208
260
|
len = FIX2INT(rb_len);
|
209
261
|
options = FIX2INT(rb_options);
|
210
262
|
|
211
|
-
|
263
|
+
cmark_parser_feed(parser, text, len);
|
264
|
+
doc = cmark_parser_finish(parser);
|
212
265
|
if (doc == NULL) {
|
213
266
|
rb_raise(rb_mNodeError, "error parsing document");
|
214
267
|
}
|
268
|
+
cmark_parser_free(parser);
|
215
269
|
|
216
270
|
return rb_node_to_value(doc);
|
217
271
|
}
|
@@ -439,23 +493,67 @@ static VALUE rb_node_insert_before(VALUE self, VALUE sibling) {
|
|
439
493
|
*
|
440
494
|
* Returns a {String}.
|
441
495
|
*/
|
442
|
-
static VALUE rb_render_html(VALUE n, VALUE rb_options) {
|
443
|
-
int options;
|
496
|
+
static VALUE rb_render_html(VALUE n, VALUE rb_options, VALUE rb_extensions) {
|
497
|
+
int options, extensions_len;
|
498
|
+
VALUE rb_ext_name;
|
499
|
+
int i;
|
444
500
|
cmark_node *node;
|
501
|
+
cmark_llist *extensions = NULL;
|
445
502
|
Check_Type(rb_options, T_FIXNUM);
|
503
|
+
Check_Type(rb_extensions, T_ARRAY);
|
446
504
|
|
447
505
|
options = FIX2INT(rb_options);
|
506
|
+
extensions_len = RARRAY_LEN(rb_extensions);
|
448
507
|
|
449
508
|
Data_Get_Struct(n, cmark_node, node);
|
450
509
|
|
451
|
-
|
510
|
+
for (i = 0; i < extensions_len; ++i) {
|
511
|
+
rb_ext_name = RARRAY_PTR(rb_extensions)[i];
|
512
|
+
|
513
|
+
if (!SYMBOL_P(rb_ext_name)) {
|
514
|
+
cmark_llist_free(extensions);
|
515
|
+
rb_raise(rb_eTypeError, "extension names should be Symbols; got a %"PRIsVALUE"", rb_obj_class(rb_ext_name));
|
516
|
+
}
|
517
|
+
|
518
|
+
cmark_syntax_extension *syntax_extension =
|
519
|
+
cmark_find_syntax_extension(rb_id2name(SYM2ID(rb_ext_name)));
|
520
|
+
|
521
|
+
if (!syntax_extension) {
|
522
|
+
cmark_llist_free(extensions);
|
523
|
+
rb_raise(rb_eArgError, "extension %s not found\n", rb_id2name(SYM2ID(rb_ext_name)));
|
524
|
+
}
|
525
|
+
|
526
|
+
extensions = cmark_llist_append(extensions, syntax_extension);
|
527
|
+
}
|
528
|
+
|
529
|
+
char *html = cmark_render_html(node, options, extensions);
|
452
530
|
VALUE ruby_html = rb_str_new2(html);
|
453
531
|
|
532
|
+
cmark_llist_free(extensions);
|
454
533
|
free(html);
|
455
534
|
|
456
535
|
return ruby_html;
|
457
536
|
}
|
458
537
|
|
538
|
+
/* Internal: Convert the node to a CommonMark string.
|
539
|
+
*
|
540
|
+
* Returns a {String}.
|
541
|
+
*/
|
542
|
+
static VALUE rb_render_commonmark(VALUE n, VALUE rb_options) {
|
543
|
+
int options;
|
544
|
+
cmark_node *node;
|
545
|
+
Check_Type(rb_options, T_FIXNUM);
|
546
|
+
|
547
|
+
options = FIX2INT(rb_options);
|
548
|
+
Data_Get_Struct(n, cmark_node, node);
|
549
|
+
|
550
|
+
char *cmark = cmark_render_commonmark(node, options, 120);
|
551
|
+
VALUE ruby_cmark = rb_str_new2(cmark);
|
552
|
+
free(cmark);
|
553
|
+
|
554
|
+
return ruby_cmark;
|
555
|
+
}
|
556
|
+
|
459
557
|
/*
|
460
558
|
* Public: Inserts a node as a sibling after the current node.
|
461
559
|
*
|
@@ -907,6 +1005,21 @@ static VALUE rb_html_escape_html(VALUE self, VALUE rb_text) {
|
|
907
1005
|
return rb_text;
|
908
1006
|
}
|
909
1007
|
|
1008
|
+
VALUE rb_extensions(VALUE self) {
|
1009
|
+
cmark_llist *exts, *it;
|
1010
|
+
cmark_syntax_extension *ext;
|
1011
|
+
VALUE ary = rb_ary_new();
|
1012
|
+
|
1013
|
+
exts = cmark_list_syntax_extensions();
|
1014
|
+
for (it = exts; it; it = it->next) {
|
1015
|
+
ext = it->data;
|
1016
|
+
rb_ary_push(ary, rb_str_new2(ext->name));
|
1017
|
+
}
|
1018
|
+
cmark_llist_free(exts);
|
1019
|
+
|
1020
|
+
return ary;
|
1021
|
+
}
|
1022
|
+
|
910
1023
|
__attribute__((visibility("default"))) void Init_commonmarker() {
|
911
1024
|
VALUE module;
|
912
1025
|
sym_document = ID2SYM(rb_intern("document"));
|
@@ -932,12 +1045,13 @@ __attribute__((visibility("default"))) void Init_commonmarker() {
|
|
932
1045
|
sym_ordered_list = ID2SYM(rb_intern("ordered_list"));
|
933
1046
|
|
934
1047
|
module = rb_define_module("CommonMarker");
|
1048
|
+
rb_define_singleton_method(module, "extensions", rb_extensions, 0);
|
935
1049
|
rb_mNodeError = rb_define_class_under(module, "NodeError", rb_eStandardError);
|
936
1050
|
rb_mNode = rb_define_class_under(module, "Node", rb_cObject);
|
937
1051
|
rb_define_singleton_method(rb_mNode, "markdown_to_html", rb_markdown_to_html,
|
938
|
-
|
1052
|
+
3);
|
939
1053
|
rb_define_singleton_method(rb_mNode, "new", rb_node_new, 1);
|
940
|
-
rb_define_singleton_method(rb_mNode, "parse_document", rb_parse_document,
|
1054
|
+
rb_define_singleton_method(rb_mNode, "parse_document", rb_parse_document, 4);
|
941
1055
|
rb_define_method(rb_mNode, "string_content", rb_node_get_string_content, 0);
|
942
1056
|
rb_define_method(rb_mNode, "string_content=", rb_node_set_string_content, 1);
|
943
1057
|
rb_define_method(rb_mNode, "type", rb_node_get_type, 0);
|
@@ -947,7 +1061,8 @@ __attribute__((visibility("default"))) void Init_commonmarker() {
|
|
947
1061
|
rb_define_method(rb_mNode, "first_child", rb_node_first_child, 0);
|
948
1062
|
rb_define_method(rb_mNode, "next", rb_node_next, 0);
|
949
1063
|
rb_define_method(rb_mNode, "insert_before", rb_node_insert_before, 1);
|
950
|
-
rb_define_method(rb_mNode, "_render_html", rb_render_html,
|
1064
|
+
rb_define_method(rb_mNode, "_render_html", rb_render_html, 2);
|
1065
|
+
rb_define_method(rb_mNode, "_render_commonmark", rb_render_commonmark, 1);
|
951
1066
|
rb_define_method(rb_mNode, "insert_after", rb_node_insert_after, 1);
|
952
1067
|
rb_define_method(rb_mNode, "prepend_child", rb_node_prepend_child, 1);
|
953
1068
|
rb_define_method(rb_mNode, "append_child", rb_node_append_child, 1);
|
@@ -971,4 +1086,6 @@ __attribute__((visibility("default"))) void Init_commonmarker() {
|
|
971
1086
|
|
972
1087
|
rb_define_method(rb_mNode, "html_escape_href", rb_html_escape_href, 1);
|
973
1088
|
rb_define_method(rb_mNode, "html_escape_html", rb_html_escape_html, 1);
|
1089
|
+
|
1090
|
+
cmark_register_plugin(core_extensions_registration);
|
974
1091
|
}
|
data/ext/commonmarker/extconf.rb
CHANGED
@@ -23,23 +23,30 @@ end
|
|
23
23
|
FileUtils.mkdir_p(CMARK_BUILD_DIR)
|
24
24
|
|
25
25
|
Dir.chdir(CMARK_BUILD_DIR) do
|
26
|
-
|
27
|
-
|
26
|
+
if host_os == 'mingw32'
|
27
|
+
system 'cmake .. -G "MSYS Makefiles"'
|
28
|
+
else
|
29
|
+
system 'cmake .. -DCMAKE_C_FLAGS=-fPIC'
|
30
|
+
end
|
31
|
+
system "make libcmark_static" or abort "make libcmark_static failed"
|
32
|
+
system "make libcmarkextensions_static" or abort "make libcmarkextensions_static failed"
|
28
33
|
# rake-compiler seems to complain about this line, not sure why it's messing with it
|
29
34
|
FileUtils.rm_rf(File.join(CMARK_BUILD_DIR, 'Testing', 'Temporary'))
|
30
35
|
end
|
31
36
|
|
32
37
|
HEADER_DIRS = [INCLUDEDIR]
|
33
|
-
LIB_DIRS = [LIBDIR, "#{CMARK_BUILD_DIR}/src"]
|
38
|
+
LIB_DIRS = [LIBDIR, "#{CMARK_BUILD_DIR}/src", "#{CMARK_BUILD_DIR}/extensions"]
|
34
39
|
|
35
40
|
dir_config('cmark', HEADER_DIRS, LIB_DIRS)
|
36
41
|
|
37
42
|
# don't even bother to do this check if using OS X's messed up system Ruby: http://git.io/vsxkn
|
38
43
|
unless sitearch =~ /^universal-darwin/
|
39
44
|
abort 'libcmark is missing.' unless find_library('cmark', 'cmark_parse_document')
|
45
|
+
abort 'cmarkextensions is missing.' unless find_library('cmarkextensions', 'core_extensions_registration')
|
40
46
|
end
|
41
47
|
|
42
|
-
$LDFLAGS << " -L#{CMARK_BUILD_DIR}/src -lcmark"
|
43
|
-
$CFLAGS << " -O2 -I#{CMARK_DIR}/src -I#{CMARK_BUILD_DIR}/src"
|
48
|
+
$LDFLAGS << " -L#{CMARK_BUILD_DIR}/src -L#{CMARK_BUILD_DIR}/extensions -lcmark -lcmarkextensions"
|
49
|
+
$CFLAGS << " -O2 -I#{CMARK_DIR}/src -I#{CMARK_DIR}/extensions -I#{CMARK_BUILD_DIR}/src"
|
50
|
+
$CFLAGS << " -DCMARK_STATIC_DEFINE"
|
44
51
|
|
45
52
|
create_makefile('commonmarker/commonmarker')
|
data/lib/commonmarker.rb
CHANGED
@@ -15,13 +15,14 @@ module CommonMarker
|
|
15
15
|
#
|
16
16
|
# text - A {String} of text
|
17
17
|
# option - Either a {Symbol} or {Array of Symbol}s indicating the render options
|
18
|
+
# extensions - An {Array of Symbol}s indicating the extensions to use
|
18
19
|
#
|
19
20
|
# Returns a {String} of converted HTML.
|
20
|
-
def self.render_html(text, options = :default)
|
21
|
-
fail TypeError,
|
21
|
+
def self.render_html(text, options = :default, extensions = [])
|
22
|
+
fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
|
22
23
|
opts = Config.process_options(options, :render)
|
23
24
|
text = text.encode('UTF-8')
|
24
|
-
html = Node.markdown_to_html(text, opts)
|
25
|
+
html = Node.markdown_to_html(text, opts, extensions)
|
25
26
|
html.force_encoding('UTF-8')
|
26
27
|
end
|
27
28
|
|
@@ -29,12 +30,13 @@ module CommonMarker
|
|
29
30
|
#
|
30
31
|
# string - {String} to be parsed
|
31
32
|
# option - A {Symbol} or {Array of Symbol}s indicating the parse options
|
33
|
+
# extensions - An {Array of Symbol}s indicating the extensions to use
|
32
34
|
#
|
33
35
|
# Returns the `document` node.
|
34
|
-
def self.render_doc(text, options = :default)
|
35
|
-
fail TypeError,
|
36
|
+
def self.render_doc(text, options = :default, extensions = [])
|
37
|
+
fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String)
|
36
38
|
opts = Config.process_options(options, :parse)
|
37
39
|
text = text.encode('UTF-8')
|
38
|
-
Node.parse_document(text, text.bytesize, opts)
|
40
|
+
Node.parse_document(text, text.bytesize, opts, extensions)
|
39
41
|
end
|
40
42
|
end
|
data/lib/commonmarker/node.rb
CHANGED
@@ -17,11 +17,22 @@ module CommonMarker
|
|
17
17
|
# Public: Convert the node to an HTML string.
|
18
18
|
#
|
19
19
|
# options - A {Symbol} or {Array of Symbol}s indicating the render options
|
20
|
+
# extensions - An {Array of Symbol}s indicating the extensions to use
|
20
21
|
#
|
21
22
|
# Returns a {String}.
|
22
|
-
def to_html(options = :default)
|
23
|
+
def to_html(options = :default, extensions = [])
|
23
24
|
opts = Config.process_options(options, :render)
|
24
|
-
_render_html(opts).force_encoding('utf-8')
|
25
|
+
_render_html(opts, extensions).force_encoding('utf-8')
|
26
|
+
end
|
27
|
+
|
28
|
+
# Public: Convert the node to a CommonMark string.
|
29
|
+
#
|
30
|
+
# options - A {Symbol} or {Array of Symbol}s indicating the render options
|
31
|
+
#
|
32
|
+
# Returns a {String}.
|
33
|
+
def to_commonmark(options = :default)
|
34
|
+
opts = Config.process_options(options, :render)
|
35
|
+
_render_commonmark(opts).force_encoding('utf-8')
|
25
36
|
end
|
26
37
|
|
27
38
|
# Public: Iterate over the children (if any) of the current pointer.
|
data/lib/commonmarker/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestCommonmark < Minitest::Test
|
4
|
+
HTML_COMMENT = %r[<!--.*?-->\s?]
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@markdown = <<-MD
|
8
|
+
Hi *there*!
|
9
|
+
|
10
|
+
1. I am a numeric list.
|
11
|
+
2. I continue the list.
|
12
|
+
* Suddenly, an unordered list!
|
13
|
+
* What fun!
|
14
|
+
|
15
|
+
Okay, _enough_.
|
16
|
+
|
17
|
+
| a | b |
|
18
|
+
| --- | --- |
|
19
|
+
| c | d |
|
20
|
+
MD
|
21
|
+
end
|
22
|
+
|
23
|
+
def render_doc(doc)
|
24
|
+
CommonMarker.render_doc(doc, :default, %i[table])
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_to_commonmark
|
28
|
+
compare = render_doc(@markdown).to_commonmark
|
29
|
+
|
30
|
+
assert_equal \
|
31
|
+
render_doc(@markdown).to_html.gsub(HTML_COMMENT, ''),
|
32
|
+
render_doc(compare).to_html.gsub(HTML_COMMENT, '')
|
33
|
+
end
|
34
|
+
end
|
data/test/test_encoding.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class TestEncoding < Minitest::Test
|
4
5
|
# see http://git.io/vq4FR
|
5
6
|
def test_encoding
|
6
|
-
contents = File.read(File.join(FIXTURES_DIR, 'curly.md'))
|
7
|
+
contents = File.read(File.join(FIXTURES_DIR, 'curly.md'), encoding: 'utf-8')
|
7
8
|
doc = CommonMarker.render_doc(contents, :smart)
|
8
9
|
render = doc.to_html
|
9
10
|
assert_equal render.rstrip, '<p>This curly quote “makes commonmarker throw an exception”.</p>'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestExtensions < Minitest::Test
|
4
|
+
def setup
|
5
|
+
@markdown = <<-MD
|
6
|
+
One extension:
|
7
|
+
|
8
|
+
| a | b |
|
9
|
+
| --- | --- |
|
10
|
+
| c | d |
|
11
|
+
| **x** | |
|
12
|
+
|
13
|
+
Another extension:
|
14
|
+
|
15
|
+
~~hi~~
|
16
|
+
MD
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_uses_specified_extensions
|
20
|
+
CommonMarker.render_html(@markdown, :default, %i[]).tap do |out|
|
21
|
+
assert out.include?("| a")
|
22
|
+
assert out.include?("| <strong>x</strong>")
|
23
|
+
assert out.include?("~~hi~~")
|
24
|
+
end
|
25
|
+
|
26
|
+
CommonMarker.render_html(@markdown, :default, %i[table]).tap do |out|
|
27
|
+
refute out.include?("| a")
|
28
|
+
%w(<table> <tr> <th> a</th> <td> c</td> <strong>x</strong></td>).each {|html| assert out.include?(html) }
|
29
|
+
assert out.include?("~~hi~~")
|
30
|
+
end
|
31
|
+
|
32
|
+
CommonMarker.render_html(@markdown, :default, %i[strikethrough]).tap do |out|
|
33
|
+
assert out.include?("| a")
|
34
|
+
refute out.include?("~~hi~~")
|
35
|
+
assert out.include?("<del>hi</del>")
|
36
|
+
end
|
37
|
+
|
38
|
+
CommonMarker.render_html(@markdown, :default, %i[table strikethrough]).tap do |out|
|
39
|
+
refute out.include?("| a")
|
40
|
+
refute out.include?("| <strong>x</strong>")
|
41
|
+
refute out.include?("~~hi~~")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_bad_extension_specifications
|
46
|
+
assert_raises(TypeError) { CommonMarker.render_html(@markdown, :default, "nope") }
|
47
|
+
assert_raises(TypeError) { CommonMarker.render_html(@markdown, :default, ["table"]) }
|
48
|
+
assert_raises(ArgumentError) { CommonMarker.render_html(@markdown, :default, %i[table bad]) }
|
49
|
+
end
|
50
|
+
end
|