commonmarker 0.1.2 → 0.1.3
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/README.md +1 -8
- data/Rakefile +5 -0
- data/bin/commonmarker +0 -1
- data/commonmarker.gemspec +0 -1
- data/ext/commonmarker/cmark/README.md +1 -0
- data/ext/commonmarker/cmark/build/CMakeCache.txt +73 -139
- data/ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CMakeCCompiler.cmake +55 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CMakeCXXCompiler.cmake +56 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.2.2 → 2.8.10.1}/CMakeDetermineCompilerABI_C.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.2.2 → 2.8.10.1}/CMakeDetermineCompilerABI_CXX.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.2.2 → 2.8.10.1}/CMakeSystem.cmake +6 -6
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.2.2 → 2.8.10.1}/CompilerIdC/CMakeCCompilerId.c +50 -156
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.2.2 → 2.8.10.1}/CompilerIdC/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.2.2 → 2.8.10.1}/CompilerIdCXX/CMakeCXXCompilerId.cpp +38 -152
- data/ext/commonmarker/cmark/build/CMakeFiles/{3.2.2 → 2.8.10.1}/CompilerIdCXX/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +14 -14
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +129 -444
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +38 -111
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile2 +6 -3
- data/ext/commonmarker/cmark/build/CMakeFiles/TargetDirectories.txt +2 -2
- data/ext/commonmarker/cmark/build/CTestTestfile.cmake +5 -5
- data/ext/commonmarker/cmark/build/Makefile +44 -44
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/DependInfo.cmake +10 -10
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +15 -12
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/cmake_clean.cmake +4 -4
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/depend.make +2 -25
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/flags.make +3 -3
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/api_test/Makefile +44 -44
- data/ext/commonmarker/cmark/build/api_test/cmake_install.cmake +20 -20
- data/ext/commonmarker/cmark/build/cmake_install.cmake +35 -35
- data/ext/commonmarker/cmark/build/man/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
- data/ext/commonmarker/cmark/build/man/Makefile +43 -43
- data/ext/commonmarker/cmark/build/man/cmake_install.cmake +26 -26
- data/ext/commonmarker/cmark/build/src/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/DependInfo.cmake +8 -8
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/build.make +60 -57
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmake_clean.cmake +4 -4
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/depend.make +2 -177
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/flags.make +5 -3
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +9 -9
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +57 -55
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +4 -4
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/depend.make +2 -169
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/flags.make +2 -2
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/DependInfo.cmake +8 -8
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/build.make +57 -54
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean.cmake +4 -4
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/cmake_clean_target.cmake +1 -1
- 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 +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/depend.make +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/flags.make +5 -3
- 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/link.txt +2 -2
- 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/references.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/Makefile +45 -45
- data/ext/commonmarker/cmark/build/src/cmake_install.cmake +47 -44
- data/ext/commonmarker/cmark/build/src/cmark_export.h +2 -8
- data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
- data/ext/commonmarker/cmark/build/testdir/CMakeFiles/CMakeDirectoryInformation.cmake +8 -8
- data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +7 -7
- data/ext/commonmarker/cmark/build/testdir/Makefile +43 -43
- data/ext/commonmarker/cmark/build/testdir/cmake_install.cmake +20 -20
- data/ext/commonmarker/cmark/src/chunk.h +13 -4
- data/ext/commonmarker/cmark/src/html.c +10 -8
- data/ext/commonmarker/cmark/src/inlines.c +38 -29
- data/ext/commonmarker/cmark/src/inlines.h +2 -2
- data/ext/commonmarker/cmark/src/node.c +6 -21
- data/ext/commonmarker/cmark/src/node.h +2 -2
- data/ext/commonmarker/cmark/src/references.c +2 -2
- data/ext/commonmarker/cmark/src/references.h +2 -2
- data/ext/commonmarker/cmark/src/xml.c +4 -2
- data/ext/commonmarker/commonmarker.c +48 -7
- data/ext/commonmarker/commonmarker.c.orig +444 -0
- data/ext/commonmarker/extconf.rb +16 -4
- data/lib/commonmarker.rb +7 -24
- data/lib/commonmarker/renderer/html_renderer.rb +6 -9
- data/lib/commonmarker/version.rb +1 -1
- data/test/spec_tests.json +2192 -2192
- data/test/test_basics.rb +0 -4
- data/test/test_helper.rb +0 -1
- data/test/test_maliciousness.rb +4 -0
- data/test/test_spec.rb +3 -2
- metadata +12 -78
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeCCompiler.cmake +0 -63
- data/ext/commonmarker/cmark/build/CMakeFiles/3.2.2/CMakeCXXCompiler.cmake +0 -64
- data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.c +0 -34
- data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.cxx +0 -405
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/C.includecache +0 -92
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/CXX.includecache +0 -36
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/cplusplus.cpp.o +0 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/depend.internal +0 -25
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/harness.c.o +0 -0
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/main.c.o +0 -0
- data/ext/commonmarker/cmark/build/api_test/api_test +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/C.includecache +0 -422
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/buffer.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/cmark_ctype.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/depend.internal +0 -177
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_href_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_html_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/houdini_html_u.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/iterator.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/main.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/man.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/references.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/utf8.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/C.includecache +0 -394
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/buffer.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmark_ctype.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/depend.internal +0 -169
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_href_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_html_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/houdini_html_u.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/iterator.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/man.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/references.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/utf8.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/cmark +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark.0.19.0.dylib +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark.dylib +0 -0
- data/ext/commonmarker/commonmarker.bundle +0 -0
@@ -1,29 +1,29 @@
|
|
1
1
|
# Install script for directory: /Users/gjtorikian/Development/commonmarker/ext/commonmarker/cmark/test
|
2
2
|
|
3
3
|
# Set the install prefix
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
IF(NOT DEFINED CMAKE_INSTALL_PREFIX)
|
5
|
+
SET(CMAKE_INSTALL_PREFIX "/usr/local")
|
6
|
+
ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX)
|
7
|
+
STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
|
8
8
|
|
9
9
|
# Set the install configuration name.
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
11
|
+
IF(BUILD_TYPE)
|
12
|
+
STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
|
13
13
|
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
ELSE(BUILD_TYPE)
|
15
|
+
SET(CMAKE_INSTALL_CONFIG_NAME "Release")
|
16
|
+
ENDIF(BUILD_TYPE)
|
17
|
+
MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
|
18
|
+
ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
19
19
|
|
20
20
|
# Set the component getting installed.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
IF(NOT CMAKE_INSTALL_COMPONENT)
|
22
|
+
IF(COMPONENT)
|
23
|
+
MESSAGE(STATUS "Install component: \"${COMPONENT}\"")
|
24
|
+
SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
|
25
|
+
ELSE(COMPONENT)
|
26
|
+
SET(CMAKE_INSTALL_COMPONENT)
|
27
|
+
ENDIF(COMPONENT)
|
28
|
+
ENDIF(NOT CMAKE_INSTALL_COMPONENT)
|
29
29
|
|
@@ -7,6 +7,8 @@
|
|
7
7
|
#include "cmark_ctype.h"
|
8
8
|
#include "buffer.h"
|
9
9
|
|
10
|
+
#define CMARK_CHUNK_EMPTY { NULL, 0, 0 }
|
11
|
+
|
10
12
|
typedef struct {
|
11
13
|
unsigned char *data;
|
12
14
|
int len;
|
@@ -78,10 +80,17 @@ static inline void cmark_chunk_set_cstr(cmark_chunk *c, const char *str)
|
|
78
80
|
if (c->alloc) {
|
79
81
|
free(c->data);
|
80
82
|
}
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
if (str == NULL) {
|
84
|
+
c->len = 0;
|
85
|
+
c->data = NULL;
|
86
|
+
c->alloc = 0;
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
c->len = strlen(str);
|
90
|
+
c->data = (unsigned char *)malloc(c->len + 1);
|
91
|
+
c->alloc = 1;
|
92
|
+
memcpy(c->data, str, c->len + 1);
|
93
|
+
}
|
85
94
|
}
|
86
95
|
|
87
96
|
static inline cmark_chunk cmark_chunk_literal(const char *data)
|
@@ -261,12 +261,13 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
|
|
261
261
|
case CMARK_NODE_LINK:
|
262
262
|
if (entering) {
|
263
263
|
cmark_strbuf_puts(html, "<a href=\"");
|
264
|
-
|
265
|
-
|
264
|
+
escape_href(html, node->as.link.url.data,
|
265
|
+
node->as.link.url.len);
|
266
266
|
|
267
|
-
if (node->as.link.title) {
|
267
|
+
if (node->as.link.title.len) {
|
268
268
|
cmark_strbuf_puts(html, "\" title=\"");
|
269
|
-
escape_html(html, node->as.link.title,
|
269
|
+
escape_html(html, node->as.link.title.data,
|
270
|
+
node->as.link.title.len);
|
270
271
|
}
|
271
272
|
|
272
273
|
cmark_strbuf_puts(html, "\">");
|
@@ -278,15 +279,16 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
|
|
278
279
|
case CMARK_NODE_IMAGE:
|
279
280
|
if (entering) {
|
280
281
|
cmark_strbuf_puts(html, "<img src=\"");
|
281
|
-
|
282
|
-
|
282
|
+
escape_href(html, node->as.link.url.data,
|
283
|
+
node->as.link.url.len);
|
283
284
|
|
284
285
|
cmark_strbuf_puts(html, "\" alt=\"");
|
285
286
|
state->plain = node;
|
286
287
|
} else {
|
287
|
-
if (node->as.link.title) {
|
288
|
+
if (node->as.link.title.len) {
|
288
289
|
cmark_strbuf_puts(html, "\" title=\"");
|
289
|
-
escape_html(html, node->as.link.title,
|
290
|
+
escape_html(html, node->as.link.title.data,
|
291
|
+
node->as.link.title.len);
|
290
292
|
}
|
291
293
|
|
292
294
|
cmark_strbuf_puts(html, "\" />");
|
@@ -59,31 +59,33 @@ static void subject_from_buf(subject *e, cmark_strbuf *buffer,
|
|
59
59
|
cmark_reference_map *refmap);
|
60
60
|
static int subject_find_special_char(subject *subj, int options);
|
61
61
|
|
62
|
-
static
|
62
|
+
static cmark_chunk cmark_clean_autolink(cmark_chunk *url, int is_email)
|
63
63
|
{
|
64
64
|
cmark_strbuf buf = GH_BUF_INIT;
|
65
65
|
|
66
66
|
cmark_chunk_trim(url);
|
67
67
|
|
68
|
-
if (url->len == 0)
|
69
|
-
|
68
|
+
if (url->len == 0) {
|
69
|
+
cmark_chunk result = CMARK_CHUNK_EMPTY;
|
70
|
+
return result;
|
71
|
+
}
|
70
72
|
|
71
73
|
if (is_email)
|
72
74
|
cmark_strbuf_puts(&buf, "mailto:");
|
73
75
|
|
74
76
|
houdini_unescape_html_f(&buf, url->data, url->len);
|
75
|
-
return
|
77
|
+
return cmark_chunk_buf_detach(&buf);
|
76
78
|
}
|
77
79
|
|
78
|
-
static inline cmark_node *make_link(cmark_node *label,
|
80
|
+
static inline cmark_node *make_link(cmark_node *label, cmark_chunk *url, cmark_chunk *title)
|
79
81
|
{
|
80
82
|
cmark_node* e = (cmark_node *)calloc(1, sizeof(*e));
|
81
83
|
if(e != NULL) {
|
82
84
|
e->type = CMARK_NODE_LINK;
|
83
85
|
e->first_child = label;
|
84
86
|
e->last_child = label;
|
85
|
-
e->as.link.url = url;
|
86
|
-
e->as.link.title = title;
|
87
|
+
e->as.link.url = *url;
|
88
|
+
e->as.link.title = *title;
|
87
89
|
e->next = NULL;
|
88
90
|
label->parent = e;
|
89
91
|
}
|
@@ -92,7 +94,9 @@ static inline cmark_node *make_link(cmark_node *label, unsigned char *url, unsig
|
|
92
94
|
|
93
95
|
static inline cmark_node* make_autolink(cmark_node* label, cmark_chunk url, int is_email)
|
94
96
|
{
|
95
|
-
|
97
|
+
cmark_chunk clean_url = cmark_clean_autolink(&url, is_email);
|
98
|
+
cmark_chunk title = CMARK_CHUNK_EMPTY;
|
99
|
+
return make_link(label, &clean_url, &title);
|
96
100
|
}
|
97
101
|
|
98
102
|
// Create an inline with a literal string value.
|
@@ -134,19 +138,20 @@ static inline cmark_node* make_simple(cmark_node_type t)
|
|
134
138
|
return e;
|
135
139
|
}
|
136
140
|
|
137
|
-
|
141
|
+
// Duplicate a chunk by creating a copy of the buffer not by reusing the
|
142
|
+
// buffer like cmark_chunk_dup does.
|
143
|
+
static cmark_chunk chunk_clone(cmark_chunk *src)
|
138
144
|
{
|
139
|
-
|
145
|
+
cmark_chunk c;
|
146
|
+
int len = src->len;
|
140
147
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
}
|
147
|
-
}
|
148
|
+
c.len = len;
|
149
|
+
c.data = (unsigned char *)malloc(len + 1);
|
150
|
+
c.alloc = 1;
|
151
|
+
memcpy(c.data, src->data, len);
|
152
|
+
c.data[len] = '\0';
|
148
153
|
|
149
|
-
|
154
|
+
return c;
|
150
155
|
}
|
151
156
|
|
152
157
|
static void subject_from_buf(subject *e, cmark_strbuf *buffer,
|
@@ -622,14 +627,16 @@ static cmark_node *make_str_with_entities(cmark_chunk *content)
|
|
622
627
|
|
623
628
|
// Clean a URL: remove surrounding whitespace and surrounding <>,
|
624
629
|
// and remove \ that escape punctuation.
|
625
|
-
|
630
|
+
cmark_chunk cmark_clean_url(cmark_chunk *url)
|
626
631
|
{
|
627
632
|
cmark_strbuf buf = GH_BUF_INIT;
|
628
633
|
|
629
634
|
cmark_chunk_trim(url);
|
630
635
|
|
631
|
-
if (url->len == 0)
|
632
|
-
|
636
|
+
if (url->len == 0) {
|
637
|
+
cmark_chunk result = CMARK_CHUNK_EMPTY;
|
638
|
+
return result;
|
639
|
+
}
|
633
640
|
|
634
641
|
if (url->data[0] == '<' && url->data[url->len - 1] == '>') {
|
635
642
|
houdini_unescape_html_f(&buf, url->data + 1, url->len - 2);
|
@@ -638,16 +645,18 @@ unsigned char *cmark_clean_url(cmark_chunk *url)
|
|
638
645
|
}
|
639
646
|
|
640
647
|
cmark_strbuf_unescape(&buf);
|
641
|
-
return
|
648
|
+
return cmark_chunk_buf_detach(&buf);
|
642
649
|
}
|
643
650
|
|
644
|
-
|
651
|
+
cmark_chunk cmark_clean_title(cmark_chunk *title)
|
645
652
|
{
|
646
653
|
cmark_strbuf buf = GH_BUF_INIT;
|
647
654
|
unsigned char first, last;
|
648
655
|
|
649
|
-
if (title->len == 0)
|
650
|
-
|
656
|
+
if (title->len == 0) {
|
657
|
+
cmark_chunk result = CMARK_CHUNK_EMPTY;
|
658
|
+
return result;
|
659
|
+
}
|
651
660
|
|
652
661
|
first = title->data[0];
|
653
662
|
last = title->data[title->len - 1];
|
@@ -662,7 +671,7 @@ unsigned char *cmark_clean_title(cmark_chunk *title)
|
|
662
671
|
}
|
663
672
|
|
664
673
|
cmark_strbuf_unescape(&buf);
|
665
|
-
return
|
674
|
+
return cmark_chunk_buf_detach(&buf);
|
666
675
|
}
|
667
676
|
|
668
677
|
// Parse an autolink or HTML tag.
|
@@ -766,7 +775,7 @@ static cmark_node* handle_close_bracket(subject* subj, cmark_node *parent)
|
|
766
775
|
cmark_reference *ref;
|
767
776
|
bool is_image = false;
|
768
777
|
cmark_chunk url_chunk, title_chunk;
|
769
|
-
|
778
|
+
cmark_chunk url, title;
|
770
779
|
delimiter *opener;
|
771
780
|
cmark_node *link_text;
|
772
781
|
cmark_node *inl;
|
@@ -854,8 +863,8 @@ static cmark_node* handle_close_bracket(subject* subj, cmark_node *parent)
|
|
854
863
|
cmark_chunk_free(&raw_label);
|
855
864
|
|
856
865
|
if (ref != NULL) { // found
|
857
|
-
url
|
858
|
-
title =
|
866
|
+
url = chunk_clone(&ref->url);
|
867
|
+
title = chunk_clone(&ref->title);
|
859
868
|
goto match;
|
860
869
|
} else {
|
861
870
|
goto noMatch;
|
@@ -5,8 +5,8 @@
|
|
5
5
|
extern "C" {
|
6
6
|
#endif
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
cmark_chunk cmark_clean_url(cmark_chunk *url);
|
9
|
+
cmark_chunk cmark_clean_title(cmark_chunk *title);
|
10
10
|
|
11
11
|
void cmark_parse_inlines(cmark_node* parent, cmark_reference_map *refmap, int options);
|
12
12
|
|
@@ -122,12 +122,8 @@ void S_free_nodes(cmark_node *e)
|
|
122
122
|
break;
|
123
123
|
case NODE_LINK:
|
124
124
|
case NODE_IMAGE:
|
125
|
-
|
126
|
-
|
127
|
-
}
|
128
|
-
if (e->as.link.title) {
|
129
|
-
free(e->as.link.title);
|
130
|
-
}
|
125
|
+
cmark_chunk_free(&e->as.link.url);
|
126
|
+
cmark_chunk_free(&e->as.link.title);
|
131
127
|
break;
|
132
128
|
default:
|
133
129
|
break;
|
@@ -282,15 +278,6 @@ cmark_node_set_user_data(cmark_node *node, void *user_data)
|
|
282
278
|
return 1;
|
283
279
|
}
|
284
280
|
|
285
|
-
static char*
|
286
|
-
S_strdup(const char *str)
|
287
|
-
{
|
288
|
-
size_t size = strlen(str) + 1;
|
289
|
-
char *dup = (char *)malloc(size);
|
290
|
-
memcpy(dup, str, size);
|
291
|
-
return dup;
|
292
|
-
}
|
293
|
-
|
294
281
|
const char*
|
295
282
|
cmark_node_get_literal(cmark_node *node)
|
296
283
|
{
|
@@ -541,7 +528,7 @@ cmark_node_get_url(cmark_node *node)
|
|
541
528
|
switch (node->type) {
|
542
529
|
case NODE_LINK:
|
543
530
|
case NODE_IMAGE:
|
544
|
-
return (
|
531
|
+
return cmark_chunk_to_cstr(&node->as.link.url);
|
545
532
|
default:
|
546
533
|
break;
|
547
534
|
}
|
@@ -559,8 +546,7 @@ cmark_node_set_url(cmark_node *node, const char *url)
|
|
559
546
|
switch (node->type) {
|
560
547
|
case NODE_LINK:
|
561
548
|
case NODE_IMAGE:
|
562
|
-
|
563
|
-
node->as.link.url = (unsigned char *)S_strdup(url);
|
549
|
+
cmark_chunk_set_cstr(&node->as.link.url, url);
|
564
550
|
return 1;
|
565
551
|
default:
|
566
552
|
break;
|
@@ -579,7 +565,7 @@ cmark_node_get_title(cmark_node *node)
|
|
579
565
|
switch (node->type) {
|
580
566
|
case NODE_LINK:
|
581
567
|
case NODE_IMAGE:
|
582
|
-
return (
|
568
|
+
return cmark_chunk_to_cstr(&node->as.link.title);
|
583
569
|
default:
|
584
570
|
break;
|
585
571
|
}
|
@@ -597,8 +583,7 @@ cmark_node_set_title(cmark_node *node, const char *title)
|
|
597
583
|
switch (node->type) {
|
598
584
|
case NODE_LINK:
|
599
585
|
case NODE_IMAGE:
|
600
|
-
|
601
|
-
node->as.link.title = (unsigned char *)S_strdup(title);
|
586
|
+
cmark_chunk_set_cstr(&node->as.link.title, title);
|
602
587
|
return 1;
|
603
588
|
default:
|
604
589
|
break;
|
@@ -118,10 +118,12 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
|
|
118
118
|
case CMARK_NODE_LINK:
|
119
119
|
case CMARK_NODE_IMAGE:
|
120
120
|
cmark_strbuf_puts(xml, " destination=\"");
|
121
|
-
escape_xml(xml, node->as.link.url,
|
121
|
+
escape_xml(xml, node->as.link.url.data,
|
122
|
+
node->as.link.url.len);
|
122
123
|
cmark_strbuf_putc(xml, '"');
|
123
124
|
cmark_strbuf_puts(xml, " title=\"");
|
124
|
-
escape_xml(xml, node->as.link.title,
|
125
|
+
escape_xml(xml, node->as.link.title.data,
|
126
|
+
node->as.link.title.len);
|
125
127
|
cmark_strbuf_putc(xml, '"');
|
126
128
|
break;
|
127
129
|
default:
|
@@ -1,9 +1,17 @@
|
|
1
1
|
#include "commonmarker.h"
|
2
2
|
#include "cmark.h"
|
3
3
|
#include "node.h"
|
4
|
+
#include "houdini.h"
|
4
5
|
|
5
6
|
VALUE rb_mCommonMark;
|
6
7
|
|
8
|
+
void rb_free_c_struct(void* n)
|
9
|
+
{
|
10
|
+
if (n != NULL && cmark_node_get_type(n) == CMARK_NODE_DOCUMENT) {
|
11
|
+
cmark_node_free(n);
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
7
15
|
static VALUE
|
8
16
|
rb_markdown_to_html(VALUE self, VALUE rb_text)
|
9
17
|
{
|
@@ -37,7 +45,7 @@ rb_parse_document(VALUE self, VALUE rb_text, VALUE rb_len, VALUE rb_options)
|
|
37
45
|
|
38
46
|
cmark_node *doc = cmark_parse_document(text, len, options);
|
39
47
|
|
40
|
-
return Data_Wrap_Struct(self, NULL,
|
48
|
+
return Data_Wrap_Struct(self, NULL, rb_free_c_struct, doc);
|
41
49
|
}
|
42
50
|
|
43
51
|
static VALUE
|
@@ -98,7 +106,7 @@ rb_node_free(VALUE self, VALUE n)
|
|
98
106
|
cmark_node *node;
|
99
107
|
Data_Get_Struct(n, cmark_node, node);
|
100
108
|
|
101
|
-
|
109
|
+
rb_free_c_struct(node);
|
102
110
|
}
|
103
111
|
|
104
112
|
static VALUE
|
@@ -112,7 +120,7 @@ rb_node_first_child(VALUE self, VALUE n)
|
|
112
120
|
|
113
121
|
cmark_node *child = cmark_node_first_child(node);
|
114
122
|
|
115
|
-
return Data_Wrap_Struct(self, NULL,
|
123
|
+
return Data_Wrap_Struct(self, NULL, rb_free_c_struct, child);
|
116
124
|
}
|
117
125
|
|
118
126
|
static VALUE
|
@@ -126,7 +134,7 @@ rb_node_next(VALUE self, VALUE n)
|
|
126
134
|
|
127
135
|
cmark_node *next = cmark_node_next(node);
|
128
136
|
|
129
|
-
return Data_Wrap_Struct(self, NULL,
|
137
|
+
return Data_Wrap_Struct(self, NULL, rb_free_c_struct, next);
|
130
138
|
}
|
131
139
|
|
132
140
|
static VALUE
|
@@ -204,7 +212,7 @@ rb_node_last_child(VALUE self, VALUE n)
|
|
204
212
|
|
205
213
|
cmark_node *child = cmark_node_last_child(node);
|
206
214
|
|
207
|
-
return Data_Wrap_Struct(self, NULL,
|
215
|
+
return Data_Wrap_Struct(self, NULL, rb_free_c_struct, child);
|
208
216
|
}
|
209
217
|
|
210
218
|
|
@@ -219,7 +227,7 @@ rb_node_parent(VALUE self, VALUE n)
|
|
219
227
|
|
220
228
|
cmark_node *parent = cmark_node_parent(node);
|
221
229
|
|
222
|
-
return Data_Wrap_Struct(self, NULL,
|
230
|
+
return Data_Wrap_Struct(self, NULL, rb_free_c_struct, parent);
|
223
231
|
}
|
224
232
|
|
225
233
|
|
@@ -234,7 +242,7 @@ rb_node_previous(VALUE self, VALUE n)
|
|
234
242
|
|
235
243
|
cmark_node *previous = cmark_node_previous(node);
|
236
244
|
|
237
|
-
return Data_Wrap_Struct(self, NULL,
|
245
|
+
return Data_Wrap_Struct(self, NULL, rb_free_c_struct, previous);
|
238
246
|
}
|
239
247
|
|
240
248
|
|
@@ -398,6 +406,36 @@ rb_node_set_fence_info(VALUE self, VALUE n, VALUE s)
|
|
398
406
|
return INT2NUM(cmark_node_set_fence_info(node, text));
|
399
407
|
}
|
400
408
|
|
409
|
+
static VALUE
|
410
|
+
rb_html_escape_href(VALUE self, VALUE rb_text)
|
411
|
+
{
|
412
|
+
Check_Type(rb_text, T_STRING);
|
413
|
+
|
414
|
+
cmark_strbuf buf = GH_BUF_INIT;
|
415
|
+
char *text = (char *)RSTRING_PTR(rb_text);
|
416
|
+
int len = RSTRING_LEN(rb_text);
|
417
|
+
|
418
|
+
houdini_escape_href(&buf, text, len);
|
419
|
+
char *result =(char *)cmark_strbuf_detach(&buf);
|
420
|
+
|
421
|
+
return rb_str_new2(result);
|
422
|
+
}
|
423
|
+
|
424
|
+
static VALUE
|
425
|
+
rb_html_escape_html(VALUE self, VALUE rb_text)
|
426
|
+
{
|
427
|
+
Check_Type(rb_text, T_STRING);
|
428
|
+
|
429
|
+
cmark_strbuf buf = GH_BUF_INIT;
|
430
|
+
char *text = (char *)RSTRING_PTR(rb_text);
|
431
|
+
int len = RSTRING_LEN(rb_text);
|
432
|
+
|
433
|
+
houdini_escape_html0(&buf, text, len, 0);
|
434
|
+
char *result =(char *)cmark_strbuf_detach(&buf);
|
435
|
+
|
436
|
+
return rb_str_new2(result);
|
437
|
+
}
|
438
|
+
|
401
439
|
__attribute__((visibility("default")))
|
402
440
|
void Init_commonmarker()
|
403
441
|
{
|
@@ -435,4 +473,7 @@ void Init_commonmarker()
|
|
435
473
|
rb_define_singleton_method(rb_mCommonMark, "node_set_list_tight", rb_node_set_list_tight, 2);
|
436
474
|
rb_define_singleton_method(rb_mCommonMark, "node_get_fence_info", rb_node_get_fence_info, 1);
|
437
475
|
rb_define_singleton_method(rb_mCommonMark, "node_set_fence_info", rb_node_set_fence_info, 2);
|
476
|
+
|
477
|
+
rb_define_singleton_method(rb_mCommonMark, "html_escape_href", rb_html_escape_href, 1);
|
478
|
+
rb_define_singleton_method(rb_mCommonMark, "html_escape_html", rb_html_escape_html, 1);
|
438
479
|
}
|