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.

jeremy_c 2010-01-13 09:35 trunk
Commit cf3809cc71ffc9557bd60829a19eb30b6254ad42
2 files changed +13 +36 -4
+13
--- src/setup.c
+++ src/setup.c
@@ -930,10 +930,23 @@
930930
@ <blockquote>%h(g.zBaseURL)/home</blockquote>
931931
@
932932
@ <p>The default "/home" page displays a Wiki page with the same name
933933
@ as the Project Name specified above. Some sites prefer to redirect
934934
@ 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>
935948
@ <hr />
936949
@ <p><input type="submit" name="submit" value="Apply Changes"></p>
937950
@ </form>
938951
db_end_transaction(0);
939952
style_footer();
940953
--- 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 @@
333333
#define TOKEN_NEWLINE 5 /* A single "\n" */
334334
#define TOKEN_BUL_LI 6 /* " * " */
335335
#define TOKEN_NUM_LI 7 /* " # " */
336336
#define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */
337337
#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 */
339340
340341
/*
341342
** State flags
342343
*/
343344
#define AT_NEWLINE 0x001 /* At start of a line */
@@ -344,10 +345,11 @@
344345
#define AT_PARAGRAPH 0x002 /* At start of a paragraph */
345346
#define ALLOW_WIKI 0x004 /* Allow wiki markup */
346347
#define FONT_MARKUP_ONLY 0x008 /* Only allow MUTYPE_FONT markup */
347348
#define INLINE_MARKUP_ONLY 0x010 /* Allow only "inline" markup */
348349
#define IN_LIST 0x020 /* Within wiki <ul> or <ol> */
350
+#define WIKI_USE_HTML 0x040 /* wiki-use-html option = on */
349351
350352
/*
351353
** Current state of the rendering engine
352354
*/
353355
typedef struct Renderer Renderer;
@@ -546,16 +548,17 @@
546548
}else{
547549
return 0;
548550
}
549551
}
550552
551
-
552553
/*
554
+** Get the next wiki token.
555
+**
553556
** z points to the start of a token. Return the number of
554557
** characters in that token. Write the token type into *pTokenType.
555558
*/
556
-static int nextToken(const char *z, Renderer *p, int *pTokenType){
559
+static int nextWikiToken(const char *z, Renderer *p, int *pTokenType){
557560
int n;
558561
if( z[0]=='<' ){
559562
n = markupLength(z);
560563
if( n>0 ){
561564
*pTokenType = TOKEN_MARKUP;
@@ -610,10 +613,27 @@
610613
}
611614
}
612615
*pTokenType = TOKEN_TEXT;
613616
return 1 + textLength(z+1, p->state & ALLOW_WIKI);
614617
}
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
+}
615635
616636
/*
617637
** A single markup is parsed into an instance of the following
618638
** structure.
619639
*/
@@ -1039,13 +1059,18 @@
10391059
static void wiki_render(Renderer *p, char *z){
10401060
int tokenType;
10411061
ParsedMarkup markup;
10421062
int n;
10431063
int inlineOnly = (p->state & INLINE_MARKUP_ONLY)!=0;
1064
+ int wikiUseHtml = (p->state & WIKI_USE_HTML)!=0;
10441065
10451066
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
+ }
10471072
p->state &= ~(AT_NEWLINE|AT_PARAGRAPH);
10481073
switch( tokenType ){
10491074
case TOKEN_PARAGRAPH: {
10501075
if( inlineOnly ){
10511076
/* blob_append(p->pOut, " &para; ", -1); */
@@ -1176,10 +1201,14 @@
11761201
}
11771202
case TOKEN_TEXT: {
11781203
startAutoParagraph(p);
11791204
blob_append(p->pOut, z, n);
11801205
break;
1206
+ }
1207
+ case TOKEN_RAW: {
1208
+ blob_append(p->pOut, z, n);
1209
+ break;
11811210
}
11821211
case TOKEN_MARKUP: {
11831212
const char *zId;
11841213
int iDiv;
11851214
parseMarkup(&markup, z);
@@ -1349,10 +1378,13 @@
13491378
}
13501379
if( flags & WIKI_INLINE ){
13511380
renderer.wantAutoParagraph = 0;
13521381
}else{
13531382
renderer.wantAutoParagraph = 1;
1383
+ }
1384
+ if( db_get_int("wiki-use-html", 0) ){
1385
+ renderer.state |= WIKI_USE_HTML;
13541386
}
13551387
if( pOut ){
13561388
renderer.pOut = pOut;
13571389
}else{
13581390
renderer.pOut = cgi_output_blob();
13591391
--- 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, " &para; ", -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, " &para; ", -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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button