1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
|
wiki_convert(&in, &out, flags);
blob_write_to_file(&out, "-");
}
/*
** COMMAND: test-markdown-render
**
** Usage: %fossil test-markdown-render FILE
**
** Render markdown in FILE as HTML on stdout.
*/
void test_markdown_render(void){
Blob in, out;
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
verify_all_options();
if( g.argc!=3 ) usage("FILE");
blob_zero(&out);
blob_read_from_file(&in, g.argv[2], ExtFILE);
markdown_to_html(&in, 0, &out);
blob_write_to_file(&out, "-");
blob_reset(&in);
blob_reset(&out);
}
/*
** Search for a <title>...</title> at the beginning of a wiki page.
** Return true (nonzero) if a title is found. Return zero if there is
** not title.
**
|
|
>
>
>
>
>
>
>
|
|
|
>
>
>
|
|
|
|
>
|
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
|
wiki_convert(&in, &out, flags);
blob_write_to_file(&out, "-");
}
/*
** COMMAND: test-markdown-render
**
** Usage: %fossil test-markdown-render FILE ...
**
** Render markdown in FILE as HTML on stdout.
** Options:
**
** --safe Do "safe-html" rendering.
*/
void test_markdown_render(void){
Blob in, out;
int i;
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
if( find_option("safe",0,0)!=0 ){
safe_html_enable(1);
}
verify_all_options();
for(i=2; i<g.argc; i++){
blob_zero(&out);
blob_read_from_file(&in, g.argv[i], ExtFILE);
if( g.argc>3 ){
fossil_print("<!------ %h ------->\n", g.argv[i]);
}
markdown_to_html(&in, 0, &out);
blob_write_to_file(&out, "-");
blob_reset(&in);
blob_reset(&out);
}
}
/*
** Search for a <title>...</title> at the beginning of a wiki page.
** Return true (nonzero) if a title is found. Return zero if there is
** not title.
**
|
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
|
if( e==eEnd || (aMarkup[e].iType & MUTYPE_Nested)!=0 ){
blob_appendf(pBlob, "</%s>", aMarkup[e].zName);
}
}while( e!=eEnd && p->n>0 );
}
/*
** Append HTML text to a Blob object. The appended text is modified
** changed in the following ways:
**
** 1. Omit any elements that are not on the AllowedMarkup list.
**
** 2. Omit any attributes that are not on the AllowedMarkup list.
**
** 3. Omit any surplus close-tags. (This prevents a surplus </div>
** or </body> or similar element from interferring with formatting
** of the outer context in which the HTML is being inserted.)
**
** 4. Insert additional close-tags as necessary so that any
** tag in the input that needs a close-tag has one. (This prevents
** the inserted HTML from messing up the formatting of subsequent
** sections of the document into which it is being inserted.)
**
** The input must be writable. Temporary changes may be made to the
** input, but the input is restored to its original state prior to
** returning. If zHtml[nHtml] is not a zero character, then a zero
** might be written in that position temporarily, but that slot will
** also be restored before this routine returns.
*/
void safe_html_append(Blob *pBlob, char *zHtml, int nHtml){
char cLast;
int i, j, n;
HtmlTagStack s;
ParsedMarkup markup;
if( nHtml<=0 ) return;
cLast = zHtml[nHtml];
zHtml[nHtml] = 0;
html_tagstack_init(&s);
i = 0;
while( i<nHtml ){
if( zHtml[i]=='<' ){
|
>
>
>
>
>
>
>
>
>
>
|
>
>
|
<
<
|
>
>
>
|
|
>
|
|
|
|
|
>
>
>
>
|
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
|
if( e==eEnd || (aMarkup[e].iType & MUTYPE_Nested)!=0 ){
blob_appendf(pBlob, "</%s>", aMarkup[e].zName);
}
}while( e!=eEnd && p->n>0 );
}
/*
** Enable or disable the "safe-html" feature. When enabled, the
** HTML generated by Markdown is adjusted so that it cannot cause
** problems when embedded in a larger document.
*/
static int safeHtml = 0;
void safe_html_enable(int v){
safeHtml = v;
}
/*
** Append HTML text to a Blob object.
**
** If safe-html is enabled then the appended text is modified
** changed in the following ways:
**
** 1. Omit any elements that are not on the AllowedMarkup list.
**
** 2. Omit any attributes that are not on the AllowedMarkup list.
**
** 3. Omit any surplus close-tags.
**
** 4. Insert additional close-tags as necessary so that any
** tag in the input that needs a close-tag has one.
**
** This modifications are intended to make the generated HTML safe
** to be embedded in a larger HTML document, such that the embedded
** HTML has no influence on the formatting and operation of the
** larger document.
**
** When safe-html is eanbled, the input to this routine must be writable.
* Temporary changes may be made to the input, but the input is restored
** to its original state prior to returning. If zHtml[nHtml] is not a
** zero character, then a zero might be written in that position
** temporarily, but that slot will also be restored before this routine
** returns.
*/
void safe_html_append(Blob *pBlob, char *zHtml, int nHtml){
char cLast;
int i, j, n;
HtmlTagStack s;
ParsedMarkup markup;
if( nHtml<=0 ) return;
if( !safeHtml ){
blob_append(pBlob, zHtml, nHtml);
return;
}
cLast = zHtml[nHtml];
zHtml[nHtml] = 0;
html_tagstack_init(&s);
i = 0;
while( i<nHtml ){
if( zHtml[i]=='<' ){
|