| ︙ | | | ︙ | |
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
static void html_epilog(struct Blob *ob, void *opaque){
INTER_BLOCK(ob);
BLOB_APPEND_LITERAL(ob, "</div>\n");
}
static void html_raw_block(struct Blob *ob, struct Blob *text, void *opaque){
char *data = blob_buffer(text);
size_t first = 0, size = blob_size(text);
INTER_BLOCK(ob);
while( first<size && data[first]=='\n' ) first++;
while( size>first && data[size-1]=='\n' ) size--;
blob_append(ob, data+first, size-first);
BLOB_APPEND_LITERAL(ob, "\n");
}
static void html_blockcode(struct Blob *ob, struct Blob *text, void *opaque){
INTER_BLOCK(ob);
BLOB_APPEND_LITERAL(ob, "<pre><code>");
html_escape(ob, blob_buffer(text), blob_size(text));
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
<
<
|
|
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
static void html_epilog(struct Blob *ob, void *opaque){
INTER_BLOCK(ob);
BLOB_APPEND_LITERAL(ob, "</div>\n");
}
static void html_raw_block(struct Blob *ob, struct Blob *text, void *opaque){
char *data = blob_buffer(text);
size_t size = blob_size(text);
Blob *title = (Blob*)opaque;
while( size>0 && fossil_isspace(data[0]) ){ data++; size--; }
while( size>0 && fossil_isspace(data[size-1]) ){ size--; }
/* If the first raw block is an <h1> element, then use it as the title. */
if( blob_size(ob)<=PROLOG_SIZE
&& size>9
&& title!=0
&& sqlite3_strnicmp("<h1",data,3)==0
&& sqlite3_strnicmp("</h1>", &data[size-5],5)==0
){
int nTag = htmlTagLength(data);
blob_append(title, data+nTag, size - nTag - 5);
return;
}
INTER_BLOCK(ob);
blob_append(ob, data, size);
BLOB_APPEND_LITERAL(ob, "\n");
}
static void html_blockcode(struct Blob *ob, struct Blob *text, void *opaque){
INTER_BLOCK(ob);
BLOB_APPEND_LITERAL(ob, "<pre><code>");
html_escape(ob, blob_buffer(text), blob_size(text));
|
| ︙ | | | ︙ | |
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
struct Blob *text,
int level,
void *opaque
){
struct Blob *title = opaque;
/* The first header at the beginning of a text is considered as
* a title and not output. */
if( blob_size(ob)<=PROLOG_SIZE && blob_size(title)==0 ){
BLOB_APPEND_BLOB(title, text);
}
INTER_BLOCK(ob);
blob_appendf(ob, "<h%d>", level);
BLOB_APPEND_BLOB(ob, text);
blob_appendf(ob, "</h%d>", level);
}
|
|
>
|
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
struct Blob *text,
int level,
void *opaque
){
struct Blob *title = opaque;
/* The first header at the beginning of a text is considered as
* a title and not output. */
if( blob_size(ob)<=PROLOG_SIZE && title!=0 && blob_size(title)==0 ){
BLOB_APPEND_BLOB(title, text);
return;
}
INTER_BLOCK(ob);
blob_appendf(ob, "<h%d>", level);
BLOB_APPEND_BLOB(ob, text);
blob_appendf(ob, "</h%d>", level);
}
|
| ︙ | | | ︙ | |
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
}
/* HTML span tags */
static int html_raw_span(struct Blob *ob, struct Blob *text, void *opaque){
BLOB_APPEND_BLOB(ob, text);
return 1;
}
static int html_autolink(
struct Blob *ob,
struct Blob *link,
|
>
|
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
}
/* HTML span tags */
static int html_raw_span(struct Blob *ob, struct Blob *text, void *opaque){
/* If the document begins with a <h1> markup, take that as the header. */
BLOB_APPEND_BLOB(ob, text);
return 1;
}
static int html_autolink(
struct Blob *ob,
struct Blob *link,
|
| ︙ | | | ︙ | |
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
|
}
static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){
html_escape(ob, blob_buffer(text), blob_size(text));
}
void markdown_to_html(
struct Blob *input_markdown,
struct Blob *output_title,
struct Blob *output_body
){
struct mkd_renderer html_renderer = {
/* prolog and epilog */
html_prolog,
html_epilog,
/* block level elements */
|
|
>
>
>
>
>
|
|
|
|
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
}
static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){
html_escape(ob, blob_buffer(text), blob_size(text));
}
/*
** Convert markdown into HTML.
**
** The document title is placed in output_title if not NULL. Or if
** output_title is NULL, the document title appears in the body.
*/
void markdown_to_html(
struct Blob *input_markdown, /* Markdown content to be rendered */
struct Blob *output_title, /* Put title here. May be NULL */
struct Blob *output_body /* Put document body here. */
){
struct mkd_renderer html_renderer = {
/* prolog and epilog */
html_prolog,
html_epilog,
/* block level elements */
|
| ︙ | | | ︙ | |
415
416
417
418
419
420
421
422
423
424
425
|
/* misc. parameters */
64, /* maximum stack */
"*_", /* emphasis characters */
0 /* opaque data */
};
html_renderer.opaque = output_title;
blob_reset(output_title);
blob_reset(output_body);
markdown(output_body, input_markdown, &html_renderer);
}
|
|
|
434
435
436
437
438
439
440
441
442
443
444
|
/* misc. parameters */
64, /* maximum stack */
"*_", /* emphasis characters */
0 /* opaque data */
};
html_renderer.opaque = output_title;
if( output_title ) blob_reset(output_title);
blob_reset(output_body);
markdown(output_body, input_markdown, &html_renderer);
}
|