| ︙ | | | ︙ | |
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
void markdown_to_html(
struct Blob *input_markdown,
struct Blob *output_title,
struct Blob *output_body);
#endif /* INTERFACE */
/* INTER_BLOCK -- skip a line between block level elements */
#define INTER_BLOCK(ob) \
do { if( blob_size(ob)>0 ) blob_append_char(ob, '\n'); } while (0)
/* BLOB_APPEND_LITERAL -- append a string literal to a blob */
#define BLOB_APPEND_LITERAL(blob, literal) \
|
>
>
>
>
>
>
>
>
>
|
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
void markdown_to_html(
struct Blob *input_markdown,
struct Blob *output_title,
struct Blob *output_body);
#endif /* INTERFACE */
/*
** An instance of the following structure is passed through the
** "opaque" pointer.
*/
typedef struct MarkdownToHtml MarkdownToHtml;
struct MarkdownToHtml {
Blob *output_title; /* Store the title here */
};
/* INTER_BLOCK -- skip a line between block level elements */
#define INTER_BLOCK(ob) \
do { if( blob_size(ob)>0 ) blob_append_char(ob, '\n'); } while (0)
/* BLOB_APPEND_LITERAL -- append a string literal to a blob */
#define BLOB_APPEND_LITERAL(blob, literal) \
|
| ︙ | | | ︙ | |
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
INTER_BLOCK(ob);
BLOB_APPEND_LITERAL(ob, "</div>\n");
}
static void html_blockhtml(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
|
|
|
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
INTER_BLOCK(ob);
BLOB_APPEND_LITERAL(ob, "</div>\n");
}
static void html_blockhtml(struct Blob *ob, struct Blob *text, void *opaque){
char *data = blob_buffer(text);
size_t size = blob_size(text);
Blob *title = ((MarkdownToHtml*)opaque)->output_title;
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
|
| ︙ | | | ︙ | |
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
static void html_header(
struct Blob *ob,
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);
|
|
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
static void html_header(
struct Blob *ob,
struct Blob *text,
int level,
void *opaque
){
struct Blob *title = ((MarkdownToHtml*)opaque)->output_title;
/* 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);
|
| ︙ | | | ︙ | |
567
568
569
570
571
572
573
574
575
576
577
578
|
0, /* entity */
html_normal_text,
/* misc. parameters */
"*_", /* emph_chars */
0 /* opaque */
};
html_renderer.opaque = output_title;
if( output_title ) blob_reset(output_title);
blob_reset(output_body);
markdown(output_body, input_markdown, &html_renderer);
}
|
>
>
>
|
|
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
|
0, /* entity */
html_normal_text,
/* misc. parameters */
"*_", /* emph_chars */
0 /* opaque */
};
MarkdownToHtml context;
memset(&context, 0, sizeof(context));
context.output_title = output_title;
html_renderer.opaque = &context;
if( output_title ) blob_reset(output_title);
blob_reset(output_body);
markdown(output_body, input_markdown, &html_renderer);
}
|