redcarpet 2.0.0b3 → 2.0.0b4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of redcarpet might be problematic. Click here for more details.
- data/README.markdown +39 -5
- data/Rakefile +2 -2
- data/ext/redcarpet/autolink.c +12 -12
- data/ext/redcarpet/autolink.h +4 -4
- data/ext/redcarpet/buffer.c +123 -218
- data/ext/redcarpet/buffer.h +49 -112
- data/ext/redcarpet/html.c +83 -117
- data/ext/redcarpet/html.h +9 -10
- data/ext/redcarpet/html_blocks.h +205 -0
- data/ext/redcarpet/html_smartypants.c +63 -39
- data/ext/redcarpet/markdown.c +456 -377
- data/ext/redcarpet/markdown.h +43 -29
- data/ext/redcarpet/rc_markdown.c +60 -34
- data/ext/redcarpet/rc_render.c +29 -35
- data/ext/redcarpet/redcarpet.h +4 -3
- data/ext/redcarpet/stack.c +81 -0
- data/ext/redcarpet/stack.h +21 -0
- data/lib/redcarpet.rb +4 -23
- data/redcarpet.gemspec +6 -4
- data/test/redcarpet_test.rb +39 -43
- metadata +56 -33
- data/ext/redcarpet/array.c +0 -300
- data/ext/redcarpet/array.h +0 -147
data/ext/redcarpet/buffer.h
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
/* buffer.h - automatic buffer structure */
|
2
|
-
|
3
1
|
/*
|
4
2
|
* Copyright (c) 2008, Natacha Porté
|
3
|
+
* Copyright (c) 2011, Vicent Martí
|
5
4
|
*
|
6
5
|
* Permission to use, copy, modify, and distribute this software for any
|
7
6
|
* purpose with or without fee is hereby granted, provided that the above
|
@@ -16,139 +15,77 @@
|
|
16
15
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
17
16
|
*/
|
18
17
|
|
19
|
-
#ifndef
|
20
|
-
#define
|
18
|
+
#ifndef __GEN_BUFFER_H__
|
19
|
+
#define __GEN_BUFFER_H__
|
21
20
|
|
22
21
|
#include <stddef.h>
|
22
|
+
#include <stdarg.h>
|
23
|
+
#include <stdint.h>
|
23
24
|
|
24
25
|
#if defined(_MSC_VER)
|
25
26
|
#define __attribute__(x)
|
26
27
|
#define inline
|
27
|
-
#define strncasecmp _strnicmp
|
28
|
-
#define snprintf _snprintf
|
29
|
-
#define va_copy(d,s) ((d) = (s))
|
30
28
|
#endif
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
typedef enum {
|
31
|
+
BUF_OK = 0,
|
32
|
+
BUF_ENOMEM = -1,
|
33
|
+
} buferror_t;
|
35
34
|
|
36
|
-
/* struct buf
|
35
|
+
/* struct buf: character array buffer */
|
37
36
|
struct buf {
|
38
|
-
|
39
|
-
size_t
|
40
|
-
size_t
|
41
|
-
size_t
|
42
|
-
|
43
|
-
|
44
|
-
/**********
|
45
|
-
* MACROS *
|
46
|
-
**********/
|
47
|
-
|
48
|
-
#define STRLEN(x) (sizeof(x) - 1)
|
49
|
-
|
50
|
-
/* CONST_BUF • global buffer from a string litteral */
|
51
|
-
#define CONST_BUF(name, string) \
|
52
|
-
static struct buf name = { string, sizeof string -1, sizeof string }
|
53
|
-
|
54
|
-
|
55
|
-
/* VOLATILE_BUF • macro for creating a volatile buffer on the stack */
|
56
|
-
#define VOLATILE_BUF(name, strname) \
|
57
|
-
struct buf name = { strname, strlen(strname) }
|
58
|
-
|
59
|
-
|
60
|
-
/* BUFPUTSL • optimized bufputs of a string litteral */
|
61
|
-
#define BUFPUTSL(output, litteral) \
|
62
|
-
bufput(output, litteral, sizeof litteral - 1)
|
63
|
-
|
64
|
-
|
37
|
+
uint8_t *data; /* actual character data */
|
38
|
+
size_t size; /* size of the string */
|
39
|
+
size_t asize; /* allocated size (0 = volatile buffer) */
|
40
|
+
size_t unit; /* reallocation unit size (0 = read-only buffer) */
|
41
|
+
};
|
65
42
|
|
66
|
-
|
67
|
-
|
68
|
-
|
43
|
+
/* CONST_BUF: global buffer from a string litteral */
|
44
|
+
#define BUF_STATIC(string) \
|
45
|
+
{ (uint8_t *)string, sizeof string -1, sizeof string, 0, 0 }
|
69
46
|
|
70
|
-
/*
|
71
|
-
|
72
|
-
|
47
|
+
/* VOLATILE_BUF: macro for creating a volatile buffer on the stack */
|
48
|
+
#define BUF_VOLATILE(strname) \
|
49
|
+
{ (uint8_t *)strname, strlen(strname), 0, 0, 0 }
|
73
50
|
|
74
|
-
/*
|
75
|
-
|
76
|
-
|
51
|
+
/* BUFPUTSL: optimized bufputs of a string litteral */
|
52
|
+
#define BUFPUTSL(output, literal) \
|
53
|
+
bufput(output, literal, sizeof literal - 1)
|
77
54
|
|
78
|
-
/*
|
79
|
-
int
|
80
|
-
bufcmps(const struct buf *, const char *);
|
55
|
+
/* bufgrow: increasing the allocated size to the given value */
|
56
|
+
int bufgrow(struct buf *, size_t);
|
81
57
|
|
82
|
-
/*
|
83
|
-
|
84
|
-
bufprefix(const struct buf *buf, const char *prefix);
|
58
|
+
/* bufnew: allocation of a new buffer */
|
59
|
+
struct buf *bufnew(size_t) __attribute__ ((malloc));
|
85
60
|
|
86
|
-
/*
|
87
|
-
struct buf *
|
88
|
-
bufdup(const struct buf *, size_t)
|
89
|
-
__attribute__ ((malloc));
|
61
|
+
/* bufnullterm: NUL-termination of the string array (making a C-string) */
|
62
|
+
const char *bufcstr(struct buf *);
|
90
63
|
|
91
|
-
/*
|
92
|
-
int
|
93
|
-
bufgrow(struct buf *, size_t);
|
64
|
+
/* bufprefix: compare the beginning of a buffer with a string */
|
65
|
+
int bufprefix(const struct buf *buf, const char *prefix);
|
94
66
|
|
95
|
-
/*
|
96
|
-
struct buf
|
97
|
-
bufnew(size_t)
|
98
|
-
__attribute__ ((malloc));
|
67
|
+
/* bufput: appends raw data to a buffer */
|
68
|
+
void bufput(struct buf *, const void *, size_t);
|
99
69
|
|
100
|
-
/*
|
101
|
-
void
|
102
|
-
bufnullterm(struct buf *);
|
70
|
+
/* bufputs: appends a NUL-terminated string to a buffer */
|
71
|
+
void bufputs(struct buf *, const char *);
|
103
72
|
|
104
|
-
/*
|
105
|
-
void
|
106
|
-
bufprintf(struct buf *, const char *, ...)
|
107
|
-
__attribute__ ((format (printf, 2, 3)));
|
73
|
+
/* bufputc: appends a single char to a buffer */
|
74
|
+
void bufputc(struct buf *, int);
|
108
75
|
|
109
|
-
/*
|
110
|
-
void
|
111
|
-
bufput(struct buf *, const void*, size_t);
|
76
|
+
/* bufrelease: decrease the reference count and free the buffer if needed */
|
77
|
+
void bufrelease(struct buf *);
|
112
78
|
|
113
|
-
/*
|
114
|
-
void
|
115
|
-
bufputs(struct buf *, const char*);
|
79
|
+
/* bufreset: frees internal data of the buffer */
|
80
|
+
void bufreset(struct buf *);
|
116
81
|
|
117
|
-
/*
|
118
|
-
void
|
119
|
-
bufputc(struct buf *, char);
|
82
|
+
/* bufslurp: removes a given number of bytes from the head of the array */
|
83
|
+
void bufslurp(struct buf *, size_t);
|
120
84
|
|
121
|
-
/*
|
122
|
-
void
|
123
|
-
bufrelease(struct buf *);
|
85
|
+
/* bufprintf: formatted printing to a buffer */
|
86
|
+
void bufprintf(struct buf *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
|
124
87
|
|
125
|
-
/*
|
126
|
-
void
|
127
|
-
bufreset(struct buf *);
|
88
|
+
/* vbufprintf: stdarg variant of formatted printing into a buffer */
|
89
|
+
void vbufprintf(struct buf *, const char * , va_list);
|
128
90
|
|
129
|
-
|
130
|
-
void
|
131
|
-
bufset(struct buf **, struct buf *);
|
132
|
-
|
133
|
-
/* bufslurp • removes a given number of bytes from the head of the array */
|
134
|
-
void
|
135
|
-
bufslurp(struct buf *, size_t);
|
136
|
-
|
137
|
-
/* buftoi • converts the numbers at the beginning of the buf into an int */
|
138
|
-
int
|
139
|
-
buftoi(struct buf *, size_t, size_t *);
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
#ifdef BUFFER_STDARG
|
144
|
-
#include <stdarg.h>
|
145
|
-
|
146
|
-
/* vbufprintf • stdarg variant of formatted printing into a buffer */
|
147
|
-
void
|
148
|
-
vbufprintf(struct buf *, const char*, va_list);
|
149
|
-
|
150
|
-
#endif /* def BUFFER_STDARG */
|
151
|
-
|
152
|
-
#endif /* ndef LITHIUM_BUFFER_H */
|
153
|
-
|
154
|
-
/* vim: set filetype=c: */
|
91
|
+
#endif
|
data/ext/redcarpet/html.c
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
#define USE_XHTML(opt) (opt->flags & HTML_USE_XHTML)
|
27
27
|
|
28
28
|
static inline void
|
29
|
-
|
29
|
+
put_escaped_char(struct buf *ob, int c)
|
30
30
|
{
|
31
31
|
switch (c) {
|
32
32
|
case '<': BUFPUTSL(ob, "<"); break;
|
@@ -39,27 +39,29 @@ put_scaped_char(struct buf *ob, char c)
|
|
39
39
|
|
40
40
|
/* sdhtml_escape • copy the buffer entity-escaping '<', '>', '&' and '"' */
|
41
41
|
void
|
42
|
-
sdhtml_escape(struct buf *ob, const
|
42
|
+
sdhtml_escape(struct buf *ob, const uint8_t *src, size_t size)
|
43
43
|
{
|
44
44
|
size_t i = 0, org;
|
45
45
|
while (i < size) {
|
46
46
|
/* copying directly unescaped characters */
|
47
47
|
org = i;
|
48
|
+
|
48
49
|
while (i < size && src[i] != '<' && src[i] != '>'
|
49
|
-
|
50
|
+
&& src[i] != '&' && src[i] != '"')
|
50
51
|
i += 1;
|
52
|
+
|
51
53
|
if (i > org) bufput(ob, src + org, i - org);
|
52
54
|
|
53
55
|
/* escaping */
|
54
56
|
if (i >= size) break;
|
55
57
|
|
56
|
-
|
58
|
+
put_escaped_char(ob, src[i]);
|
57
59
|
i++;
|
58
60
|
}
|
59
61
|
}
|
60
62
|
|
61
63
|
int
|
62
|
-
sdhtml_tag(const
|
64
|
+
sdhtml_tag(const uint8_t *tag_data, size_t tag_size, const char *tagname)
|
63
65
|
{
|
64
66
|
size_t i;
|
65
67
|
int closed = 0;
|
@@ -95,7 +97,7 @@ sdhtml_tag(const char *tag_data, size_t tag_size, const char *tagname)
|
|
95
97
|
* GENERIC RENDERER *
|
96
98
|
********************/
|
97
99
|
static int
|
98
|
-
rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *opaque)
|
100
|
+
rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque)
|
99
101
|
{
|
100
102
|
struct html_renderopt *options = opaque;
|
101
103
|
|
@@ -110,7 +112,7 @@ rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *op
|
|
110
112
|
BUFPUTSL(ob, "<a href=\"");
|
111
113
|
if (type == MKDA_EMAIL)
|
112
114
|
BUFPUTSL(ob, "mailto:");
|
113
|
-
|
115
|
+
sdhtml_escape(ob, link->data, link->size);
|
114
116
|
|
115
117
|
if (options->link_attributes) {
|
116
118
|
bufputc(ob, '\"');
|
@@ -137,7 +139,7 @@ rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *op
|
|
137
139
|
}
|
138
140
|
|
139
141
|
static void
|
140
|
-
rndr_blockcode(struct buf *ob, struct buf *text, struct buf *lang, void *opaque)
|
142
|
+
rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque)
|
141
143
|
{
|
142
144
|
if (ob->size) bufputc(ob, '\n');
|
143
145
|
|
@@ -172,53 +174,8 @@ rndr_blockcode(struct buf *ob, struct buf *text, struct buf *lang, void *opaque)
|
|
172
174
|
BUFPUTSL(ob, "</code></pre>\n");
|
173
175
|
}
|
174
176
|
|
175
|
-
/*
|
176
|
-
* GitHub style code block:
|
177
|
-
*
|
178
|
-
* <pre lang="LANG"><code>
|
179
|
-
* ...
|
180
|
-
* </pre></code>
|
181
|
-
*
|
182
|
-
* Unlike other parsers, we store the language identifier in the <pre>,
|
183
|
-
* and don't let the user generate custom classes.
|
184
|
-
*
|
185
|
-
* The language identifier in the <pre> block gets postprocessed and all
|
186
|
-
* the code inside gets syntax highlighted with Pygments. This is much safer
|
187
|
-
* than letting the user specify a CSS class for highlighting.
|
188
|
-
*
|
189
|
-
* Note that we only generate HTML for the first specifier.
|
190
|
-
* E.g.
|
191
|
-
* ~~~~ {.python .numbered} => <pre lang="python"><code>
|
192
|
-
*/
|
193
177
|
static void
|
194
|
-
|
195
|
-
{
|
196
|
-
if (ob->size) bufputc(ob, '\n');
|
197
|
-
|
198
|
-
if (lang && lang->size) {
|
199
|
-
size_t i = 0;
|
200
|
-
BUFPUTSL(ob, "<pre lang=\"");
|
201
|
-
|
202
|
-
while (i < lang->size && !isspace(lang->data[i]))
|
203
|
-
i++;
|
204
|
-
|
205
|
-
if (lang->data[0] == '.')
|
206
|
-
sdhtml_escape(ob, lang->data + 1, i - 1);
|
207
|
-
else
|
208
|
-
sdhtml_escape(ob, lang->data, i);
|
209
|
-
|
210
|
-
BUFPUTSL(ob, "\"><code>");
|
211
|
-
} else
|
212
|
-
BUFPUTSL(ob, "<pre><code>");
|
213
|
-
|
214
|
-
if (text)
|
215
|
-
sdhtml_escape(ob, text->data, text->size);
|
216
|
-
|
217
|
-
BUFPUTSL(ob, "</code></pre>\n");
|
218
|
-
}
|
219
|
-
|
220
|
-
static void
|
221
|
-
rndr_blockquote(struct buf *ob, struct buf *text, void *opaque)
|
178
|
+
rndr_blockquote(struct buf *ob, const struct buf *text, void *opaque)
|
222
179
|
{
|
223
180
|
if (ob->size) bufputc(ob, '\n');
|
224
181
|
BUFPUTSL(ob, "<blockquote>\n");
|
@@ -227,7 +184,7 @@ rndr_blockquote(struct buf *ob, struct buf *text, void *opaque)
|
|
227
184
|
}
|
228
185
|
|
229
186
|
static int
|
230
|
-
rndr_codespan(struct buf *ob, struct buf *text, void *opaque)
|
187
|
+
rndr_codespan(struct buf *ob, const struct buf *text, void *opaque)
|
231
188
|
{
|
232
189
|
BUFPUTSL(ob, "<code>");
|
233
190
|
if (text) sdhtml_escape(ob, text->data, text->size);
|
@@ -236,7 +193,7 @@ rndr_codespan(struct buf *ob, struct buf *text, void *opaque)
|
|
236
193
|
}
|
237
194
|
|
238
195
|
static int
|
239
|
-
rndr_strikethrough(struct buf *ob, struct buf *text, void *opaque)
|
196
|
+
rndr_strikethrough(struct buf *ob, const struct buf *text, void *opaque)
|
240
197
|
{
|
241
198
|
if (!text || !text->size)
|
242
199
|
return 0;
|
@@ -248,7 +205,7 @@ rndr_strikethrough(struct buf *ob, struct buf *text, void *opaque)
|
|
248
205
|
}
|
249
206
|
|
250
207
|
static int
|
251
|
-
rndr_double_emphasis(struct buf *ob, struct buf *text, void *opaque)
|
208
|
+
rndr_double_emphasis(struct buf *ob, const struct buf *text, void *opaque)
|
252
209
|
{
|
253
210
|
if (!text || !text->size)
|
254
211
|
return 0;
|
@@ -261,7 +218,7 @@ rndr_double_emphasis(struct buf *ob, struct buf *text, void *opaque)
|
|
261
218
|
}
|
262
219
|
|
263
220
|
static int
|
264
|
-
rndr_emphasis(struct buf *ob, struct buf *text, void *opaque)
|
221
|
+
rndr_emphasis(struct buf *ob, const struct buf *text, void *opaque)
|
265
222
|
{
|
266
223
|
if (!text || !text->size) return 0;
|
267
224
|
BUFPUTSL(ob, "<em>");
|
@@ -273,16 +230,16 @@ rndr_emphasis(struct buf *ob, struct buf *text, void *opaque)
|
|
273
230
|
static int
|
274
231
|
rndr_linebreak(struct buf *ob, void *opaque)
|
275
232
|
{
|
276
|
-
struct html_renderopt *options = opaque;
|
233
|
+
struct html_renderopt *options = opaque;
|
277
234
|
bufputs(ob, USE_XHTML(options) ? "<br/>\n" : "<br>\n");
|
278
235
|
return 1;
|
279
236
|
}
|
280
237
|
|
281
238
|
static void
|
282
|
-
rndr_header(struct buf *ob, struct buf *text, int level, void *opaque)
|
239
|
+
rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
|
283
240
|
{
|
284
241
|
struct html_renderopt *options = opaque;
|
285
|
-
|
242
|
+
|
286
243
|
if (ob->size)
|
287
244
|
bufputc(ob, '\n');
|
288
245
|
|
@@ -296,17 +253,17 @@ rndr_header(struct buf *ob, struct buf *text, int level, void *opaque)
|
|
296
253
|
}
|
297
254
|
|
298
255
|
static int
|
299
|
-
rndr_link(struct buf *ob, struct buf *link, struct buf *title, struct buf *content, void *opaque)
|
256
|
+
rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque)
|
300
257
|
{
|
301
258
|
struct html_renderopt *options = opaque;
|
302
|
-
|
303
|
-
if ((options->flags & HTML_SAFELINK) != 0 && !sd_autolink_issafe(link->data, link->size))
|
259
|
+
|
260
|
+
if (link != NULL && (options->flags & HTML_SAFELINK) != 0 && !sd_autolink_issafe(link->data, link->size))
|
304
261
|
return 0;
|
305
262
|
|
306
263
|
BUFPUTSL(ob, "<a href=\"");
|
307
264
|
|
308
265
|
if (link && link->size)
|
309
|
-
|
266
|
+
sdhtml_escape(ob, link->data, link->size);
|
310
267
|
|
311
268
|
if (title && title->size) {
|
312
269
|
BUFPUTSL(ob, "\" title=\"");
|
@@ -327,7 +284,7 @@ rndr_link(struct buf *ob, struct buf *link, struct buf *title, struct buf *conte
|
|
327
284
|
}
|
328
285
|
|
329
286
|
static void
|
330
|
-
rndr_list(struct buf *ob, struct buf *text, int flags, void *opaque)
|
287
|
+
rndr_list(struct buf *ob, const struct buf *text, int flags, void *opaque)
|
331
288
|
{
|
332
289
|
if (ob->size) bufputc(ob, '\n');
|
333
290
|
bufput(ob, flags & MKD_LIST_ORDERED ? "<ol>\n" : "<ul>\n", 5);
|
@@ -336,18 +293,21 @@ rndr_list(struct buf *ob, struct buf *text, int flags, void *opaque)
|
|
336
293
|
}
|
337
294
|
|
338
295
|
static void
|
339
|
-
rndr_listitem(struct buf *ob, struct buf *text, int flags, void *opaque)
|
296
|
+
rndr_listitem(struct buf *ob, const struct buf *text, int flags, void *opaque)
|
340
297
|
{
|
341
298
|
BUFPUTSL(ob, "<li>");
|
342
299
|
if (text) {
|
343
|
-
|
344
|
-
|
345
|
-
|
300
|
+
size_t size = text->size;
|
301
|
+
while (size && text->data[size - 1] == '\n')
|
302
|
+
size--;
|
303
|
+
|
304
|
+
bufput(ob, text->data, size);
|
305
|
+
}
|
346
306
|
BUFPUTSL(ob, "</li>\n");
|
347
307
|
}
|
348
308
|
|
349
309
|
static void
|
350
|
-
rndr_paragraph(struct buf *ob, struct buf *text, void *opaque)
|
310
|
+
rndr_paragraph(struct buf *ob, const struct buf *text, void *opaque)
|
351
311
|
{
|
352
312
|
struct html_renderopt *options = opaque;
|
353
313
|
size_t i = 0;
|
@@ -379,7 +339,7 @@ rndr_paragraph(struct buf *ob, struct buf *text, void *opaque)
|
|
379
339
|
*/
|
380
340
|
if (i >= text->size - 1)
|
381
341
|
break;
|
382
|
-
|
342
|
+
|
383
343
|
rndr_linebreak(ob, opaque);
|
384
344
|
i++;
|
385
345
|
}
|
@@ -390,7 +350,7 @@ rndr_paragraph(struct buf *ob, struct buf *text, void *opaque)
|
|
390
350
|
}
|
391
351
|
|
392
352
|
static void
|
393
|
-
rndr_raw_block(struct buf *ob, struct buf *text, void *opaque)
|
353
|
+
rndr_raw_block(struct buf *ob, const struct buf *text, void *opaque)
|
394
354
|
{
|
395
355
|
size_t org, sz;
|
396
356
|
if (!text) return;
|
@@ -405,7 +365,7 @@ rndr_raw_block(struct buf *ob, struct buf *text, void *opaque)
|
|
405
365
|
}
|
406
366
|
|
407
367
|
static int
|
408
|
-
rndr_triple_emphasis(struct buf *ob, struct buf *text, void *opaque)
|
368
|
+
rndr_triple_emphasis(struct buf *ob, const struct buf *text, void *opaque)
|
409
369
|
{
|
410
370
|
if (!text || !text->size) return 0;
|
411
371
|
BUFPUTSL(ob, "<strong><em>");
|
@@ -417,15 +377,15 @@ rndr_triple_emphasis(struct buf *ob, struct buf *text, void *opaque)
|
|
417
377
|
static void
|
418
378
|
rndr_hrule(struct buf *ob, void *opaque)
|
419
379
|
{
|
420
|
-
struct html_renderopt *options = opaque;
|
380
|
+
struct html_renderopt *options = opaque;
|
421
381
|
if (ob->size) bufputc(ob, '\n');
|
422
382
|
bufputs(ob, USE_XHTML(options) ? "<hr/>\n" : "<hr>\n");
|
423
383
|
}
|
424
384
|
|
425
385
|
static int
|
426
|
-
rndr_image(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt, void *opaque)
|
386
|
+
rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
|
427
387
|
{
|
428
|
-
struct html_renderopt *options = opaque;
|
388
|
+
struct html_renderopt *options = opaque;
|
429
389
|
if (!link || !link->size) return 0;
|
430
390
|
BUFPUTSL(ob, "<img src=\"");
|
431
391
|
sdhtml_escape(ob, link->data, link->size);
|
@@ -441,9 +401,9 @@ rndr_image(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt,
|
|
441
401
|
}
|
442
402
|
|
443
403
|
static int
|
444
|
-
rndr_raw_html(struct buf *ob, struct buf *text, void *opaque)
|
404
|
+
rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque)
|
445
405
|
{
|
446
|
-
struct html_renderopt *options = opaque;
|
406
|
+
struct html_renderopt *options = opaque;
|
447
407
|
|
448
408
|
if ((options->flags & HTML_SKIP_HTML) != 0)
|
449
409
|
return 1;
|
@@ -462,7 +422,7 @@ rndr_raw_html(struct buf *ob, struct buf *text, void *opaque)
|
|
462
422
|
}
|
463
423
|
|
464
424
|
static void
|
465
|
-
rndr_table(struct buf *ob, struct buf *header, struct buf *body, void *opaque)
|
425
|
+
rndr_table(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque)
|
466
426
|
{
|
467
427
|
if (ob->size) bufputc(ob, '\n');
|
468
428
|
BUFPUTSL(ob, "<table><thead>\n");
|
@@ -475,7 +435,7 @@ rndr_table(struct buf *ob, struct buf *header, struct buf *body, void *opaque)
|
|
475
435
|
}
|
476
436
|
|
477
437
|
static void
|
478
|
-
rndr_tablerow(struct buf *ob, struct buf *text, void *opaque)
|
438
|
+
rndr_tablerow(struct buf *ob, const struct buf *text, void *opaque)
|
479
439
|
{
|
480
440
|
BUFPUTSL(ob, "<tr>\n");
|
481
441
|
if (text)
|
@@ -484,33 +444,43 @@ rndr_tablerow(struct buf *ob, struct buf *text, void *opaque)
|
|
484
444
|
}
|
485
445
|
|
486
446
|
static void
|
487
|
-
rndr_tablecell(struct buf *ob, struct buf *text, int
|
447
|
+
rndr_tablecell(struct buf *ob, const struct buf *text, int flags, void *opaque)
|
488
448
|
{
|
489
|
-
|
490
|
-
|
491
|
-
|
449
|
+
if (flags & MKD_TABLE_HEADER) {
|
450
|
+
BUFPUTSL(ob, "<th");
|
451
|
+
} else {
|
452
|
+
BUFPUTSL(ob, "<td");
|
453
|
+
}
|
454
|
+
|
455
|
+
switch (flags & MKD_TABLE_ALIGNMASK) {
|
456
|
+
case MKD_TABLE_ALIGN_CENTER:
|
457
|
+
BUFPUTSL(ob, " align=\"center\">");
|
492
458
|
break;
|
493
459
|
|
494
|
-
case
|
495
|
-
BUFPUTSL(ob, "
|
460
|
+
case MKD_TABLE_ALIGN_L:
|
461
|
+
BUFPUTSL(ob, " align=\"left\">");
|
496
462
|
break;
|
497
463
|
|
498
|
-
case
|
499
|
-
BUFPUTSL(ob, "
|
464
|
+
case MKD_TABLE_ALIGN_R:
|
465
|
+
BUFPUTSL(ob, " align=\"right\">");
|
500
466
|
break;
|
501
467
|
|
502
468
|
default:
|
503
|
-
BUFPUTSL(ob, "
|
504
|
-
break;
|
469
|
+
BUFPUTSL(ob, ">");
|
505
470
|
}
|
506
471
|
|
507
472
|
if (text)
|
508
473
|
bufput(ob, text->data, text->size);
|
509
|
-
|
474
|
+
|
475
|
+
if (flags & MKD_TABLE_HEADER) {
|
476
|
+
BUFPUTSL(ob, "</th>\n");
|
477
|
+
} else {
|
478
|
+
BUFPUTSL(ob, "</td>\n");
|
479
|
+
}
|
510
480
|
}
|
511
481
|
|
512
482
|
static int
|
513
|
-
rndr_superscript(struct buf *ob, struct buf *text, void *opaque)
|
483
|
+
rndr_superscript(struct buf *ob, const struct buf *text, void *opaque)
|
514
484
|
{
|
515
485
|
if (!text || !text->size) return 0;
|
516
486
|
BUFPUTSL(ob, "<sup>");
|
@@ -520,35 +490,37 @@ rndr_superscript(struct buf *ob, struct buf *text, void *opaque)
|
|
520
490
|
}
|
521
491
|
|
522
492
|
static void
|
523
|
-
rndr_normal_text(struct buf *ob, struct buf *text, void *opaque)
|
493
|
+
rndr_normal_text(struct buf *ob, const struct buf *text, void *opaque)
|
524
494
|
{
|
525
495
|
if (text)
|
526
496
|
sdhtml_escape(ob, text->data, text->size);
|
527
497
|
}
|
528
498
|
|
529
499
|
static void
|
530
|
-
toc_header(struct buf *ob, struct buf *text, int level, void *opaque)
|
500
|
+
toc_header(struct buf *ob, const struct buf *text, int level, void *opaque)
|
531
501
|
{
|
532
502
|
struct html_renderopt *options = opaque;
|
533
503
|
|
534
|
-
|
535
|
-
|
536
|
-
BUFPUTSL(ob, "<li
|
537
|
-
|
538
|
-
|
539
|
-
}
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
504
|
+
if (level > options->toc_data.current_level) {
|
505
|
+
while (level > options->toc_data.current_level) {
|
506
|
+
BUFPUTSL(ob, "<ul>\n<li>\n");
|
507
|
+
options->toc_data.current_level++;
|
508
|
+
}
|
509
|
+
} else if (level < options->toc_data.current_level) {
|
510
|
+
BUFPUTSL(ob, "</li>\n");
|
511
|
+
while (level < options->toc_data.current_level) {
|
512
|
+
BUFPUTSL(ob, "</ul>\n</li>\n");
|
513
|
+
options->toc_data.current_level--;
|
514
|
+
}
|
515
|
+
BUFPUTSL(ob,"<li>\n");
|
516
|
+
} else {
|
517
|
+
BUFPUTSL(ob,"</li>\n<li>\n");
|
546
518
|
}
|
547
519
|
|
548
|
-
bufprintf(ob, "<
|
520
|
+
bufprintf(ob, "<a href=\"#toc_%d\">", options->toc_data.header_count++);
|
549
521
|
if (text)
|
550
522
|
bufput(ob, text->data, text->size);
|
551
|
-
BUFPUTSL(ob, "</a
|
523
|
+
BUFPUTSL(ob, "</a>\n");
|
552
524
|
}
|
553
525
|
|
554
526
|
static void
|
@@ -556,13 +528,10 @@ toc_finalize(struct buf *ob, void *opaque)
|
|
556
528
|
{
|
557
529
|
struct html_renderopt *options = opaque;
|
558
530
|
|
559
|
-
while (options->toc_data.current_level >
|
560
|
-
BUFPUTSL(ob, "</
|
531
|
+
while (options->toc_data.current_level > 0) {
|
532
|
+
BUFPUTSL(ob, "</li>\n</ul>\n");
|
561
533
|
options->toc_data.current_level--;
|
562
534
|
}
|
563
|
-
|
564
|
-
if (options->toc_data.current_level)
|
565
|
-
BUFPUTSL(ob, "</ul>\n");
|
566
535
|
}
|
567
536
|
|
568
537
|
void
|
@@ -658,7 +627,4 @@ sdhtml_renderer(struct sd_callbacks *callbacks, struct html_renderopt *options,
|
|
658
627
|
|
659
628
|
if (render_flags & HTML_SKIP_HTML)
|
660
629
|
callbacks->blockhtml = NULL;
|
661
|
-
|
662
|
-
if (render_flags & HTML_GITHUB_BLOCKCODE)
|
663
|
-
callbacks->blockcode = rndr_blockcode_github;
|
664
630
|
}
|