Fossil SCM
Do not duplicate markdown titles in the title of the page and in the body of the document.
Commit
d407c3842116e163fce36055c3998e08731fc6f9
Parent
cc7f4df41743ffc…
2 files changed
+15
-7
+1
-8
+15
-7
| --- src/markdown_html.c | ||
| +++ src/markdown_html.c | ||
| @@ -100,21 +100,23 @@ | ||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | static void html_raw_block(struct Blob *ob, struct Blob *text, void *opaque){ |
| 103 | 103 | char *data = blob_buffer(text); |
| 104 | 104 | size_t size = blob_size(text); |
| 105 | + Blob *title = (Blob*)opaque; | |
| 105 | 106 | while( size>0 && fossil_isspace(data[0]) ){ data++; size--; } |
| 106 | 107 | while( size>0 && fossil_isspace(data[size-1]) ){ size--; } |
| 107 | 108 | /* If the first raw block is an <h1> element, then use it as the title. */ |
| 108 | 109 | if( blob_size(ob)<=PROLOG_SIZE |
| 109 | 110 | && size>9 |
| 111 | + && title!=0 | |
| 110 | 112 | && sqlite3_strnicmp("<h1",data,3)==0 |
| 111 | 113 | && sqlite3_strnicmp("</h1>", &data[size-5],5)==0 |
| 112 | 114 | ){ |
| 113 | - Blob *title = (Blob*)opaque; | |
| 114 | 115 | int nTag = htmlTagLength(data); |
| 115 | 116 | blob_append(title, data+nTag, size - nTag - 5); |
| 117 | + return; | |
| 116 | 118 | } |
| 117 | 119 | INTER_BLOCK(ob); |
| 118 | 120 | blob_append(ob, data, size); |
| 119 | 121 | BLOB_APPEND_LITERAL(ob, "\n"); |
| 120 | 122 | } |
| @@ -140,12 +142,13 @@ | ||
| 140 | 142 | void *opaque |
| 141 | 143 | ){ |
| 142 | 144 | struct Blob *title = opaque; |
| 143 | 145 | /* The first header at the beginning of a text is considered as |
| 144 | 146 | * a title and not output. */ |
| 145 | - if( blob_size(ob)<=PROLOG_SIZE && blob_size(title)==0 ){ | |
| 147 | + if( blob_size(ob)<=PROLOG_SIZE && title!=0 && blob_size(title)==0 ){ | |
| 146 | 148 | BLOB_APPEND_BLOB(title, text); |
| 149 | + return; | |
| 147 | 150 | } |
| 148 | 151 | INTER_BLOCK(ob); |
| 149 | 152 | blob_appendf(ob, "<h%d>", level); |
| 150 | 153 | BLOB_APPEND_BLOB(ob, text); |
| 151 | 154 | blob_appendf(ob, "</h%d>", level); |
| @@ -381,15 +384,20 @@ | ||
| 381 | 384 | |
| 382 | 385 | static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){ |
| 383 | 386 | html_escape(ob, blob_buffer(text), blob_size(text)); |
| 384 | 387 | } |
| 385 | 388 | |
| 386 | - | |
| 389 | +/* | |
| 390 | +** Convert markdown into HTML. | |
| 391 | +** | |
| 392 | +** The document title is placed in output_title if not NULL. Or if | |
| 393 | +** output_title is NULL, the document title appears in the body. | |
| 394 | +*/ | |
| 387 | 395 | void markdown_to_html( |
| 388 | - struct Blob *input_markdown, | |
| 389 | - struct Blob *output_title, | |
| 390 | - struct Blob *output_body | |
| 396 | + struct Blob *input_markdown, /* Markdown content to be rendered */ | |
| 397 | + struct Blob *output_title, /* Put title here. May be NULL */ | |
| 398 | + struct Blob *output_body /* Put document body here. */ | |
| 391 | 399 | ){ |
| 392 | 400 | struct mkd_renderer html_renderer = { |
| 393 | 401 | /* prolog and epilog */ |
| 394 | 402 | html_prolog, |
| 395 | 403 | html_epilog, |
| @@ -426,9 +434,9 @@ | ||
| 426 | 434 | 64, /* maximum stack */ |
| 427 | 435 | "*_", /* emphasis characters */ |
| 428 | 436 | 0 /* opaque data */ |
| 429 | 437 | }; |
| 430 | 438 | html_renderer.opaque = output_title; |
| 431 | - blob_reset(output_title); | |
| 439 | + if( output_title ) blob_reset(output_title); | |
| 432 | 440 | blob_reset(output_body); |
| 433 | 441 | markdown(output_body, input_markdown, &html_renderer); |
| 434 | 442 | } |
| 435 | 443 |
| --- src/markdown_html.c | |
| +++ src/markdown_html.c | |
| @@ -100,21 +100,23 @@ | |
| 100 | } |
| 101 | |
| 102 | static void html_raw_block(struct Blob *ob, struct Blob *text, void *opaque){ |
| 103 | char *data = blob_buffer(text); |
| 104 | size_t size = blob_size(text); |
| 105 | while( size>0 && fossil_isspace(data[0]) ){ data++; size--; } |
| 106 | while( size>0 && fossil_isspace(data[size-1]) ){ size--; } |
| 107 | /* If the first raw block is an <h1> element, then use it as the title. */ |
| 108 | if( blob_size(ob)<=PROLOG_SIZE |
| 109 | && size>9 |
| 110 | && sqlite3_strnicmp("<h1",data,3)==0 |
| 111 | && sqlite3_strnicmp("</h1>", &data[size-5],5)==0 |
| 112 | ){ |
| 113 | Blob *title = (Blob*)opaque; |
| 114 | int nTag = htmlTagLength(data); |
| 115 | blob_append(title, data+nTag, size - nTag - 5); |
| 116 | } |
| 117 | INTER_BLOCK(ob); |
| 118 | blob_append(ob, data, size); |
| 119 | BLOB_APPEND_LITERAL(ob, "\n"); |
| 120 | } |
| @@ -140,12 +142,13 @@ | |
| 140 | void *opaque |
| 141 | ){ |
| 142 | struct Blob *title = opaque; |
| 143 | /* The first header at the beginning of a text is considered as |
| 144 | * a title and not output. */ |
| 145 | if( blob_size(ob)<=PROLOG_SIZE && blob_size(title)==0 ){ |
| 146 | BLOB_APPEND_BLOB(title, text); |
| 147 | } |
| 148 | INTER_BLOCK(ob); |
| 149 | blob_appendf(ob, "<h%d>", level); |
| 150 | BLOB_APPEND_BLOB(ob, text); |
| 151 | blob_appendf(ob, "</h%d>", level); |
| @@ -381,15 +384,20 @@ | |
| 381 | |
| 382 | static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){ |
| 383 | html_escape(ob, blob_buffer(text), blob_size(text)); |
| 384 | } |
| 385 | |
| 386 | |
| 387 | void markdown_to_html( |
| 388 | struct Blob *input_markdown, |
| 389 | struct Blob *output_title, |
| 390 | struct Blob *output_body |
| 391 | ){ |
| 392 | struct mkd_renderer html_renderer = { |
| 393 | /* prolog and epilog */ |
| 394 | html_prolog, |
| 395 | html_epilog, |
| @@ -426,9 +434,9 @@ | |
| 426 | 64, /* maximum stack */ |
| 427 | "*_", /* emphasis characters */ |
| 428 | 0 /* opaque data */ |
| 429 | }; |
| 430 | html_renderer.opaque = output_title; |
| 431 | blob_reset(output_title); |
| 432 | blob_reset(output_body); |
| 433 | markdown(output_body, input_markdown, &html_renderer); |
| 434 | } |
| 435 |
| --- src/markdown_html.c | |
| +++ src/markdown_html.c | |
| @@ -100,21 +100,23 @@ | |
| 100 | } |
| 101 | |
| 102 | static void html_raw_block(struct Blob *ob, struct Blob *text, void *opaque){ |
| 103 | char *data = blob_buffer(text); |
| 104 | size_t size = blob_size(text); |
| 105 | Blob *title = (Blob*)opaque; |
| 106 | while( size>0 && fossil_isspace(data[0]) ){ data++; size--; } |
| 107 | while( size>0 && fossil_isspace(data[size-1]) ){ size--; } |
| 108 | /* If the first raw block is an <h1> element, then use it as the title. */ |
| 109 | if( blob_size(ob)<=PROLOG_SIZE |
| 110 | && size>9 |
| 111 | && title!=0 |
| 112 | && sqlite3_strnicmp("<h1",data,3)==0 |
| 113 | && sqlite3_strnicmp("</h1>", &data[size-5],5)==0 |
| 114 | ){ |
| 115 | int nTag = htmlTagLength(data); |
| 116 | blob_append(title, data+nTag, size - nTag - 5); |
| 117 | return; |
| 118 | } |
| 119 | INTER_BLOCK(ob); |
| 120 | blob_append(ob, data, size); |
| 121 | BLOB_APPEND_LITERAL(ob, "\n"); |
| 122 | } |
| @@ -140,12 +142,13 @@ | |
| 142 | void *opaque |
| 143 | ){ |
| 144 | struct Blob *title = opaque; |
| 145 | /* The first header at the beginning of a text is considered as |
| 146 | * a title and not output. */ |
| 147 | if( blob_size(ob)<=PROLOG_SIZE && title!=0 && blob_size(title)==0 ){ |
| 148 | BLOB_APPEND_BLOB(title, text); |
| 149 | return; |
| 150 | } |
| 151 | INTER_BLOCK(ob); |
| 152 | blob_appendf(ob, "<h%d>", level); |
| 153 | BLOB_APPEND_BLOB(ob, text); |
| 154 | blob_appendf(ob, "</h%d>", level); |
| @@ -381,15 +384,20 @@ | |
| 384 | |
| 385 | static void html_normal_text(struct Blob *ob, struct Blob *text, void *opaque){ |
| 386 | html_escape(ob, blob_buffer(text), blob_size(text)); |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | ** Convert markdown into HTML. |
| 391 | ** |
| 392 | ** The document title is placed in output_title if not NULL. Or if |
| 393 | ** output_title is NULL, the document title appears in the body. |
| 394 | */ |
| 395 | void markdown_to_html( |
| 396 | struct Blob *input_markdown, /* Markdown content to be rendered */ |
| 397 | struct Blob *output_title, /* Put title here. May be NULL */ |
| 398 | struct Blob *output_body /* Put document body here. */ |
| 399 | ){ |
| 400 | struct mkd_renderer html_renderer = { |
| 401 | /* prolog and epilog */ |
| 402 | html_prolog, |
| 403 | html_epilog, |
| @@ -426,9 +434,9 @@ | |
| 434 | 64, /* maximum stack */ |
| 435 | "*_", /* emphasis characters */ |
| 436 | 0 /* opaque data */ |
| 437 | }; |
| 438 | html_renderer.opaque = output_title; |
| 439 | if( output_title ) blob_reset(output_title); |
| 440 | blob_reset(output_body); |
| 441 | markdown(output_body, input_markdown, &html_renderer); |
| 442 | } |
| 443 |
+1
-8
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -147,20 +147,13 @@ | ||
| 147 | 147 | */ |
| 148 | 148 | void wiki_render_by_mimetype(Blob *pWiki, const char *zMimetype){ |
| 149 | 149 | if( zMimetype==0 || fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0 ){ |
| 150 | 150 | wiki_convert(pWiki, 0, 0); |
| 151 | 151 | }else if( fossil_strcmp(zMimetype, "text/x-markdown")==0 ){ |
| 152 | - Blob title = BLOB_INITIALIZER; | |
| 153 | 152 | Blob tail = BLOB_INITIALIZER; |
| 154 | - markdown_to_html(pWiki, &title, &tail); | |
| 155 | -#if 0 | |
| 156 | - if( blob_size(&title)>0 ){ | |
| 157 | - @ <h1>%s(blob_str(&title))</h1> | |
| 158 | - } | |
| 159 | -#endif | |
| 153 | + markdown_to_html(pWiki, 0, &tail); | |
| 160 | 154 | @ %s(blob_str(&tail)) |
| 161 | - blob_reset(&title); | |
| 162 | 155 | blob_reset(&tail); |
| 163 | 156 | }else{ |
| 164 | 157 | @ <pre> |
| 165 | 158 | @ %h(blob_str(pWiki)) |
| 166 | 159 | @ </pre> |
| 167 | 160 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -147,20 +147,13 @@ | |
| 147 | */ |
| 148 | void wiki_render_by_mimetype(Blob *pWiki, const char *zMimetype){ |
| 149 | if( zMimetype==0 || fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0 ){ |
| 150 | wiki_convert(pWiki, 0, 0); |
| 151 | }else if( fossil_strcmp(zMimetype, "text/x-markdown")==0 ){ |
| 152 | Blob title = BLOB_INITIALIZER; |
| 153 | Blob tail = BLOB_INITIALIZER; |
| 154 | markdown_to_html(pWiki, &title, &tail); |
| 155 | #if 0 |
| 156 | if( blob_size(&title)>0 ){ |
| 157 | @ <h1>%s(blob_str(&title))</h1> |
| 158 | } |
| 159 | #endif |
| 160 | @ %s(blob_str(&tail)) |
| 161 | blob_reset(&title); |
| 162 | blob_reset(&tail); |
| 163 | }else{ |
| 164 | @ <pre> |
| 165 | @ %h(blob_str(pWiki)) |
| 166 | @ </pre> |
| 167 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -147,20 +147,13 @@ | |
| 147 | */ |
| 148 | void wiki_render_by_mimetype(Blob *pWiki, const char *zMimetype){ |
| 149 | if( zMimetype==0 || fossil_strcmp(zMimetype, "text/x-fossil-wiki")==0 ){ |
| 150 | wiki_convert(pWiki, 0, 0); |
| 151 | }else if( fossil_strcmp(zMimetype, "text/x-markdown")==0 ){ |
| 152 | Blob tail = BLOB_INITIALIZER; |
| 153 | markdown_to_html(pWiki, 0, &tail); |
| 154 | @ %s(blob_str(&tail)) |
| 155 | blob_reset(&tail); |
| 156 | }else{ |
| 157 | @ <pre> |
| 158 | @ %h(blob_str(pWiki)) |
| 159 | @ </pre> |
| 160 |