commonmarker 0.3.0 → 0.4.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/ext/commonmarker/cmark/CMakeLists.txt +10 -4
- data/ext/commonmarker/cmark/Makefile +5 -5
- data/ext/commonmarker/cmark/api_test/CMakeLists.txt +1 -1
- data/ext/commonmarker/cmark/api_test/main.c +16 -0
- data/ext/commonmarker/cmark/build/CMakeCache.txt +3 -4
- data/ext/commonmarker/cmark/build/CMakeFiles/2.8.10.1/CMakeSystem.cmake +4 -4
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +12 -12
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +97 -142
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +0 -1
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +1 -1
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/DependInfo.cmake +1 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/build.make +23 -23
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark.dir/cmake_clean.cmake +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/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark_static.dir/buffer.c.o +0 -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/houdini_html_u.c.o +0 -0
- 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/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/render.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/utf8.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/cmake_install.cmake +3 -3
- data/ext/commonmarker/cmark/build/src/cmark_version.h +2 -2
- data/ext/commonmarker/cmark/build/src/config.h +6 -6
- data/ext/commonmarker/cmark/build/src/libcmark.a +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark.pc +1 -1
- data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +4 -4
- data/ext/commonmarker/cmark/changelog.txt +46 -0
- data/ext/commonmarker/cmark/man/man3/cmark.3 +21 -20
- data/ext/commonmarker/cmark/src/CMakeLists.txt +4 -6
- data/ext/commonmarker/cmark/src/bench.h +8 -8
- data/ext/commonmarker/cmark/src/blocks.c +917 -947
- data/ext/commonmarker/cmark/src/buffer.c +213 -288
- data/ext/commonmarker/cmark/src/buffer.h +19 -21
- data/ext/commonmarker/cmark/src/chunk.h +78 -82
- data/ext/commonmarker/cmark/src/cmark.c +9 -17
- data/ext/commonmarker/cmark/src/cmark.h +113 -157
- data/ext/commonmarker/cmark/src/cmark_ctype.c +24 -35
- data/ext/commonmarker/cmark/src/commonmark.c +390 -425
- data/ext/commonmarker/cmark/src/config.h.in +6 -6
- data/ext/commonmarker/cmark/src/houdini.h +21 -15
- data/ext/commonmarker/cmark/src/houdini_href_e.c +50 -57
- data/ext/commonmarker/cmark/src/houdini_html_e.c +36 -51
- data/ext/commonmarker/cmark/src/houdini_html_u.c +119 -124
- data/ext/commonmarker/cmark/src/html.c +289 -307
- data/ext/commonmarker/cmark/src/inlines.c +976 -1030
- data/ext/commonmarker/cmark/src/inlines.h +4 -2
- data/ext/commonmarker/cmark/src/iterator.c +96 -126
- data/ext/commonmarker/cmark/src/iterator.h +5 -5
- data/ext/commonmarker/cmark/src/latex.c +379 -401
- data/ext/commonmarker/cmark/src/main.c +168 -175
- data/ext/commonmarker/cmark/src/man.c +212 -226
- data/ext/commonmarker/cmark/src/node.c +746 -839
- data/ext/commonmarker/cmark/src/node.h +47 -48
- data/ext/commonmarker/cmark/src/parser.h +14 -14
- data/ext/commonmarker/cmark/src/references.c +101 -111
- data/ext/commonmarker/cmark/src/references.h +10 -8
- data/ext/commonmarker/cmark/src/render.c +144 -167
- data/ext/commonmarker/cmark/src/render.h +22 -41
- data/ext/commonmarker/cmark/src/scanners.c +27695 -20903
- data/ext/commonmarker/cmark/src/scanners.h +2 -1
- data/ext/commonmarker/cmark/src/scanners.re +1 -1
- data/ext/commonmarker/cmark/src/utf8.c +276 -419
- data/ext/commonmarker/cmark/src/utf8.h +6 -6
- data/ext/commonmarker/cmark/src/xml.c +129 -144
- data/ext/commonmarker/cmark/test/CMakeLists.txt +4 -4
- data/ext/commonmarker/cmark/test/smart_punct.txt +8 -0
- data/ext/commonmarker/cmark/test/spec.txt +109 -47
- data/lib/commonmarker/version.rb +1 -1
- metadata +2 -2
@@ -5,182 +5,159 @@
|
|
5
5
|
#include "utf8.h"
|
6
6
|
#include "render.h"
|
7
7
|
|
8
|
-
static inline
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
renderer->need_cr = 1;
|
13
|
-
}
|
8
|
+
static inline void S_cr(cmark_renderer *renderer) {
|
9
|
+
if (renderer->need_cr < 1) {
|
10
|
+
renderer->need_cr = 1;
|
11
|
+
}
|
14
12
|
}
|
15
13
|
|
16
|
-
static inline
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
renderer->need_cr = 2;
|
21
|
-
}
|
14
|
+
static inline void S_blankline(cmark_renderer *renderer) {
|
15
|
+
if (renderer->need_cr < 2) {
|
16
|
+
renderer->need_cr = 2;
|
17
|
+
}
|
22
18
|
}
|
23
19
|
|
24
|
-
static
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
renderer->last_breakable = 0;
|
116
|
-
renderer->begin_line = false;
|
117
|
-
}
|
118
|
-
|
119
|
-
i += len;
|
120
|
-
}
|
20
|
+
static void S_out(cmark_renderer *renderer, const char *source, bool wrap,
|
21
|
+
cmark_escaping escape) {
|
22
|
+
int length = cmark_strbuf_safe_strlen(source);
|
23
|
+
unsigned char nextc;
|
24
|
+
int32_t c;
|
25
|
+
int i = 0;
|
26
|
+
int len;
|
27
|
+
cmark_chunk remainder = cmark_chunk_literal("");
|
28
|
+
int k = renderer->buffer->size - 1;
|
29
|
+
|
30
|
+
wrap = wrap && !renderer->no_wrap;
|
31
|
+
|
32
|
+
if (renderer->in_tight_list_item && renderer->need_cr > 1) {
|
33
|
+
renderer->need_cr = 1;
|
34
|
+
}
|
35
|
+
while (renderer->need_cr) {
|
36
|
+
if (k < 0 || renderer->buffer->ptr[k] == '\n') {
|
37
|
+
k -= 1;
|
38
|
+
} else {
|
39
|
+
cmark_strbuf_putc(renderer->buffer, '\n');
|
40
|
+
if (renderer->need_cr > 1) {
|
41
|
+
cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
|
42
|
+
renderer->prefix->size);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
renderer->column = 0;
|
46
|
+
renderer->begin_line = true;
|
47
|
+
renderer->need_cr -= 1;
|
48
|
+
}
|
49
|
+
|
50
|
+
while (i < length) {
|
51
|
+
if (renderer->begin_line) {
|
52
|
+
cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
|
53
|
+
renderer->prefix->size);
|
54
|
+
// note: this assumes prefix is ascii:
|
55
|
+
renderer->column = renderer->prefix->size;
|
56
|
+
}
|
57
|
+
|
58
|
+
len = cmark_utf8proc_iterate((const uint8_t *)source + i, length - i, &c);
|
59
|
+
if (len == -1) { // error condition
|
60
|
+
return; // return without rendering rest of string
|
61
|
+
}
|
62
|
+
nextc = source[i + len];
|
63
|
+
if (c == 32 && wrap) {
|
64
|
+
if (!renderer->begin_line) {
|
65
|
+
cmark_strbuf_putc(renderer->buffer, ' ');
|
66
|
+
renderer->column += 1;
|
67
|
+
renderer->begin_line = false;
|
68
|
+
renderer->last_breakable = renderer->buffer->size - 1;
|
69
|
+
// skip following spaces
|
70
|
+
while (source[i + 1] == ' ') {
|
71
|
+
i++;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
} else if (c == 10) {
|
76
|
+
cmark_strbuf_putc(renderer->buffer, '\n');
|
77
|
+
renderer->column = 0;
|
78
|
+
renderer->begin_line = true;
|
79
|
+
renderer->last_breakable = 0;
|
80
|
+
} else if (escape == LITERAL) {
|
81
|
+
cmark_render_code_point(renderer, c);
|
82
|
+
renderer->begin_line = false;
|
83
|
+
} else {
|
84
|
+
(renderer->outc)(renderer, escape, c, nextc);
|
85
|
+
renderer->begin_line = false;
|
86
|
+
}
|
87
|
+
|
88
|
+
// If adding the character went beyond width, look for an
|
89
|
+
// earlier place where the line could be broken:
|
90
|
+
if (renderer->width > 0 && renderer->column > renderer->width &&
|
91
|
+
!renderer->begin_line && renderer->last_breakable > 0) {
|
92
|
+
|
93
|
+
// copy from last_breakable to remainder
|
94
|
+
cmark_chunk_set_cstr(&remainder, (char *)renderer->buffer->ptr +
|
95
|
+
renderer->last_breakable + 1);
|
96
|
+
// truncate at last_breakable
|
97
|
+
cmark_strbuf_truncate(renderer->buffer, renderer->last_breakable);
|
98
|
+
// add newline, prefix, and remainder
|
99
|
+
cmark_strbuf_putc(renderer->buffer, '\n');
|
100
|
+
cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr,
|
101
|
+
renderer->prefix->size);
|
102
|
+
cmark_strbuf_put(renderer->buffer, remainder.data, remainder.len);
|
103
|
+
renderer->column = renderer->prefix->size + remainder.len;
|
104
|
+
cmark_chunk_free(&remainder);
|
105
|
+
renderer->last_breakable = 0;
|
106
|
+
renderer->begin_line = false;
|
107
|
+
}
|
108
|
+
|
109
|
+
i += len;
|
110
|
+
}
|
121
111
|
}
|
122
112
|
|
123
113
|
// Assumes no newlines, assumes ascii content:
|
124
|
-
void
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
cmark_strbuf_puts(renderer->buffer, s);
|
129
|
-
renderer->column += renderer->buffer->size - origsize;
|
114
|
+
void cmark_render_ascii(cmark_renderer *renderer, const char *s) {
|
115
|
+
int origsize = renderer->buffer->size;
|
116
|
+
cmark_strbuf_puts(renderer->buffer, s);
|
117
|
+
renderer->column += renderer->buffer->size - origsize;
|
130
118
|
}
|
131
119
|
|
132
|
-
void
|
133
|
-
|
134
|
-
|
135
|
-
utf8proc_encode_char(c, renderer->buffer);
|
136
|
-
renderer->column += 1;
|
120
|
+
void cmark_render_code_point(cmark_renderer *renderer, uint32_t c) {
|
121
|
+
cmark_utf8proc_encode_char(c, renderer->buffer);
|
122
|
+
renderer->column += 1;
|
137
123
|
}
|
138
124
|
|
139
|
-
char*
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
}
|
178
|
-
|
179
|
-
result = (char *)cmark_strbuf_detach(renderer.buffer);
|
180
|
-
|
181
|
-
cmark_iter_free(iter);
|
182
|
-
cmark_strbuf_free(renderer.prefix);
|
183
|
-
cmark_strbuf_free(renderer.buffer);
|
184
|
-
|
185
|
-
return result;
|
125
|
+
char *cmark_render(cmark_node *root, int options, int width,
|
126
|
+
void (*outc)(cmark_renderer *, cmark_escaping, int32_t,
|
127
|
+
unsigned char),
|
128
|
+
int (*render_node)(cmark_renderer *renderer,
|
129
|
+
cmark_node *node,
|
130
|
+
cmark_event_type ev_type, int options)) {
|
131
|
+
cmark_strbuf pref = GH_BUF_INIT;
|
132
|
+
cmark_strbuf buf = GH_BUF_INIT;
|
133
|
+
cmark_node *cur;
|
134
|
+
cmark_event_type ev_type;
|
135
|
+
char *result;
|
136
|
+
cmark_iter *iter = cmark_iter_new(root);
|
137
|
+
|
138
|
+
cmark_renderer renderer = {&buf, &pref, 0, width, 0, 0, true,
|
139
|
+
false, false, outc, S_cr, S_blankline, S_out};
|
140
|
+
|
141
|
+
while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
|
142
|
+
cur = cmark_iter_get_node(iter);
|
143
|
+
if (!render_node(&renderer, cur, ev_type, options)) {
|
144
|
+
// a false value causes us to skip processing
|
145
|
+
// the node's contents. this is used for
|
146
|
+
// autolinks.
|
147
|
+
cmark_iter_reset(iter, cur, CMARK_EVENT_EXIT);
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
// ensure final newline
|
152
|
+
if (renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
|
153
|
+
cmark_strbuf_putc(renderer.buffer, '\n');
|
154
|
+
}
|
155
|
+
|
156
|
+
result = (char *)cmark_strbuf_detach(renderer.buffer);
|
157
|
+
|
158
|
+
cmark_iter_free(iter);
|
159
|
+
cmark_strbuf_free(renderer.prefix);
|
160
|
+
cmark_strbuf_free(renderer.buffer);
|
161
|
+
|
162
|
+
return result;
|
186
163
|
}
|
@@ -9,55 +9,36 @@ extern "C" {
|
|
9
9
|
#include "buffer.h"
|
10
10
|
#include "chunk.h"
|
11
11
|
|
12
|
-
typedef enum
|
13
|
-
LITERAL,
|
14
|
-
NORMAL,
|
15
|
-
TITLE,
|
16
|
-
URL
|
17
|
-
} cmark_escaping;
|
12
|
+
typedef enum { LITERAL, NORMAL, TITLE, URL } cmark_escaping;
|
18
13
|
|
19
14
|
struct cmark_renderer {
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
void (*cr)(struct cmark_renderer*);
|
34
|
-
void (*blankline)(struct cmark_renderer*);
|
35
|
-
void (*out)(struct cmark_renderer*,
|
36
|
-
const char *,
|
37
|
-
bool,
|
38
|
-
cmark_escaping);
|
15
|
+
cmark_strbuf *buffer;
|
16
|
+
cmark_strbuf *prefix;
|
17
|
+
int column;
|
18
|
+
int width;
|
19
|
+
int need_cr;
|
20
|
+
bufsize_t last_breakable;
|
21
|
+
bool begin_line;
|
22
|
+
bool no_wrap;
|
23
|
+
bool in_tight_list_item;
|
24
|
+
void (*outc)(struct cmark_renderer *, cmark_escaping, int32_t, unsigned char);
|
25
|
+
void (*cr)(struct cmark_renderer *);
|
26
|
+
void (*blankline)(struct cmark_renderer *);
|
27
|
+
void (*out)(struct cmark_renderer *, const char *, bool, cmark_escaping);
|
39
28
|
};
|
40
29
|
|
41
30
|
typedef struct cmark_renderer cmark_renderer;
|
42
31
|
|
43
|
-
void
|
44
|
-
cmark_render_ascii(cmark_renderer *renderer, const char* s);
|
32
|
+
void cmark_render_ascii(cmark_renderer *renderer, const char *s);
|
45
33
|
|
46
|
-
void
|
47
|
-
cmark_render_code_point(cmark_renderer *renderer, uint32_t c);
|
34
|
+
void cmark_render_code_point(cmark_renderer *renderer, uint32_t c);
|
48
35
|
|
49
|
-
char*
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
int32_t,
|
56
|
-
unsigned char),
|
57
|
-
int (*render_node)(cmark_renderer *renderer,
|
58
|
-
cmark_node *node,
|
59
|
-
cmark_event_type ev_type,
|
60
|
-
int options));
|
36
|
+
char *cmark_render(cmark_node *root, int options, int width,
|
37
|
+
void (*outc)(cmark_renderer *, cmark_escaping, int32_t,
|
38
|
+
unsigned char),
|
39
|
+
int (*render_node)(cmark_renderer *renderer,
|
40
|
+
cmark_node *node,
|
41
|
+
cmark_event_type ev_type, int options));
|
61
42
|
|
62
43
|
#ifdef __cplusplus
|
63
44
|
}
|