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
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'date'
|
2
2
|
require 'rake/clean'
|
3
|
+
require 'rake/extensiontask'
|
3
4
|
require 'digest/md5'
|
4
5
|
|
5
6
|
task :default => :test
|
@@ -8,31 +9,7 @@ task :default => :test
|
|
8
9
|
# Ruby Extension
|
9
10
|
# ==========================================================
|
10
11
|
|
11
|
-
|
12
|
-
RUBYDIGEST = Digest::MD5.hexdigest(`#{RUBY} --version`)
|
13
|
-
|
14
|
-
file "ext/ruby-#{RUBYDIGEST}" do |f|
|
15
|
-
rm_f FileList["ext/ruby-*"]
|
16
|
-
touch f.name
|
17
|
-
end
|
18
|
-
CLEAN.include "ext/ruby-*"
|
19
|
-
|
20
|
-
file 'ext/Makefile' => FileList['ext/*.{c,h,rb}', "ext/ruby-#{RUBYDIGEST}"] do
|
21
|
-
chdir('ext') { ruby 'extconf.rb' }
|
22
|
-
end
|
23
|
-
CLEAN.include 'ext/Makefile', 'ext/mkmf.log'
|
24
|
-
|
25
|
-
file "ext/redcarpet.#{DLEXT}" => FileList["ext/Makefile"] do |f|
|
26
|
-
sh 'cd ext && make clean && make && rm -rf conftest.dSYM'
|
27
|
-
end
|
28
|
-
CLEAN.include 'ext/*.{o,bundle,so,dll}'
|
29
|
-
|
30
|
-
file "lib/redcarpet.#{DLEXT}" => "ext/redcarpet.#{DLEXT}" do |f|
|
31
|
-
cp f.prerequisites, "lib/", :preserve => true
|
32
|
-
end
|
33
|
-
|
34
|
-
desc 'Build the redcarpet extension'
|
35
|
-
task :build => "lib/redcarpet.#{DLEXT}"
|
12
|
+
Rake::ExtensionTask.new('redcarpet')
|
36
13
|
|
37
14
|
# ==========================================================
|
38
15
|
# Testing
|
@@ -43,10 +20,10 @@ Rake::TestTask.new('test:unit') do |t|
|
|
43
20
|
t.test_files = FileList['test/*_test.rb']
|
44
21
|
t.ruby_opts += ['-rubygems'] if defined? Gem
|
45
22
|
end
|
46
|
-
task 'test:unit' => [:
|
23
|
+
task 'test:unit' => [:compile]
|
47
24
|
|
48
25
|
desc 'Run conformance tests (MARKDOWN_TEST_VER=1.0)'
|
49
|
-
task 'test:conformance' => [:
|
26
|
+
task 'test:conformance' => [:compile] do |t|
|
50
27
|
script = "#{pwd}/bin/redcarpet"
|
51
28
|
test_version = ENV['MARKDOWN_TEST_VER'] || '1.0.3'
|
52
29
|
lib_dir = "#{pwd}/lib"
|
@@ -56,13 +33,13 @@ task 'test:conformance' => [:build] do |t|
|
|
56
33
|
end
|
57
34
|
|
58
35
|
desc 'Run version 1.0 conformance suite'
|
59
|
-
task 'test:conformance:1.0' => [:
|
36
|
+
task 'test:conformance:1.0' => [:compile] do |t|
|
60
37
|
ENV['MARKDOWN_TEST_VER'] = '1.0'
|
61
38
|
Rake::Task['test:conformance'].invoke
|
62
39
|
end
|
63
40
|
|
64
41
|
desc 'Run 1.0.3 conformance suite'
|
65
|
-
task 'test:conformance:1.0.3' => [:
|
42
|
+
task 'test:conformance:1.0.3' => [:compile] do |t|
|
66
43
|
ENV['MARKDOWN_TEST_VER'] = '1.0.3'
|
67
44
|
Rake::Task['test:conformance'].invoke
|
68
45
|
end
|
@@ -140,10 +117,11 @@ task :gather => 'upskirt/src/markdown.h' do |t|
|
|
140
117
|
FileList[
|
141
118
|
'upskirt/src/{markdown,buffer,array}.h',
|
142
119
|
'upskirt/src/{markdown,buffer,array}.c',
|
143
|
-
'upskirt/render/
|
144
|
-
'upskirt/render/
|
120
|
+
'upskirt/render/html.c',
|
121
|
+
'upskirt/render/html_smartypants.c',
|
122
|
+
'upskirt/render/html.h',
|
145
123
|
]
|
146
|
-
cp files, 'ext/',
|
124
|
+
cp files, 'ext/redcarpet/',
|
147
125
|
:preserve => true,
|
148
126
|
:verbose => true
|
149
127
|
end
|
File without changes
|
File without changes
|
@@ -23,6 +23,7 @@
|
|
23
23
|
*/
|
24
24
|
|
25
25
|
#define BUFFER_STDARG
|
26
|
+
#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) //16mb
|
26
27
|
|
27
28
|
#include "buffer.h"
|
28
29
|
|
@@ -147,6 +148,25 @@ bufdup(const struct buf *src, size_t dupunit) {
|
|
147
148
|
#endif
|
148
149
|
return ret; }
|
149
150
|
|
151
|
+
/* bufgrow • increasing the allocated size to the given value */
|
152
|
+
int
|
153
|
+
bufgrow(struct buf *buf, size_t neosz) {
|
154
|
+
size_t neoasz;
|
155
|
+
void *neodata;
|
156
|
+
if (!buf || !buf->unit || neosz > BUFFER_MAX_ALLOC_SIZE) return 0;
|
157
|
+
if (buf->asize >= neosz) return 1;
|
158
|
+
neoasz = buf->asize + buf->unit;
|
159
|
+
while (neoasz < neosz) neoasz += buf->unit;
|
160
|
+
neodata = realloc(buf->data, neoasz);
|
161
|
+
if (!neodata) return 0;
|
162
|
+
#ifdef BUFFER_STATS
|
163
|
+
buffer_stat_alloc_bytes += (neoasz - buf->asize);
|
164
|
+
#endif
|
165
|
+
buf->data = neodata;
|
166
|
+
buf->asize = neoasz;
|
167
|
+
return 1; }
|
168
|
+
|
169
|
+
|
150
170
|
/* bufnew • allocation of a new buffer */
|
151
171
|
struct buf *
|
152
172
|
bufnew(size_t unit) {
|
@@ -196,6 +216,14 @@ bufputs(struct buf *buf, const char *str) {
|
|
196
216
|
bufput(buf, str, strlen (str)); }
|
197
217
|
|
198
218
|
|
219
|
+
/* bufputc • appends a single char to a buffer */
|
220
|
+
void
|
221
|
+
bufputc(struct buf *buf, char c) {
|
222
|
+
if (!buf || !bufgrow(buf, buf->size + 1)) return;
|
223
|
+
buf->data[buf->size] = c;
|
224
|
+
buf->size += 1; }
|
225
|
+
|
226
|
+
|
199
227
|
/* bufrelease • decrease the reference count and free the buffer if needed */
|
200
228
|
void
|
201
229
|
bufrelease(struct buf *buf) {
|
@@ -21,7 +21,6 @@
|
|
21
21
|
|
22
22
|
#include <stddef.h>
|
23
23
|
|
24
|
-
#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) /* 16mb */
|
25
24
|
|
26
25
|
/********************
|
27
26
|
* TYPE DEFINITIONS *
|
@@ -82,6 +81,10 @@ struct buf *
|
|
82
81
|
bufdup(const struct buf *, size_t)
|
83
82
|
__attribute__ ((malloc));
|
84
83
|
|
84
|
+
/* bufgrow • increasing the allocated size to the given value */
|
85
|
+
int
|
86
|
+
bufgrow(struct buf *, size_t);
|
87
|
+
|
85
88
|
/* bufnew • allocation of a new buffer */
|
86
89
|
struct buf *
|
87
90
|
bufnew(size_t)
|
@@ -104,6 +107,10 @@ bufput(struct buf *, const void*, size_t);
|
|
104
107
|
void
|
105
108
|
bufputs(struct buf *, const char*);
|
106
109
|
|
110
|
+
/* bufputc • appends a single char to a buffer */
|
111
|
+
void
|
112
|
+
bufputc(struct buf *, char);
|
113
|
+
|
107
114
|
/* bufrelease • decrease the reference count and free the buffer if needed */
|
108
115
|
void
|
109
116
|
bufrelease(struct buf *);
|
@@ -135,33 +142,6 @@ vbufprintf(struct buf *, const char*, va_list);
|
|
135
142
|
|
136
143
|
#endif /* def BUFFER_STDARG */
|
137
144
|
|
138
|
-
#include <stdlib.h>
|
139
|
-
|
140
|
-
/* bufgrow • increasing the allocated size to the given value */
|
141
|
-
static inline int
|
142
|
-
bufgrow(struct buf *buf, size_t neosz) {
|
143
|
-
size_t neoasz;
|
144
|
-
void *neodata;
|
145
|
-
if (!buf || !buf->unit || neosz > BUFFER_MAX_ALLOC_SIZE) return 0;
|
146
|
-
if (buf->asize >= neosz) return 1;
|
147
|
-
neoasz = buf->asize + buf->unit;
|
148
|
-
while (neoasz < neosz) neoasz += buf->unit;
|
149
|
-
neodata = realloc(buf->data, neoasz);
|
150
|
-
if (!neodata) return 0;
|
151
|
-
#ifdef BUFFER_STATS
|
152
|
-
buffer_stat_alloc_bytes += (neoasz - buf->asize);
|
153
|
-
#endif
|
154
|
-
buf->data = neodata;
|
155
|
-
buf->asize = neoasz;
|
156
|
-
return 1; }
|
157
|
-
|
158
|
-
/* bufputc • appends a single char to a buffer */
|
159
|
-
static inline void
|
160
|
-
bufputc(struct buf *buf, char c) {
|
161
|
-
if (!buf || !bufgrow(buf, buf->size + 1)) return;
|
162
|
-
buf->data[buf->size] = c;
|
163
|
-
buf->size += 1; }
|
164
|
-
|
165
145
|
#endif /* ndef LITHIUM_BUFFER_H */
|
166
146
|
|
167
147
|
/* vim: set filetype=c: */
|
File without changes
|
@@ -16,25 +16,21 @@
|
|
16
16
|
*/
|
17
17
|
|
18
18
|
#include "markdown.h"
|
19
|
-
#include "
|
19
|
+
#include "html.h"
|
20
20
|
|
21
21
|
#include <string.h>
|
22
22
|
#include <stdlib.h>
|
23
23
|
#include <stdio.h>
|
24
24
|
#include <ctype.h>
|
25
25
|
|
26
|
-
struct
|
26
|
+
struct html_renderopt {
|
27
27
|
struct {
|
28
28
|
int header_count;
|
29
29
|
int current_level;
|
30
30
|
} toc_data;
|
31
31
|
|
32
|
-
struct {
|
33
|
-
int in_squote;
|
34
|
-
int in_dquote;
|
35
|
-
} quotes;
|
36
|
-
|
37
32
|
unsigned int flags;
|
33
|
+
const char *close_tag;
|
38
34
|
};
|
39
35
|
|
40
36
|
static inline void
|
@@ -109,12 +105,12 @@ is_html_tag(struct buf *tag, const char *tagname)
|
|
109
105
|
static int
|
110
106
|
rndr_autolink(struct buf *ob, struct buf *link, enum mkd_autolink type, void *opaque)
|
111
107
|
{
|
112
|
-
struct
|
108
|
+
struct html_renderopt *options = opaque;
|
113
109
|
|
114
110
|
if (!link || !link->size)
|
115
111
|
return 0;
|
116
112
|
|
117
|
-
if ((options->flags &
|
113
|
+
if ((options->flags & HTML_SAFELINK) != 0 &&
|
118
114
|
!is_safe_link(link->data, link->size) &&
|
119
115
|
type != MKDA_EMAIL)
|
120
116
|
return 0;
|
@@ -277,12 +273,12 @@ rndr_emphasis(struct buf *ob, struct buf *text, void *opaque)
|
|
277
273
|
static void
|
278
274
|
rndr_header(struct buf *ob, struct buf *text, int level, void *opaque)
|
279
275
|
{
|
280
|
-
struct
|
276
|
+
struct html_renderopt *options = opaque;
|
281
277
|
|
282
278
|
if (ob->size)
|
283
279
|
bufputc(ob, '\n');
|
284
280
|
|
285
|
-
if (options->flags &
|
281
|
+
if (options->flags & HTML_TOC) {
|
286
282
|
bufprintf(ob, "<a name=\"toc_%d\"></a>", options->toc_data.header_count++);
|
287
283
|
}
|
288
284
|
|
@@ -294,9 +290,9 @@ rndr_header(struct buf *ob, struct buf *text, int level, void *opaque)
|
|
294
290
|
static int
|
295
291
|
rndr_link(struct buf *ob, struct buf *link, struct buf *title, struct buf *content, void *opaque)
|
296
292
|
{
|
297
|
-
struct
|
293
|
+
struct html_renderopt *options = opaque;
|
298
294
|
|
299
|
-
if ((options->flags &
|
295
|
+
if ((options->flags & HTML_SAFELINK) != 0 && !is_safe_link(link->data, link->size))
|
300
296
|
return 0;
|
301
297
|
|
302
298
|
BUFPUTSL(ob, "<a href=\"");
|
@@ -333,7 +329,7 @@ rndr_listitem(struct buf *ob, struct buf *text, int flags, void *opaque)
|
|
333
329
|
static void
|
334
330
|
rndr_paragraph(struct buf *ob, struct buf *text, void *opaque)
|
335
331
|
{
|
336
|
-
struct
|
332
|
+
struct html_renderopt *options = opaque;
|
337
333
|
size_t i = 0;
|
338
334
|
|
339
335
|
if (ob->size) bufputc(ob, '\n');
|
@@ -347,7 +343,7 @@ rndr_paragraph(struct buf *ob, struct buf *text, void *opaque)
|
|
347
343
|
return;
|
348
344
|
|
349
345
|
BUFPUTSL(ob, "<p>");
|
350
|
-
if (options->flags &
|
346
|
+
if (options->flags & HTML_HARD_WRAP) {
|
351
347
|
size_t org;
|
352
348
|
while (i < text->size) {
|
353
349
|
org = i;
|
@@ -360,17 +356,14 @@ rndr_paragraph(struct buf *ob, struct buf *text, void *opaque)
|
|
360
356
|
if (i >= text->size)
|
361
357
|
break;
|
362
358
|
|
363
|
-
BUFPUTSL(ob, "<br
|
359
|
+
BUFPUTSL(ob, "<br");
|
360
|
+
bufputs(ob, options->close_tag);
|
364
361
|
i++;
|
365
362
|
}
|
366
363
|
} else {
|
367
364
|
bufput(ob, &text->data[i], text->size - i);
|
368
365
|
}
|
369
366
|
BUFPUTSL(ob, "</p>\n");
|
370
|
-
|
371
|
-
/* Close any open quotes at the end of the paragraph */
|
372
|
-
options->quotes.in_squote = 0;
|
373
|
-
options->quotes.in_dquote = 0;
|
374
367
|
}
|
375
368
|
|
376
369
|
static void
|
@@ -398,21 +391,19 @@ rndr_triple_emphasis(struct buf *ob, struct buf *text, void *opaque)
|
|
398
391
|
return 1;
|
399
392
|
}
|
400
393
|
|
401
|
-
|
402
|
-
/**********************
|
403
|
-
* XHTML 1.0 RENDERER *
|
404
|
-
**********************/
|
405
|
-
|
406
394
|
static void
|
407
395
|
rndr_hrule(struct buf *ob, void *opaque)
|
408
396
|
{
|
397
|
+
struct html_renderopt *options = opaque;
|
409
398
|
if (ob->size) bufputc(ob, '\n');
|
410
|
-
BUFPUTSL(ob, "<hr
|
399
|
+
BUFPUTSL(ob, "<hr");
|
400
|
+
bufputs(ob, options->close_tag);
|
411
401
|
}
|
412
402
|
|
413
403
|
static int
|
414
404
|
rndr_image(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt, void *opaque)
|
415
405
|
{
|
406
|
+
struct html_renderopt *options = opaque;
|
416
407
|
if (!link || !link->size) return 0;
|
417
408
|
BUFPUTSL(ob, "<img src=\"");
|
418
409
|
attr_escape(ob, link->data, link->size);
|
@@ -422,32 +413,36 @@ rndr_image(struct buf *ob, struct buf *link, struct buf *title, struct buf *alt,
|
|
422
413
|
if (title && title->size) {
|
423
414
|
BUFPUTSL(ob, "\" title=\"");
|
424
415
|
attr_escape(ob, title->data, title->size); }
|
425
|
-
|
416
|
+
|
417
|
+
bufputc(ob, '"');
|
418
|
+
bufputs(ob, options->close_tag);
|
426
419
|
return 1;
|
427
420
|
}
|
428
421
|
|
429
422
|
static int
|
430
423
|
rndr_linebreak(struct buf *ob, void *opaque)
|
431
424
|
{
|
432
|
-
|
425
|
+
struct html_renderopt *options = opaque;
|
426
|
+
BUFPUTSL(ob, "<br");
|
427
|
+
bufputs(ob, options->close_tag);
|
433
428
|
return 1;
|
434
429
|
}
|
435
430
|
|
436
431
|
static int
|
437
432
|
rndr_raw_html(struct buf *ob, struct buf *text, void *opaque)
|
438
433
|
{
|
439
|
-
struct
|
434
|
+
struct html_renderopt *options = opaque;
|
440
435
|
|
441
|
-
if ((options->flags &
|
436
|
+
if ((options->flags & HTML_SKIP_HTML) != 0)
|
442
437
|
return 1;
|
443
438
|
|
444
|
-
if ((options->flags &
|
439
|
+
if ((options->flags & HTML_SKIP_STYLE) != 0 && is_html_tag(text, "style"))
|
445
440
|
return 1;
|
446
441
|
|
447
|
-
if ((options->flags &
|
442
|
+
if ((options->flags & HTML_SKIP_LINKS) != 0 && is_html_tag(text, "a"))
|
448
443
|
return 1;
|
449
444
|
|
450
|
-
if ((options->flags &
|
445
|
+
if ((options->flags & HTML_SKIP_IMAGES) != 0 && is_html_tag(text, "img"))
|
451
446
|
return 1;
|
452
447
|
|
453
448
|
bufput(ob, text->data, text->size);
|
@@ -504,92 +499,6 @@ rndr_tablecell(struct buf *ob, struct buf *text, int align, void *opaque)
|
|
504
499
|
BUFPUTSL(ob, "</td>");
|
505
500
|
}
|
506
501
|
|
507
|
-
static struct {
|
508
|
-
char c0;
|
509
|
-
const char *pattern;
|
510
|
-
const char *entity;
|
511
|
-
int skip;
|
512
|
-
} smartypants_subs[] = {
|
513
|
-
{ '\'', "'s>", "’", 0 },
|
514
|
-
{ '\'', "'t>", "’", 0 },
|
515
|
-
{ '\'', "'re>", "’", 0 },
|
516
|
-
{ '\'', "'ll>", "’", 0 },
|
517
|
-
{ '\'', "'ve>", "’", 0 },
|
518
|
-
{ '\'', "'m>", "’", 0 },
|
519
|
-
{ '\'', "'d>", "’", 0 },
|
520
|
-
{ '-', "--", "—", 1 },
|
521
|
-
{ '-', "<->", "–", 0 },
|
522
|
-
{ '.', "...", "…", 2 },
|
523
|
-
{ '.', ". . .", "…", 4 },
|
524
|
-
{ '(', "(c)", "©", 2 },
|
525
|
-
{ '(', "(r)", "®", 2 },
|
526
|
-
{ '(', "(tm)", "™", 3 },
|
527
|
-
{ '3', "<3/4>", "¾", 2 },
|
528
|
-
{ '3', "<3/4ths>", "¾", 2 },
|
529
|
-
{ '1', "<1/2>", "½", 2 },
|
530
|
-
{ '1', "<1/4>", "¼", 2 },
|
531
|
-
{ '1', "<1/4th>", "¼", 2 },
|
532
|
-
{ '&', "�", 0, 3 },
|
533
|
-
};
|
534
|
-
|
535
|
-
#define SUBS_COUNT (sizeof(smartypants_subs) / sizeof(smartypants_subs[0]))
|
536
|
-
|
537
|
-
static inline int
|
538
|
-
word_boundary(char c)
|
539
|
-
{
|
540
|
-
return isspace(c) || ispunct(c);
|
541
|
-
}
|
542
|
-
|
543
|
-
static int
|
544
|
-
smartypants_cmpsub(const struct buf *buf, size_t start, const char *prefix)
|
545
|
-
{
|
546
|
-
size_t i;
|
547
|
-
|
548
|
-
if (prefix[0] == '<') {
|
549
|
-
if (start == 0 || !word_boundary(buf->data[start - 1]))
|
550
|
-
return 0;
|
551
|
-
|
552
|
-
prefix++;
|
553
|
-
}
|
554
|
-
|
555
|
-
for (i = start; i < buf->size; ++i) {
|
556
|
-
char c, p;
|
557
|
-
|
558
|
-
c = tolower(buf->data[i]);
|
559
|
-
p = *prefix++;
|
560
|
-
|
561
|
-
if (p == 0)
|
562
|
-
return 1;
|
563
|
-
|
564
|
-
if (p == '>')
|
565
|
-
return word_boundary(c);
|
566
|
-
|
567
|
-
if (c != p)
|
568
|
-
return 0;
|
569
|
-
}
|
570
|
-
|
571
|
-
return (*prefix == '>');
|
572
|
-
}
|
573
|
-
|
574
|
-
static int
|
575
|
-
smartypants_quotes(struct buf *ob, struct buf *text, size_t i, int is_open)
|
576
|
-
{
|
577
|
-
char ent[8];
|
578
|
-
|
579
|
-
if (is_open && i + 1 < text->size && !word_boundary(text->data[i + 1]))
|
580
|
-
return 0;
|
581
|
-
|
582
|
-
if (!is_open && i > 0 && !word_boundary(text->data[i - 1]))
|
583
|
-
return 0;
|
584
|
-
|
585
|
-
snprintf(ent, sizeof(ent), "&%c%cquo;",
|
586
|
-
is_open ? 'r' : 'l',
|
587
|
-
text->data[i] == '\'' ? 's' : 'd');
|
588
|
-
|
589
|
-
bufputs(ob, ent);
|
590
|
-
return 1;
|
591
|
-
}
|
592
|
-
|
593
502
|
static void
|
594
503
|
rndr_normal_text(struct buf *ob, struct buf *text, void *opaque)
|
595
504
|
{
|
@@ -597,61 +506,10 @@ rndr_normal_text(struct buf *ob, struct buf *text, void *opaque)
|
|
597
506
|
attr_escape(ob, text->data, text->size);
|
598
507
|
}
|
599
508
|
|
600
|
-
static void
|
601
|
-
rndr_smartypants(struct buf *ob, struct buf *text, void *opaque)
|
602
|
-
{
|
603
|
-
struct xhtml_renderopt *options = opaque;
|
604
|
-
size_t i;
|
605
|
-
|
606
|
-
if (!text)
|
607
|
-
return;
|
608
|
-
|
609
|
-
for (i = 0; i < text->size; ++i) {
|
610
|
-
size_t sub;
|
611
|
-
char c = text->data[i];
|
612
|
-
|
613
|
-
for (sub = 0; sub < SUBS_COUNT; ++sub) {
|
614
|
-
if (c == smartypants_subs[sub].c0 &&
|
615
|
-
smartypants_cmpsub(text, i, smartypants_subs[sub].pattern)) {
|
616
|
-
|
617
|
-
if (smartypants_subs[sub].entity)
|
618
|
-
bufputs(ob, smartypants_subs[sub].entity);
|
619
|
-
|
620
|
-
i += smartypants_subs[sub].skip;
|
621
|
-
break;
|
622
|
-
}
|
623
|
-
}
|
624
|
-
|
625
|
-
if (sub < SUBS_COUNT)
|
626
|
-
continue;
|
627
|
-
|
628
|
-
switch (c) {
|
629
|
-
case '\"':
|
630
|
-
if (smartypants_quotes(ob, text, i, options->quotes.in_dquote)) {
|
631
|
-
options->quotes.in_dquote = !options->quotes.in_dquote;
|
632
|
-
continue;
|
633
|
-
}
|
634
|
-
break;
|
635
|
-
|
636
|
-
case '\'':
|
637
|
-
if (smartypants_quotes(ob, text, i, options->quotes.in_squote)) {
|
638
|
-
options->quotes.in_squote = !options->quotes.in_squote;
|
639
|
-
continue;
|
640
|
-
}
|
641
|
-
break;
|
642
|
-
}
|
643
|
-
|
644
|
-
/*
|
645
|
-
* Copy raw character
|
646
|
-
*/
|
647
|
-
put_scaped_char(ob, c);
|
648
|
-
}
|
649
|
-
}
|
650
|
-
|
651
509
|
static void
|
652
510
|
toc_header(struct buf *ob, struct buf *text, int level, void *opaque)
|
653
511
|
{
|
654
|
-
struct
|
512
|
+
struct html_renderopt *options = opaque;
|
655
513
|
|
656
514
|
if (level > options->toc_data.current_level) {
|
657
515
|
if (level > 1)
|
@@ -676,7 +534,7 @@ toc_header(struct buf *ob, struct buf *text, int level, void *opaque)
|
|
676
534
|
static void
|
677
535
|
toc_finalize(struct buf *ob, void *opaque)
|
678
536
|
{
|
679
|
-
struct
|
537
|
+
struct html_renderopt *options = opaque;
|
680
538
|
|
681
539
|
while (options->toc_data.current_level > 1) {
|
682
540
|
BUFPUTSL(ob, "</ul></li>\n");
|
@@ -688,7 +546,7 @@ toc_finalize(struct buf *ob, void *opaque)
|
|
688
546
|
}
|
689
547
|
|
690
548
|
void
|
691
|
-
|
549
|
+
upshtml_toc_renderer(struct mkd_renderer *renderer)
|
692
550
|
{
|
693
551
|
static const struct mkd_renderer toc_render = {
|
694
552
|
NULL,
|
@@ -723,17 +581,20 @@ ups_toc_renderer(struct mkd_renderer *renderer)
|
|
723
581
|
NULL
|
724
582
|
};
|
725
583
|
|
726
|
-
struct
|
727
|
-
options = calloc(1, sizeof(struct
|
728
|
-
options->flags =
|
584
|
+
struct html_renderopt *options;
|
585
|
+
options = calloc(1, sizeof(struct html_renderopt));
|
586
|
+
options->flags = HTML_TOC;
|
729
587
|
|
730
588
|
memcpy(renderer, &toc_render, sizeof(struct mkd_renderer));
|
731
589
|
renderer->opaque = options;
|
732
590
|
}
|
733
591
|
|
734
592
|
void
|
735
|
-
|
593
|
+
upshtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags)
|
736
594
|
{
|
595
|
+
static const char *xhtml_close = "/>\n";
|
596
|
+
static const char *html_close = ">\n";
|
597
|
+
|
737
598
|
static const struct mkd_renderer renderer_default = {
|
738
599
|
rndr_blockcode,
|
739
600
|
rndr_blockquote,
|
@@ -767,33 +628,31 @@ ups_xhtml_renderer(struct mkd_renderer *renderer, unsigned int render_flags)
|
|
767
628
|
NULL
|
768
629
|
};
|
769
630
|
|
770
|
-
struct
|
771
|
-
options = calloc(1, sizeof(struct
|
631
|
+
struct html_renderopt *options;
|
632
|
+
options = calloc(1, sizeof(struct html_renderopt));
|
772
633
|
options->flags = render_flags;
|
634
|
+
options->close_tag = (render_flags & HTML_USE_XHTML) ? xhtml_close : html_close;
|
773
635
|
|
774
636
|
memcpy(renderer, &renderer_default, sizeof(struct mkd_renderer));
|
775
637
|
renderer->opaque = options;
|
776
638
|
|
777
|
-
if (render_flags &
|
639
|
+
if (render_flags & HTML_SKIP_IMAGES)
|
778
640
|
renderer->image = NULL;
|
779
641
|
|
780
|
-
if (render_flags &
|
642
|
+
if (render_flags & HTML_SKIP_LINKS) {
|
781
643
|
renderer->link = NULL;
|
782
644
|
renderer->autolink = NULL;
|
783
645
|
}
|
784
646
|
|
785
|
-
if (render_flags &
|
647
|
+
if (render_flags & HTML_SKIP_HTML)
|
786
648
|
renderer->blockhtml = NULL;
|
787
649
|
|
788
|
-
if (render_flags &
|
789
|
-
renderer->normal_text = rndr_smartypants;
|
790
|
-
|
791
|
-
if (render_flags & XHTML_GITHUB_BLOCKCODE)
|
650
|
+
if (render_flags & HTML_GITHUB_BLOCKCODE)
|
792
651
|
renderer->blockcode = rndr_blockcode_github;
|
793
652
|
}
|
794
653
|
|
795
654
|
void
|
796
|
-
|
655
|
+
upshtml_free_renderer(struct mkd_renderer *renderer)
|
797
656
|
{
|
798
657
|
free(renderer->opaque);
|
799
658
|
}
|