redcarpet 1.12.2 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of redcarpet might be problematic. Click here for more details.
- data/Rakefile +10 -32
- data/ext/{array.c → redcarpet/array.c} +0 -0
- data/ext/{array.h → redcarpet/array.h} +0 -0
- data/ext/{buffer.c → redcarpet/buffer.c} +28 -0
- data/ext/{buffer.h → redcarpet/buffer.h} +8 -28
- data/ext/{extconf.rb → redcarpet/extconf.rb} +0 -0
- data/ext/{xhtml.c → redcarpet/html.c} +46 -187
- data/ext/{xhtml.h → redcarpet/html.h} +20 -15
- data/ext/redcarpet/html_smartypants.c +335 -0
- data/ext/{markdown.c → redcarpet/markdown.c} +66 -20
- data/ext/{markdown.h → redcarpet/markdown.h} +0 -0
- data/ext/{redcarpet.c → redcarpet/redcarpet.c} +28 -21
- data/lib/redcarpet.rb +4 -1
- data/redcarpet.gemspec +14 -13
- data/test/redcarpet_test.rb +1 -1
- metadata +29 -16
@@ -14,30 +14,35 @@
|
|
14
14
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
15
|
*/
|
16
16
|
|
17
|
-
#ifndef
|
18
|
-
#define
|
17
|
+
#ifndef UPSKIRT_HTML_H
|
18
|
+
#define UPSKIRT_HTML_H
|
19
|
+
|
20
|
+
#include "markdown.h"
|
19
21
|
|
20
22
|
typedef enum {
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
HTML_SKIP_HTML = (1 << 0),
|
24
|
+
HTML_SKIP_STYLE = (1 << 1),
|
25
|
+
HTML_SKIP_IMAGES = (1 << 2),
|
26
|
+
HTML_SKIP_LINKS = (1 << 3),
|
27
|
+
HTML_EXPAND_TABS = (1 << 5),
|
28
|
+
HTML_SAFELINK = (1 << 7),
|
29
|
+
HTML_TOC = (1 << 8),
|
30
|
+
HTML_HARD_WRAP = (1 << 9),
|
31
|
+
HTML_GITHUB_BLOCKCODE = (1 << 10),
|
32
|
+
HTML_USE_XHTML = (1 << 11),
|
31
33
|
} render_mode;
|
32
34
|
|
33
35
|
extern void
|
34
|
-
|
36
|
+
upshtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags);
|
37
|
+
|
38
|
+
extern void
|
39
|
+
upshtml_toc_renderer(struct mkd_renderer *renderer);
|
35
40
|
|
36
41
|
extern void
|
37
|
-
|
42
|
+
upshtml_free_renderer(struct mkd_renderer *renderer);
|
38
43
|
|
39
44
|
extern void
|
40
|
-
|
45
|
+
upshtml_smartypants(struct buf *ob, struct buf *text);
|
41
46
|
|
42
47
|
#endif
|
43
48
|
|
@@ -0,0 +1,335 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2011, Vicent Marti
|
3
|
+
*
|
4
|
+
* Permission to use, copy, modify, and distribute this software for any
|
5
|
+
* purpose with or without fee is hereby granted, provided that the above
|
6
|
+
* copyright notice and this permission notice appear in all copies.
|
7
|
+
*
|
8
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
9
|
+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
10
|
+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
11
|
+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
12
|
+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
13
|
+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
14
|
+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
15
|
+
*/
|
16
|
+
|
17
|
+
#include "buffer.h"
|
18
|
+
#include "html.h"
|
19
|
+
|
20
|
+
#include <string.h>
|
21
|
+
#include <stdlib.h>
|
22
|
+
#include <stdio.h>
|
23
|
+
#include <ctype.h>
|
24
|
+
|
25
|
+
struct smartypants_data {
|
26
|
+
int in_squote;
|
27
|
+
int in_dquote;
|
28
|
+
};
|
29
|
+
|
30
|
+
static size_t smartypants_cb__ltag(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size);
|
31
|
+
static size_t smartypants_cb__dquote(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size);
|
32
|
+
static size_t smartypants_cb__amp(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size);
|
33
|
+
static size_t smartypants_cb__period(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size);
|
34
|
+
static size_t smartypants_cb__number(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size);
|
35
|
+
static size_t smartypants_cb__dash(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size);
|
36
|
+
static size_t smartypants_cb__parens(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size);
|
37
|
+
static size_t smartypants_cb__squote(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size);
|
38
|
+
static size_t smartypants_cb__backtick(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size);
|
39
|
+
|
40
|
+
static size_t (*smartypants_cb_ptrs[])
|
41
|
+
(struct buf *, struct smartypants_data *, char, const char *, size_t) =
|
42
|
+
{
|
43
|
+
NULL, /* 0 */
|
44
|
+
smartypants_cb__dash, /* 1 */
|
45
|
+
smartypants_cb__parens, /* 2 */
|
46
|
+
smartypants_cb__squote, /* 3 */
|
47
|
+
smartypants_cb__dquote, /* 4 */
|
48
|
+
smartypants_cb__amp, /* 5 */
|
49
|
+
smartypants_cb__period, /* 6 */
|
50
|
+
smartypants_cb__number, /* 7 */
|
51
|
+
smartypants_cb__ltag, /* 8 */
|
52
|
+
smartypants_cb__backtick, /* 9 */
|
53
|
+
};
|
54
|
+
|
55
|
+
static const char smartypants_cb_chars[] = {
|
56
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
57
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
58
|
+
0, 0, 4, 0, 0, 0, 5, 3, 2, 0, 0, 0, 0, 1, 6, 0,
|
59
|
+
0, 7, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0,
|
60
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
61
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
62
|
+
9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
63
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
64
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
65
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
66
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
67
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
68
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
69
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
70
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
71
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
72
|
+
};
|
73
|
+
|
74
|
+
static inline int
|
75
|
+
word_boundary(char c)
|
76
|
+
{
|
77
|
+
return c == 0 || isspace(c) || ispunct(c);
|
78
|
+
}
|
79
|
+
|
80
|
+
static int
|
81
|
+
smartypants_quotes(struct buf *ob, char previous_char, char next_char, char quote, int *is_open)
|
82
|
+
{
|
83
|
+
char ent[8];
|
84
|
+
|
85
|
+
if (*is_open && !word_boundary(next_char))
|
86
|
+
return 0;
|
87
|
+
|
88
|
+
if (!(*is_open) && !word_boundary(previous_char))
|
89
|
+
return 0;
|
90
|
+
|
91
|
+
snprintf(ent, sizeof(ent), "&%c%cquo;", (*is_open) ? 'r' : 'l', quote);
|
92
|
+
*is_open = !(*is_open);
|
93
|
+
bufputs(ob, ent);
|
94
|
+
return 1;
|
95
|
+
}
|
96
|
+
|
97
|
+
static size_t
|
98
|
+
smartypants_cb__squote(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size)
|
99
|
+
{
|
100
|
+
if (size >= 2) {
|
101
|
+
char t1 = tolower(text[1]);
|
102
|
+
|
103
|
+
if (t1 == '\'') {
|
104
|
+
if (smartypants_quotes(ob, previous_char, size >= 3 ? text[2] : 0, 'd', &smrt->in_dquote))
|
105
|
+
return 1;
|
106
|
+
}
|
107
|
+
|
108
|
+
if ((t1 == 's' || t1 == 't' || t1 == 'm' || t1 == 'd') &&
|
109
|
+
(size == 3 || word_boundary(text[2]))) {
|
110
|
+
BUFPUTSL(ob, "’");
|
111
|
+
return 0;
|
112
|
+
}
|
113
|
+
|
114
|
+
if (size >= 3) {
|
115
|
+
char t2 = tolower(text[2]);
|
116
|
+
|
117
|
+
if (((t1 == 'r' && t2 == 'e') ||
|
118
|
+
(t1 == 'l' && t2 == 'l') ||
|
119
|
+
(t1 == 'v' && t2 == 'e')) &&
|
120
|
+
(size == 4 || word_boundary(text[3]))) {
|
121
|
+
BUFPUTSL(ob, "’");
|
122
|
+
return 0;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
if (smartypants_quotes(ob, previous_char, size > 0 ? text[1] : 0, 's', &smrt->in_squote))
|
128
|
+
return 0;
|
129
|
+
|
130
|
+
bufputc(ob, text[0]);
|
131
|
+
return 0;
|
132
|
+
}
|
133
|
+
|
134
|
+
static size_t
|
135
|
+
smartypants_cb__parens(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size)
|
136
|
+
{
|
137
|
+
if (size >= 3) {
|
138
|
+
char t1 = tolower(text[1]);
|
139
|
+
char t2 = tolower(text[2]);
|
140
|
+
|
141
|
+
if (t1 == 'c' && t2 == ')') {
|
142
|
+
BUFPUTSL(ob, "©");
|
143
|
+
return 2;
|
144
|
+
}
|
145
|
+
|
146
|
+
if (t1 == 'r' && t2 == ')') {
|
147
|
+
BUFPUTSL(ob, "®");
|
148
|
+
return 2;
|
149
|
+
}
|
150
|
+
|
151
|
+
if (size >= 4 && t1 == 't' && t2 == 'm' && text[3] == ')') {
|
152
|
+
BUFPUTSL(ob, "™");
|
153
|
+
return 3;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
bufputc(ob, text[0]);
|
158
|
+
return 0;
|
159
|
+
}
|
160
|
+
|
161
|
+
static size_t
|
162
|
+
smartypants_cb__dash(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size)
|
163
|
+
{
|
164
|
+
if (size >= 2) {
|
165
|
+
if (text[1] == '-') {
|
166
|
+
BUFPUTSL(ob, "—");
|
167
|
+
return 1;
|
168
|
+
}
|
169
|
+
|
170
|
+
if (word_boundary(previous_char) && word_boundary(text[1])) {
|
171
|
+
BUFPUTSL(ob, "–");
|
172
|
+
return 0;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
176
|
+
bufputc(ob, text[0]);
|
177
|
+
return 0;
|
178
|
+
}
|
179
|
+
|
180
|
+
static size_t
|
181
|
+
smartypants_cb__amp(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size)
|
182
|
+
{
|
183
|
+
if (size >= 6 && memcmp(text, """, 6) == 0) {
|
184
|
+
if (smartypants_quotes(ob, previous_char, size >= 7 ? text[6] : 0, 'd', &smrt->in_dquote))
|
185
|
+
return 5;
|
186
|
+
}
|
187
|
+
|
188
|
+
if (size >= 4 && memcmp(text, "�", 4) == 0)
|
189
|
+
return 3;
|
190
|
+
|
191
|
+
bufputc(ob, '&');
|
192
|
+
return 0;
|
193
|
+
}
|
194
|
+
|
195
|
+
static size_t
|
196
|
+
smartypants_cb__period(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size)
|
197
|
+
{
|
198
|
+
if (size >= 3 && text[1] == '.' && text[2] == '.') {
|
199
|
+
BUFPUTSL(ob, "…");
|
200
|
+
return 2;
|
201
|
+
}
|
202
|
+
|
203
|
+
if (size >= 5 && text[1] == ' ' && text[2] == '.' && text[3] == ' ' && text[4] == '.') {
|
204
|
+
BUFPUTSL(ob, "…");
|
205
|
+
return 4;
|
206
|
+
}
|
207
|
+
|
208
|
+
bufputc(ob, text[0]);
|
209
|
+
return 0;
|
210
|
+
}
|
211
|
+
|
212
|
+
static size_t
|
213
|
+
smartypants_cb__backtick(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size)
|
214
|
+
{
|
215
|
+
if (size >= 2 && text[1] == '`') {
|
216
|
+
if (smartypants_quotes(ob, previous_char, size >= 3 ? text[2] : 0, 'd', &smrt->in_dquote))
|
217
|
+
return 1;
|
218
|
+
}
|
219
|
+
|
220
|
+
return 0;
|
221
|
+
}
|
222
|
+
|
223
|
+
static size_t
|
224
|
+
smartypants_cb__number(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size)
|
225
|
+
{
|
226
|
+
if (word_boundary(previous_char) && size >= 3) {
|
227
|
+
if (text[0] == '1' && text[1] == '/' && text[2] == '2') {
|
228
|
+
if (size == 3 || word_boundary(text[3])) {
|
229
|
+
BUFPUTSL(ob, "½");
|
230
|
+
return 2;
|
231
|
+
}
|
232
|
+
}
|
233
|
+
|
234
|
+
if (text[0] == '1' && text[1] == '/' && text[2] == '4') {
|
235
|
+
if (size == 3 || word_boundary(text[3]) ||
|
236
|
+
(size >= 5 && tolower(text[3]) == 't' && tolower(text[4]) == 'h')) {
|
237
|
+
BUFPUTSL(ob, "¼");
|
238
|
+
return 2;
|
239
|
+
}
|
240
|
+
}
|
241
|
+
|
242
|
+
if (text[0] == '3' && text[1] == '/' && text[2] == '4') {
|
243
|
+
if (size == 3 || word_boundary(text[3]) ||
|
244
|
+
(size >= 6 && tolower(text[3]) == 't' && tolower(text[4]) == 'h' && tolower(text[5]) == 's')) {
|
245
|
+
BUFPUTSL(ob, "¾");
|
246
|
+
return 2;
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
bufputc(ob, text[0]);
|
252
|
+
return 0;
|
253
|
+
}
|
254
|
+
|
255
|
+
static size_t
|
256
|
+
smartypants_cb__dquote(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size)
|
257
|
+
{
|
258
|
+
if (!smartypants_quotes(ob, previous_char, size > 0 ? text[1] : 0, 'd', &smrt->in_dquote))
|
259
|
+
BUFPUTSL(ob, """);
|
260
|
+
|
261
|
+
return 0;
|
262
|
+
}
|
263
|
+
|
264
|
+
static size_t
|
265
|
+
smartypants_cb__ltag(struct buf *ob, struct smartypants_data *smrt, char previous_char, const char *text, size_t size)
|
266
|
+
{
|
267
|
+
size_t i = 0;
|
268
|
+
|
269
|
+
while (i < size && text[i] != '>')
|
270
|
+
i++;
|
271
|
+
|
272
|
+
bufput(ob, text, i + 1);
|
273
|
+
return i;
|
274
|
+
}
|
275
|
+
|
276
|
+
#if 0
|
277
|
+
static struct {
|
278
|
+
char c0;
|
279
|
+
const char *pattern;
|
280
|
+
const char *entity;
|
281
|
+
int skip;
|
282
|
+
} smartypants_subs[] = {
|
283
|
+
{ '\'', "'s>", "’", 0 },
|
284
|
+
{ '\'', "'t>", "’", 0 },
|
285
|
+
{ '\'', "'re>", "’", 0 },
|
286
|
+
{ '\'', "'ll>", "’", 0 },
|
287
|
+
{ '\'', "'ve>", "’", 0 },
|
288
|
+
{ '\'', "'m>", "’", 0 },
|
289
|
+
{ '\'', "'d>", "’", 0 },
|
290
|
+
{ '-', "--", "—", 1 },
|
291
|
+
{ '-', "<->", "–", 0 },
|
292
|
+
{ '.', "...", "…", 2 },
|
293
|
+
{ '.', ". . .", "…", 4 },
|
294
|
+
{ '(', "(c)", "©", 2 },
|
295
|
+
{ '(', "(r)", "®", 2 },
|
296
|
+
{ '(', "(tm)", "™", 3 },
|
297
|
+
{ '3', "<3/4>", "¾", 2 },
|
298
|
+
{ '3', "<3/4ths>", "¾", 2 },
|
299
|
+
{ '1', "<1/2>", "½", 2 },
|
300
|
+
{ '1', "<1/4>", "¼", 2 },
|
301
|
+
{ '1', "<1/4th>", "¼", 2 },
|
302
|
+
{ '&', "�", 0, 3 },
|
303
|
+
};
|
304
|
+
#endif
|
305
|
+
|
306
|
+
void
|
307
|
+
upshtml_smartypants(struct buf *ob, struct buf *text)
|
308
|
+
{
|
309
|
+
size_t i;
|
310
|
+
struct smartypants_data smrt = {0, 0};
|
311
|
+
|
312
|
+
if (!text)
|
313
|
+
return;
|
314
|
+
|
315
|
+
bufgrow(ob, text->size);
|
316
|
+
|
317
|
+
for (i = 0; i < text->size; ++i) {
|
318
|
+
size_t org;
|
319
|
+
char action = 0;
|
320
|
+
|
321
|
+
org = i;
|
322
|
+
while (i < text->size && (action = smartypants_cb_chars[(unsigned char)text->data[i]]) == 0)
|
323
|
+
i++;
|
324
|
+
|
325
|
+
if (i > org)
|
326
|
+
bufput(ob, text->data + org, i - org);
|
327
|
+
|
328
|
+
if (i < text->size) {
|
329
|
+
i += smartypants_cb_ptrs[(int)action]
|
330
|
+
(ob, &smrt, i ? text->data[i - 1] : 0, text->data + i, text->size - i);
|
331
|
+
}
|
332
|
+
}
|
333
|
+
}
|
334
|
+
|
335
|
+
|
@@ -50,12 +50,44 @@ struct render;
|
|
50
50
|
typedef size_t
|
51
51
|
(*char_trigger)(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size);
|
52
52
|
|
53
|
+
static size_t char_emphasis(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size);
|
54
|
+
static size_t char_linebreak(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size);
|
55
|
+
static size_t char_codespan(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size);
|
56
|
+
static size_t char_escape(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size);
|
57
|
+
static size_t char_entity(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size);
|
58
|
+
static size_t char_langle_tag(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size);
|
59
|
+
static size_t char_autolink(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size);
|
60
|
+
static size_t char_link(struct buf *ob, struct render *rndr, char *data, size_t offset, size_t size);
|
61
|
+
|
62
|
+
enum markdown_char_t {
|
63
|
+
MD_CHAR_NONE = 0,
|
64
|
+
MD_CHAR_EMPHASIS,
|
65
|
+
MD_CHAR_CODESPAN,
|
66
|
+
MD_CHAR_LINEBREAK,
|
67
|
+
MD_CHAR_LINK,
|
68
|
+
MD_CHAR_LANGLE,
|
69
|
+
MD_CHAR_ESCAPE,
|
70
|
+
MD_CHAR_ENTITITY,
|
71
|
+
MD_CHAR_AUTOLINK,
|
72
|
+
};
|
73
|
+
|
74
|
+
static char_trigger markdown_char_ptrs[] = {
|
75
|
+
NULL,
|
76
|
+
&char_emphasis,
|
77
|
+
&char_codespan,
|
78
|
+
&char_linebreak,
|
79
|
+
&char_link,
|
80
|
+
&char_langle_tag,
|
81
|
+
&char_escape,
|
82
|
+
&char_entity,
|
83
|
+
&char_autolink,
|
84
|
+
};
|
53
85
|
|
54
86
|
/* render • structure containing one particular render */
|
55
87
|
struct render {
|
56
88
|
struct mkd_renderer make;
|
57
89
|
struct array refs;
|
58
|
-
|
90
|
+
char active_char[256];
|
59
91
|
struct parray work_bufs[2];
|
60
92
|
unsigned int ext_flags;
|
61
93
|
size_t max_nesting;
|
@@ -305,7 +337,7 @@ static void
|
|
305
337
|
parse_inline(struct buf *ob, struct render *rndr, char *data, size_t size)
|
306
338
|
{
|
307
339
|
size_t i = 0, end = 0;
|
308
|
-
|
340
|
+
char action = 0;
|
309
341
|
struct buf work = { 0, 0, 0, 0, 0 };
|
310
342
|
|
311
343
|
if (rndr->work_bufs[BUFFER_SPAN].size +
|
@@ -330,7 +362,7 @@ parse_inline(struct buf *ob, struct render *rndr, char *data, size_t size)
|
|
330
362
|
i = end;
|
331
363
|
|
332
364
|
/* calling the trigger */
|
333
|
-
end = action(ob, rndr, data + i, i, size - i);
|
365
|
+
end = markdown_char_ptrs[(int)action](ob, rndr, data + i, i, size - i);
|
334
366
|
if (!end) /* no action from the callback */
|
335
367
|
end = i + 1;
|
336
368
|
else {
|
@@ -1755,20 +1787,34 @@ parse_table_header(struct buf *ob, struct render *rndr, char *data, size_t size,
|
|
1755
1787
|
under_end++;
|
1756
1788
|
|
1757
1789
|
for (col = 0; col < *columns && i < under_end; ++col) {
|
1790
|
+
size_t dashes = 0;
|
1791
|
+
|
1792
|
+
while (i < under_end && (data[i] == ' ' || data[i] == '\t'))
|
1793
|
+
i++;
|
1794
|
+
|
1758
1795
|
if (data[i] == ':') {
|
1759
1796
|
i++; (*column_data)[col] |= MKD_TABLE_ALIGN_L;
|
1797
|
+
dashes++;
|
1760
1798
|
}
|
1761
1799
|
|
1762
|
-
while (i < under_end && data[i] == '-')
|
1763
|
-
i++;
|
1800
|
+
while (i < under_end && data[i] == '-') {
|
1801
|
+
i++; dashes++;
|
1802
|
+
}
|
1764
1803
|
|
1765
1804
|
if (i < under_end && data[i] == ':') {
|
1766
1805
|
i++; (*column_data)[col] |= MKD_TABLE_ALIGN_R;
|
1806
|
+
dashes++;
|
1767
1807
|
}
|
1768
1808
|
|
1809
|
+
while (i < under_end && (data[i] == ' ' || data[i] == '\t'))
|
1810
|
+
i++;
|
1811
|
+
|
1769
1812
|
if (i < under_end && data[i] != '|')
|
1770
1813
|
break;
|
1771
1814
|
|
1815
|
+
if (dashes < 3)
|
1816
|
+
break;
|
1817
|
+
|
1772
1818
|
i++;
|
1773
1819
|
}
|
1774
1820
|
|
@@ -2052,34 +2098,34 @@ ups_markdown(struct buf *ob, struct buf *ib, const struct mkd_renderer *rndrer,
|
|
2052
2098
|
rndr.active_char[i] = 0;
|
2053
2099
|
|
2054
2100
|
if (rndr.make.emphasis || rndr.make.double_emphasis || rndr.make.triple_emphasis) {
|
2055
|
-
rndr.active_char['*'] =
|
2056
|
-
rndr.active_char['_'] =
|
2101
|
+
rndr.active_char['*'] = MD_CHAR_EMPHASIS;
|
2102
|
+
rndr.active_char['_'] = MD_CHAR_EMPHASIS;
|
2057
2103
|
if (extensions & MKDEXT_STRIKETHROUGH)
|
2058
|
-
rndr.active_char['~'] =
|
2104
|
+
rndr.active_char['~'] = MD_CHAR_EMPHASIS;
|
2059
2105
|
}
|
2060
2106
|
|
2061
2107
|
if (rndr.make.codespan)
|
2062
|
-
rndr.active_char['`'] =
|
2108
|
+
rndr.active_char['`'] = MD_CHAR_CODESPAN;
|
2063
2109
|
|
2064
2110
|
if (rndr.make.linebreak)
|
2065
|
-
rndr.active_char['\n'] =
|
2111
|
+
rndr.active_char['\n'] = MD_CHAR_LINEBREAK;
|
2066
2112
|
|
2067
2113
|
if (rndr.make.image || rndr.make.link)
|
2068
|
-
rndr.active_char['['] =
|
2114
|
+
rndr.active_char['['] = MD_CHAR_LINK;
|
2069
2115
|
|
2070
|
-
rndr.active_char['<'] =
|
2071
|
-
rndr.active_char['\\'] =
|
2072
|
-
rndr.active_char['&'] =
|
2116
|
+
rndr.active_char['<'] = MD_CHAR_LANGLE;
|
2117
|
+
rndr.active_char['\\'] = MD_CHAR_ESCAPE;
|
2118
|
+
rndr.active_char['&'] = MD_CHAR_ENTITITY;
|
2073
2119
|
|
2074
2120
|
if (extensions & MKDEXT_AUTOLINK) {
|
2075
|
-
rndr.active_char['h'] =
|
2076
|
-
rndr.active_char['H'] =
|
2121
|
+
rndr.active_char['h'] = MD_CHAR_AUTOLINK; // http, https
|
2122
|
+
rndr.active_char['H'] = MD_CHAR_AUTOLINK;
|
2077
2123
|
|
2078
|
-
rndr.active_char['f'] =
|
2079
|
-
rndr.active_char['F'] =
|
2124
|
+
rndr.active_char['f'] = MD_CHAR_AUTOLINK; // ftp
|
2125
|
+
rndr.active_char['F'] = MD_CHAR_AUTOLINK;
|
2080
2126
|
|
2081
|
-
rndr.active_char['m'] =
|
2082
|
-
rndr.active_char['M'] =
|
2127
|
+
rndr.active_char['m'] = MD_CHAR_AUTOLINK; // mailto
|
2128
|
+
rndr.active_char['M'] = MD_CHAR_AUTOLINK;
|
2083
2129
|
}
|
2084
2130
|
|
2085
2131
|
/* Extension data */
|