Fossil SCM
New option of 'wiki-use-html' which causes the wiki system to use HTML as it's markup language. i.e. do not interfeer with what was entered.
Commit
cf3809cc71ffc9557bd60829a19eb30b6254ad42
Parent
c16017374e4318a…
2 files changed
+13
+36
-4
+13
| --- src/setup.c | ||
| +++ src/setup.c | ||
| @@ -930,10 +930,23 @@ | ||
| 930 | 930 | @ <blockquote>%h(g.zBaseURL)/home</blockquote> |
| 931 | 931 | @ |
| 932 | 932 | @ <p>The default "/home" page displays a Wiki page with the same name |
| 933 | 933 | @ as the Project Name specified above. Some sites prefer to redirect |
| 934 | 934 | @ to a documentation page (ex: "/doc/tip/index.wiki") or to "/timeline".</p> |
| 935 | + @ <hr /> | |
| 936 | + onoff_attribute("Use HTML as wiki markup language", | |
| 937 | + "wiki-use-html", "wiki-use-html", 0); | |
| 938 | + @ <p>Use HTML as the wiki markup language. Wiki links will still be parsed but | |
| 939 | + @ all other wiki formatting will be ignored. This option is helpful if you have | |
| 940 | + @ chosen to use a rich HTML editor for wiki markup such as TinyMCE.</p> | |
| 941 | + @ <p><strong>CAUTION:</strong> when | |
| 942 | + @ enabling, <i>all</i> HTML tags and attributes are accepted in the wiki. | |
| 943 | + @ No sanitization is done. This means that it is very possible for malicious | |
| 944 | + @ users to inject dangerous HTML, CSS and JavaScript code into your wiki.</p> | |
| 945 | + @ <p>This should <strong>only</strong> be enabled when wiki editing is limited | |
| 946 | + @ to trusted users. It should <strong>not</strong> be used on a publically | |
| 947 | + @ editable wiki.</p> | |
| 935 | 948 | @ <hr /> |
| 936 | 949 | @ <p><input type="submit" name="submit" value="Apply Changes"></p> |
| 937 | 950 | @ </form> |
| 938 | 951 | db_end_transaction(0); |
| 939 | 952 | style_footer(); |
| 940 | 953 |
| --- src/setup.c | |
| +++ src/setup.c | |
| @@ -930,10 +930,23 @@ | |
| 930 | @ <blockquote>%h(g.zBaseURL)/home</blockquote> |
| 931 | @ |
| 932 | @ <p>The default "/home" page displays a Wiki page with the same name |
| 933 | @ as the Project Name specified above. Some sites prefer to redirect |
| 934 | @ to a documentation page (ex: "/doc/tip/index.wiki") or to "/timeline".</p> |
| 935 | @ <hr /> |
| 936 | @ <p><input type="submit" name="submit" value="Apply Changes"></p> |
| 937 | @ </form> |
| 938 | db_end_transaction(0); |
| 939 | style_footer(); |
| 940 |
| --- src/setup.c | |
| +++ src/setup.c | |
| @@ -930,10 +930,23 @@ | |
| 930 | @ <blockquote>%h(g.zBaseURL)/home</blockquote> |
| 931 | @ |
| 932 | @ <p>The default "/home" page displays a Wiki page with the same name |
| 933 | @ as the Project Name specified above. Some sites prefer to redirect |
| 934 | @ to a documentation page (ex: "/doc/tip/index.wiki") or to "/timeline".</p> |
| 935 | @ <hr /> |
| 936 | onoff_attribute("Use HTML as wiki markup language", |
| 937 | "wiki-use-html", "wiki-use-html", 0); |
| 938 | @ <p>Use HTML as the wiki markup language. Wiki links will still be parsed but |
| 939 | @ all other wiki formatting will be ignored. This option is helpful if you have |
| 940 | @ chosen to use a rich HTML editor for wiki markup such as TinyMCE.</p> |
| 941 | @ <p><strong>CAUTION:</strong> when |
| 942 | @ enabling, <i>all</i> HTML tags and attributes are accepted in the wiki. |
| 943 | @ No sanitization is done. This means that it is very possible for malicious |
| 944 | @ users to inject dangerous HTML, CSS and JavaScript code into your wiki.</p> |
| 945 | @ <p>This should <strong>only</strong> be enabled when wiki editing is limited |
| 946 | @ to trusted users. It should <strong>not</strong> be used on a publically |
| 947 | @ editable wiki.</p> |
| 948 | @ <hr /> |
| 949 | @ <p><input type="submit" name="submit" value="Apply Changes"></p> |
| 950 | @ </form> |
| 951 | db_end_transaction(0); |
| 952 | style_footer(); |
| 953 |
+36
-4
| --- src/wikiformat.c | ||
| +++ src/wikiformat.c | ||
| @@ -333,11 +333,12 @@ | ||
| 333 | 333 | #define TOKEN_NEWLINE 5 /* A single "\n" */ |
| 334 | 334 | #define TOKEN_BUL_LI 6 /* " * " */ |
| 335 | 335 | #define TOKEN_NUM_LI 7 /* " # " */ |
| 336 | 336 | #define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */ |
| 337 | 337 | #define TOKEN_INDENT 9 /* " " */ |
| 338 | -#define TOKEN_TEXT 10 /* None of the above */ | |
| 338 | +#define TOKEN_RAW 10 /* Output exactly (used when wiki-use-html==1) */ | |
| 339 | +#define TOKEN_TEXT 11 /* None of the above */ | |
| 339 | 340 | |
| 340 | 341 | /* |
| 341 | 342 | ** State flags |
| 342 | 343 | */ |
| 343 | 344 | #define AT_NEWLINE 0x001 /* At start of a line */ |
| @@ -344,10 +345,11 @@ | ||
| 344 | 345 | #define AT_PARAGRAPH 0x002 /* At start of a paragraph */ |
| 345 | 346 | #define ALLOW_WIKI 0x004 /* Allow wiki markup */ |
| 346 | 347 | #define FONT_MARKUP_ONLY 0x008 /* Only allow MUTYPE_FONT markup */ |
| 347 | 348 | #define INLINE_MARKUP_ONLY 0x010 /* Allow only "inline" markup */ |
| 348 | 349 | #define IN_LIST 0x020 /* Within wiki <ul> or <ol> */ |
| 350 | +#define WIKI_USE_HTML 0x040 /* wiki-use-html option = on */ | |
| 349 | 351 | |
| 350 | 352 | /* |
| 351 | 353 | ** Current state of the rendering engine |
| 352 | 354 | */ |
| 353 | 355 | typedef struct Renderer Renderer; |
| @@ -546,16 +548,17 @@ | ||
| 546 | 548 | }else{ |
| 547 | 549 | return 0; |
| 548 | 550 | } |
| 549 | 551 | } |
| 550 | 552 | |
| 551 | - | |
| 552 | 553 | /* |
| 554 | +** Get the next wiki token. | |
| 555 | +** | |
| 553 | 556 | ** z points to the start of a token. Return the number of |
| 554 | 557 | ** characters in that token. Write the token type into *pTokenType. |
| 555 | 558 | */ |
| 556 | -static int nextToken(const char *z, Renderer *p, int *pTokenType){ | |
| 559 | +static int nextWikiToken(const char *z, Renderer *p, int *pTokenType){ | |
| 557 | 560 | int n; |
| 558 | 561 | if( z[0]=='<' ){ |
| 559 | 562 | n = markupLength(z); |
| 560 | 563 | if( n>0 ){ |
| 561 | 564 | *pTokenType = TOKEN_MARKUP; |
| @@ -610,10 +613,27 @@ | ||
| 610 | 613 | } |
| 611 | 614 | } |
| 612 | 615 | *pTokenType = TOKEN_TEXT; |
| 613 | 616 | return 1 + textLength(z+1, p->state & ALLOW_WIKI); |
| 614 | 617 | } |
| 618 | + | |
| 619 | +/* | |
| 620 | +** Parse only Wiki links, return everything else as TOKEN_RAW. | |
| 621 | +** | |
| 622 | +** z points to the start of a token. Return the number of | |
| 623 | +** characters in that token. Write the token type into *pTokenType. | |
| 624 | +*/ | |
| 625 | + | |
| 626 | +static int nextRawToken(const char *z, Renderer *p, int *pTokenType){ | |
| 627 | + int n; | |
| 628 | + if( z[0]=='[' && (n = linkLength(z))>0 ){ | |
| 629 | + *pTokenType = TOKEN_LINK; | |
| 630 | + return n; | |
| 631 | + } | |
| 632 | + *pTokenType = TOKEN_RAW; | |
| 633 | + return 1 + textLength(z+1, p->state); | |
| 634 | +} | |
| 615 | 635 | |
| 616 | 636 | /* |
| 617 | 637 | ** A single markup is parsed into an instance of the following |
| 618 | 638 | ** structure. |
| 619 | 639 | */ |
| @@ -1039,13 +1059,18 @@ | ||
| 1039 | 1059 | static void wiki_render(Renderer *p, char *z){ |
| 1040 | 1060 | int tokenType; |
| 1041 | 1061 | ParsedMarkup markup; |
| 1042 | 1062 | int n; |
| 1043 | 1063 | int inlineOnly = (p->state & INLINE_MARKUP_ONLY)!=0; |
| 1064 | + int wikiUseHtml = (p->state & WIKI_USE_HTML)!=0; | |
| 1044 | 1065 | |
| 1045 | 1066 | while( z[0] ){ |
| 1046 | - n = nextToken(z, p, &tokenType); | |
| 1067 | + if( wikiUseHtml ){ | |
| 1068 | + n = nextRawToken(z, p, &tokenType); | |
| 1069 | + }else{ | |
| 1070 | + n = nextWikiToken(z, p, &tokenType); | |
| 1071 | + } | |
| 1047 | 1072 | p->state &= ~(AT_NEWLINE|AT_PARAGRAPH); |
| 1048 | 1073 | switch( tokenType ){ |
| 1049 | 1074 | case TOKEN_PARAGRAPH: { |
| 1050 | 1075 | if( inlineOnly ){ |
| 1051 | 1076 | /* blob_append(p->pOut, " ¶ ", -1); */ |
| @@ -1176,10 +1201,14 @@ | ||
| 1176 | 1201 | } |
| 1177 | 1202 | case TOKEN_TEXT: { |
| 1178 | 1203 | startAutoParagraph(p); |
| 1179 | 1204 | blob_append(p->pOut, z, n); |
| 1180 | 1205 | break; |
| 1206 | + } | |
| 1207 | + case TOKEN_RAW: { | |
| 1208 | + blob_append(p->pOut, z, n); | |
| 1209 | + break; | |
| 1181 | 1210 | } |
| 1182 | 1211 | case TOKEN_MARKUP: { |
| 1183 | 1212 | const char *zId; |
| 1184 | 1213 | int iDiv; |
| 1185 | 1214 | parseMarkup(&markup, z); |
| @@ -1349,10 +1378,13 @@ | ||
| 1349 | 1378 | } |
| 1350 | 1379 | if( flags & WIKI_INLINE ){ |
| 1351 | 1380 | renderer.wantAutoParagraph = 0; |
| 1352 | 1381 | }else{ |
| 1353 | 1382 | renderer.wantAutoParagraph = 1; |
| 1383 | + } | |
| 1384 | + if( db_get_int("wiki-use-html", 0) ){ | |
| 1385 | + renderer.state |= WIKI_USE_HTML; | |
| 1354 | 1386 | } |
| 1355 | 1387 | if( pOut ){ |
| 1356 | 1388 | renderer.pOut = pOut; |
| 1357 | 1389 | }else{ |
| 1358 | 1390 | renderer.pOut = cgi_output_blob(); |
| 1359 | 1391 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -333,11 +333,12 @@ | |
| 333 | #define TOKEN_NEWLINE 5 /* A single "\n" */ |
| 334 | #define TOKEN_BUL_LI 6 /* " * " */ |
| 335 | #define TOKEN_NUM_LI 7 /* " # " */ |
| 336 | #define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */ |
| 337 | #define TOKEN_INDENT 9 /* " " */ |
| 338 | #define TOKEN_TEXT 10 /* None of the above */ |
| 339 | |
| 340 | /* |
| 341 | ** State flags |
| 342 | */ |
| 343 | #define AT_NEWLINE 0x001 /* At start of a line */ |
| @@ -344,10 +345,11 @@ | |
| 344 | #define AT_PARAGRAPH 0x002 /* At start of a paragraph */ |
| 345 | #define ALLOW_WIKI 0x004 /* Allow wiki markup */ |
| 346 | #define FONT_MARKUP_ONLY 0x008 /* Only allow MUTYPE_FONT markup */ |
| 347 | #define INLINE_MARKUP_ONLY 0x010 /* Allow only "inline" markup */ |
| 348 | #define IN_LIST 0x020 /* Within wiki <ul> or <ol> */ |
| 349 | |
| 350 | /* |
| 351 | ** Current state of the rendering engine |
| 352 | */ |
| 353 | typedef struct Renderer Renderer; |
| @@ -546,16 +548,17 @@ | |
| 546 | }else{ |
| 547 | return 0; |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | |
| 552 | /* |
| 553 | ** z points to the start of a token. Return the number of |
| 554 | ** characters in that token. Write the token type into *pTokenType. |
| 555 | */ |
| 556 | static int nextToken(const char *z, Renderer *p, int *pTokenType){ |
| 557 | int n; |
| 558 | if( z[0]=='<' ){ |
| 559 | n = markupLength(z); |
| 560 | if( n>0 ){ |
| 561 | *pTokenType = TOKEN_MARKUP; |
| @@ -610,10 +613,27 @@ | |
| 610 | } |
| 611 | } |
| 612 | *pTokenType = TOKEN_TEXT; |
| 613 | return 1 + textLength(z+1, p->state & ALLOW_WIKI); |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | ** A single markup is parsed into an instance of the following |
| 618 | ** structure. |
| 619 | */ |
| @@ -1039,13 +1059,18 @@ | |
| 1039 | static void wiki_render(Renderer *p, char *z){ |
| 1040 | int tokenType; |
| 1041 | ParsedMarkup markup; |
| 1042 | int n; |
| 1043 | int inlineOnly = (p->state & INLINE_MARKUP_ONLY)!=0; |
| 1044 | |
| 1045 | while( z[0] ){ |
| 1046 | n = nextToken(z, p, &tokenType); |
| 1047 | p->state &= ~(AT_NEWLINE|AT_PARAGRAPH); |
| 1048 | switch( tokenType ){ |
| 1049 | case TOKEN_PARAGRAPH: { |
| 1050 | if( inlineOnly ){ |
| 1051 | /* blob_append(p->pOut, " ¶ ", -1); */ |
| @@ -1176,10 +1201,14 @@ | |
| 1176 | } |
| 1177 | case TOKEN_TEXT: { |
| 1178 | startAutoParagraph(p); |
| 1179 | blob_append(p->pOut, z, n); |
| 1180 | break; |
| 1181 | } |
| 1182 | case TOKEN_MARKUP: { |
| 1183 | const char *zId; |
| 1184 | int iDiv; |
| 1185 | parseMarkup(&markup, z); |
| @@ -1349,10 +1378,13 @@ | |
| 1349 | } |
| 1350 | if( flags & WIKI_INLINE ){ |
| 1351 | renderer.wantAutoParagraph = 0; |
| 1352 | }else{ |
| 1353 | renderer.wantAutoParagraph = 1; |
| 1354 | } |
| 1355 | if( pOut ){ |
| 1356 | renderer.pOut = pOut; |
| 1357 | }else{ |
| 1358 | renderer.pOut = cgi_output_blob(); |
| 1359 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -333,11 +333,12 @@ | |
| 333 | #define TOKEN_NEWLINE 5 /* A single "\n" */ |
| 334 | #define TOKEN_BUL_LI 6 /* " * " */ |
| 335 | #define TOKEN_NUM_LI 7 /* " # " */ |
| 336 | #define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */ |
| 337 | #define TOKEN_INDENT 9 /* " " */ |
| 338 | #define TOKEN_RAW 10 /* Output exactly (used when wiki-use-html==1) */ |
| 339 | #define TOKEN_TEXT 11 /* None of the above */ |
| 340 | |
| 341 | /* |
| 342 | ** State flags |
| 343 | */ |
| 344 | #define AT_NEWLINE 0x001 /* At start of a line */ |
| @@ -344,10 +345,11 @@ | |
| 345 | #define AT_PARAGRAPH 0x002 /* At start of a paragraph */ |
| 346 | #define ALLOW_WIKI 0x004 /* Allow wiki markup */ |
| 347 | #define FONT_MARKUP_ONLY 0x008 /* Only allow MUTYPE_FONT markup */ |
| 348 | #define INLINE_MARKUP_ONLY 0x010 /* Allow only "inline" markup */ |
| 349 | #define IN_LIST 0x020 /* Within wiki <ul> or <ol> */ |
| 350 | #define WIKI_USE_HTML 0x040 /* wiki-use-html option = on */ |
| 351 | |
| 352 | /* |
| 353 | ** Current state of the rendering engine |
| 354 | */ |
| 355 | typedef struct Renderer Renderer; |
| @@ -546,16 +548,17 @@ | |
| 548 | }else{ |
| 549 | return 0; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | /* |
| 554 | ** Get the next wiki token. |
| 555 | ** |
| 556 | ** z points to the start of a token. Return the number of |
| 557 | ** characters in that token. Write the token type into *pTokenType. |
| 558 | */ |
| 559 | static int nextWikiToken(const char *z, Renderer *p, int *pTokenType){ |
| 560 | int n; |
| 561 | if( z[0]=='<' ){ |
| 562 | n = markupLength(z); |
| 563 | if( n>0 ){ |
| 564 | *pTokenType = TOKEN_MARKUP; |
| @@ -610,10 +613,27 @@ | |
| 613 | } |
| 614 | } |
| 615 | *pTokenType = TOKEN_TEXT; |
| 616 | return 1 + textLength(z+1, p->state & ALLOW_WIKI); |
| 617 | } |
| 618 | |
| 619 | /* |
| 620 | ** Parse only Wiki links, return everything else as TOKEN_RAW. |
| 621 | ** |
| 622 | ** z points to the start of a token. Return the number of |
| 623 | ** characters in that token. Write the token type into *pTokenType. |
| 624 | */ |
| 625 | |
| 626 | static int nextRawToken(const char *z, Renderer *p, int *pTokenType){ |
| 627 | int n; |
| 628 | if( z[0]=='[' && (n = linkLength(z))>0 ){ |
| 629 | *pTokenType = TOKEN_LINK; |
| 630 | return n; |
| 631 | } |
| 632 | *pTokenType = TOKEN_RAW; |
| 633 | return 1 + textLength(z+1, p->state); |
| 634 | } |
| 635 | |
| 636 | /* |
| 637 | ** A single markup is parsed into an instance of the following |
| 638 | ** structure. |
| 639 | */ |
| @@ -1039,13 +1059,18 @@ | |
| 1059 | static void wiki_render(Renderer *p, char *z){ |
| 1060 | int tokenType; |
| 1061 | ParsedMarkup markup; |
| 1062 | int n; |
| 1063 | int inlineOnly = (p->state & INLINE_MARKUP_ONLY)!=0; |
| 1064 | int wikiUseHtml = (p->state & WIKI_USE_HTML)!=0; |
| 1065 | |
| 1066 | while( z[0] ){ |
| 1067 | if( wikiUseHtml ){ |
| 1068 | n = nextRawToken(z, p, &tokenType); |
| 1069 | }else{ |
| 1070 | n = nextWikiToken(z, p, &tokenType); |
| 1071 | } |
| 1072 | p->state &= ~(AT_NEWLINE|AT_PARAGRAPH); |
| 1073 | switch( tokenType ){ |
| 1074 | case TOKEN_PARAGRAPH: { |
| 1075 | if( inlineOnly ){ |
| 1076 | /* blob_append(p->pOut, " ¶ ", -1); */ |
| @@ -1176,10 +1201,14 @@ | |
| 1201 | } |
| 1202 | case TOKEN_TEXT: { |
| 1203 | startAutoParagraph(p); |
| 1204 | blob_append(p->pOut, z, n); |
| 1205 | break; |
| 1206 | } |
| 1207 | case TOKEN_RAW: { |
| 1208 | blob_append(p->pOut, z, n); |
| 1209 | break; |
| 1210 | } |
| 1211 | case TOKEN_MARKUP: { |
| 1212 | const char *zId; |
| 1213 | int iDiv; |
| 1214 | parseMarkup(&markup, z); |
| @@ -1349,10 +1378,13 @@ | |
| 1378 | } |
| 1379 | if( flags & WIKI_INLINE ){ |
| 1380 | renderer.wantAutoParagraph = 0; |
| 1381 | }else{ |
| 1382 | renderer.wantAutoParagraph = 1; |
| 1383 | } |
| 1384 | if( db_get_int("wiki-use-html", 0) ){ |
| 1385 | renderer.state |= WIKI_USE_HTML; |
| 1386 | } |
| 1387 | if( pOut ){ |
| 1388 | renderer.pOut = pOut; |
| 1389 | }else{ |
| 1390 | renderer.pOut = cgi_output_blob(); |
| 1391 |