Fossil SCM
Add support for <verbatim type="allow-links">
Commit
bf67db062dd3a20bd855549cf4023c64813b4674
Parent
4615bc8faf85010…
1 file changed
+36
-19
+36
-19
| --- src/wikiformat.c | ||
| +++ src/wikiformat.c | ||
| @@ -385,13 +385,14 @@ | ||
| 385 | 385 | ** State flags. Save the lower 16 bits for the WIKI_* flags. |
| 386 | 386 | */ |
| 387 | 387 | #define AT_NEWLINE 0x0010000 /* At start of a line */ |
| 388 | 388 | #define AT_PARAGRAPH 0x0020000 /* At start of a paragraph */ |
| 389 | 389 | #define ALLOW_WIKI 0x0040000 /* Allow wiki markup */ |
| 390 | -#define FONT_MARKUP_ONLY 0x0080000 /* Only allow MUTYPE_FONT markup */ | |
| 391 | -#define INLINE_MARKUP_ONLY 0x0100000 /* Allow only "inline" markup */ | |
| 392 | -#define IN_LIST 0x0200000 /* Within wiki <ul> or <ol> */ | |
| 390 | +#define ALLOW_LINKS 0x0080000 /* Allow [...] hyperlinks */ | |
| 391 | +#define FONT_MARKUP_ONLY 0x0100000 /* Only allow MUTYPE_FONT markup */ | |
| 392 | +#define INLINE_MARKUP_ONLY 0x0200000 /* Allow only "inline" markup */ | |
| 393 | +#define IN_LIST 0x0400000 /* Within wiki <ul> or <ol> */ | |
| 393 | 394 | |
| 394 | 395 | /* |
| 395 | 396 | ** Current state of the rendering engine |
| 396 | 397 | */ |
| 397 | 398 | typedef struct Renderer Renderer; |
| @@ -485,18 +486,27 @@ | ||
| 485 | 486 | ** < |
| 486 | 487 | ** & |
| 487 | 488 | ** \n |
| 488 | 489 | ** [ |
| 489 | 490 | ** |
| 490 | -** The "[" and "\n" are only considered interesting if the "useWiki" | |
| 491 | -** flag is set. | |
| 491 | +** The "[" is only considered if flags contain ALLOW_LINKS or ALLOW_WIKI. | |
| 492 | +** The "\n" is only considered interesting if the flags constains ALLOW_WIKI. | |
| 492 | 493 | */ |
| 493 | -static int textLength(const char *z, int useWiki){ | |
| 494 | +static int textLength(const char *z, int flags){ | |
| 494 | 495 | int n = 0; |
| 495 | - int c; | |
| 496 | - while( (c = z[0])!=0 && c!='<' && c!='&' && | |
| 497 | - (useWiki==0 || (c!='[' && c!='\n')) ){ | |
| 496 | + int c, x1, x2; | |
| 497 | + | |
| 498 | + if( flags & ALLOW_WIKI ){ | |
| 499 | + x1 = '['; | |
| 500 | + x2 = '\n'; | |
| 501 | + }else if( flags & ALLOW_LINKS ){ | |
| 502 | + x1 = '['; | |
| 503 | + x2 = 0; | |
| 504 | + }else{ | |
| 505 | + x1 = x2 = 0; | |
| 506 | + } | |
| 507 | + while( (c = z[0])!=0 && c!='<' && c!='&' && c!=x1 && c!=x2 ){ | |
| 498 | 508 | n++; |
| 499 | 509 | z++; |
| 500 | 510 | } |
| 501 | 511 | return n; |
| 502 | 512 | } |
| @@ -669,13 +679,16 @@ | ||
| 669 | 679 | } |
| 670 | 680 | if( z[0]=='[' && (n = linkLength(z))>0 ){ |
| 671 | 681 | *pTokenType = TOKEN_LINK; |
| 672 | 682 | return n; |
| 673 | 683 | } |
| 684 | + }else if( (p->state & ALLOW_LINKS)!=0 && z[0]=='[' && (n = linkLength(z))>0 ){ | |
| 685 | + *pTokenType = TOKEN_LINK; | |
| 686 | + return n; | |
| 674 | 687 | } |
| 675 | 688 | *pTokenType = TOKEN_TEXT; |
| 676 | - return 1 + textLength(z+1, p->state & ALLOW_WIKI); | |
| 689 | + return 1 + textLength(z+1, p->state); | |
| 677 | 690 | } |
| 678 | 691 | |
| 679 | 692 | /* |
| 680 | 693 | ** Parse only Wiki links, return everything else as TOKEN_RAW. |
| 681 | 694 | ** |
| @@ -1382,11 +1395,11 @@ | ||
| 1382 | 1395 | zDisplay = zTarget; |
| 1383 | 1396 | }else{ |
| 1384 | 1397 | while( fossil_isspace(*zDisplay) ) zDisplay++; |
| 1385 | 1398 | } |
| 1386 | 1399 | openHyperlink(p, zTarget, zClose, sizeof(zClose), zOrig); |
| 1387 | - if( linksOnly || zClose[0]==0 ){ | |
| 1400 | + if( linksOnly || zClose[0]==0 || p->inVerbatim ){ | |
| 1388 | 1401 | if( cS1 ) z[iS1] = cS1; |
| 1389 | 1402 | if( zClose[0]!=']' ){ |
| 1390 | 1403 | blob_appendf(p->pOut, "[%h]%s", zTarget, zClose); |
| 1391 | 1404 | }else{ |
| 1392 | 1405 | blob_appendf(p->pOut, "%h%s", zTarget, zClose); |
| @@ -1506,22 +1519,26 @@ | ||
| 1506 | 1519 | /* Enter <verbatim> processing. With verbatim enabled, all other |
| 1507 | 1520 | ** markup other than the corresponding end-tag with the same ID is |
| 1508 | 1521 | ** ignored. |
| 1509 | 1522 | */ |
| 1510 | 1523 | if( markup.iCode==MARKUP_VERBATIM ){ |
| 1511 | - int vAttrIdx, vAttrDidAppend=0; | |
| 1524 | + int ii, vAttrDidAppend=0; | |
| 1512 | 1525 | p->zVerbatimId = 0; |
| 1513 | 1526 | p->inVerbatim = 1; |
| 1514 | 1527 | p->preVerbState = p->state; |
| 1515 | 1528 | p->state &= ~ALLOW_WIKI; |
| 1516 | - for (vAttrIdx = 0; vAttrIdx < markup.nAttr; vAttrIdx++){ | |
| 1517 | - if( markup.aAttr[vAttrIdx].iACode == ATTR_ID ){ | |
| 1518 | - p->zVerbatimId = markup.aAttr[0].zValue; | |
| 1519 | - }else if( markup.aAttr[vAttrIdx].iACode == ATTR_TYPE ){ | |
| 1520 | - blob_appendf(p->pOut, "<pre name='code' class='%s'>", | |
| 1521 | - markup.aAttr[vAttrIdx].zValue); | |
| 1522 | - vAttrDidAppend=1; | |
| 1529 | + for(ii=0; ii<markup.nAttr; ii++){ | |
| 1530 | + if( markup.aAttr[ii].iACode == ATTR_ID ){ | |
| 1531 | + p->zVerbatimId = markup.aAttr[ii].zValue; | |
| 1532 | + }else if( markup.aAttr[ii].iACode == ATTR_TYPE ){ | |
| 1533 | + if( fossil_stricmp(markup.aAttr[ii].zValue, "allow-links")==0 ){ | |
| 1534 | + p->state |= ALLOW_LINKS; | |
| 1535 | + }else{ | |
| 1536 | + blob_appendf(p->pOut, "<pre name='code' class='%s'>", | |
| 1537 | + markup.aAttr[ii].zValue); | |
| 1538 | + vAttrDidAppend=1; | |
| 1539 | + } | |
| 1523 | 1540 | } |
| 1524 | 1541 | } |
| 1525 | 1542 | if( !vAttrDidAppend ) { |
| 1526 | 1543 | endAutoParagraph(p); |
| 1527 | 1544 | blob_append(p->pOut, "<pre class='verbatim'>",-1); |
| 1528 | 1545 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -385,13 +385,14 @@ | |
| 385 | ** State flags. Save the lower 16 bits for the WIKI_* flags. |
| 386 | */ |
| 387 | #define AT_NEWLINE 0x0010000 /* At start of a line */ |
| 388 | #define AT_PARAGRAPH 0x0020000 /* At start of a paragraph */ |
| 389 | #define ALLOW_WIKI 0x0040000 /* Allow wiki markup */ |
| 390 | #define FONT_MARKUP_ONLY 0x0080000 /* Only allow MUTYPE_FONT markup */ |
| 391 | #define INLINE_MARKUP_ONLY 0x0100000 /* Allow only "inline" markup */ |
| 392 | #define IN_LIST 0x0200000 /* Within wiki <ul> or <ol> */ |
| 393 | |
| 394 | /* |
| 395 | ** Current state of the rendering engine |
| 396 | */ |
| 397 | typedef struct Renderer Renderer; |
| @@ -485,18 +486,27 @@ | |
| 485 | ** < |
| 486 | ** & |
| 487 | ** \n |
| 488 | ** [ |
| 489 | ** |
| 490 | ** The "[" and "\n" are only considered interesting if the "useWiki" |
| 491 | ** flag is set. |
| 492 | */ |
| 493 | static int textLength(const char *z, int useWiki){ |
| 494 | int n = 0; |
| 495 | int c; |
| 496 | while( (c = z[0])!=0 && c!='<' && c!='&' && |
| 497 | (useWiki==0 || (c!='[' && c!='\n')) ){ |
| 498 | n++; |
| 499 | z++; |
| 500 | } |
| 501 | return n; |
| 502 | } |
| @@ -669,13 +679,16 @@ | |
| 669 | } |
| 670 | if( z[0]=='[' && (n = linkLength(z))>0 ){ |
| 671 | *pTokenType = TOKEN_LINK; |
| 672 | return n; |
| 673 | } |
| 674 | } |
| 675 | *pTokenType = TOKEN_TEXT; |
| 676 | return 1 + textLength(z+1, p->state & ALLOW_WIKI); |
| 677 | } |
| 678 | |
| 679 | /* |
| 680 | ** Parse only Wiki links, return everything else as TOKEN_RAW. |
| 681 | ** |
| @@ -1382,11 +1395,11 @@ | |
| 1382 | zDisplay = zTarget; |
| 1383 | }else{ |
| 1384 | while( fossil_isspace(*zDisplay) ) zDisplay++; |
| 1385 | } |
| 1386 | openHyperlink(p, zTarget, zClose, sizeof(zClose), zOrig); |
| 1387 | if( linksOnly || zClose[0]==0 ){ |
| 1388 | if( cS1 ) z[iS1] = cS1; |
| 1389 | if( zClose[0]!=']' ){ |
| 1390 | blob_appendf(p->pOut, "[%h]%s", zTarget, zClose); |
| 1391 | }else{ |
| 1392 | blob_appendf(p->pOut, "%h%s", zTarget, zClose); |
| @@ -1506,22 +1519,26 @@ | |
| 1506 | /* Enter <verbatim> processing. With verbatim enabled, all other |
| 1507 | ** markup other than the corresponding end-tag with the same ID is |
| 1508 | ** ignored. |
| 1509 | */ |
| 1510 | if( markup.iCode==MARKUP_VERBATIM ){ |
| 1511 | int vAttrIdx, vAttrDidAppend=0; |
| 1512 | p->zVerbatimId = 0; |
| 1513 | p->inVerbatim = 1; |
| 1514 | p->preVerbState = p->state; |
| 1515 | p->state &= ~ALLOW_WIKI; |
| 1516 | for (vAttrIdx = 0; vAttrIdx < markup.nAttr; vAttrIdx++){ |
| 1517 | if( markup.aAttr[vAttrIdx].iACode == ATTR_ID ){ |
| 1518 | p->zVerbatimId = markup.aAttr[0].zValue; |
| 1519 | }else if( markup.aAttr[vAttrIdx].iACode == ATTR_TYPE ){ |
| 1520 | blob_appendf(p->pOut, "<pre name='code' class='%s'>", |
| 1521 | markup.aAttr[vAttrIdx].zValue); |
| 1522 | vAttrDidAppend=1; |
| 1523 | } |
| 1524 | } |
| 1525 | if( !vAttrDidAppend ) { |
| 1526 | endAutoParagraph(p); |
| 1527 | blob_append(p->pOut, "<pre class='verbatim'>",-1); |
| 1528 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -385,13 +385,14 @@ | |
| 385 | ** State flags. Save the lower 16 bits for the WIKI_* flags. |
| 386 | */ |
| 387 | #define AT_NEWLINE 0x0010000 /* At start of a line */ |
| 388 | #define AT_PARAGRAPH 0x0020000 /* At start of a paragraph */ |
| 389 | #define ALLOW_WIKI 0x0040000 /* Allow wiki markup */ |
| 390 | #define ALLOW_LINKS 0x0080000 /* Allow [...] hyperlinks */ |
| 391 | #define FONT_MARKUP_ONLY 0x0100000 /* Only allow MUTYPE_FONT markup */ |
| 392 | #define INLINE_MARKUP_ONLY 0x0200000 /* Allow only "inline" markup */ |
| 393 | #define IN_LIST 0x0400000 /* Within wiki <ul> or <ol> */ |
| 394 | |
| 395 | /* |
| 396 | ** Current state of the rendering engine |
| 397 | */ |
| 398 | typedef struct Renderer Renderer; |
| @@ -485,18 +486,27 @@ | |
| 486 | ** < |
| 487 | ** & |
| 488 | ** \n |
| 489 | ** [ |
| 490 | ** |
| 491 | ** The "[" is only considered if flags contain ALLOW_LINKS or ALLOW_WIKI. |
| 492 | ** The "\n" is only considered interesting if the flags constains ALLOW_WIKI. |
| 493 | */ |
| 494 | static int textLength(const char *z, int flags){ |
| 495 | int n = 0; |
| 496 | int c, x1, x2; |
| 497 | |
| 498 | if( flags & ALLOW_WIKI ){ |
| 499 | x1 = '['; |
| 500 | x2 = '\n'; |
| 501 | }else if( flags & ALLOW_LINKS ){ |
| 502 | x1 = '['; |
| 503 | x2 = 0; |
| 504 | }else{ |
| 505 | x1 = x2 = 0; |
| 506 | } |
| 507 | while( (c = z[0])!=0 && c!='<' && c!='&' && c!=x1 && c!=x2 ){ |
| 508 | n++; |
| 509 | z++; |
| 510 | } |
| 511 | return n; |
| 512 | } |
| @@ -669,13 +679,16 @@ | |
| 679 | } |
| 680 | if( z[0]=='[' && (n = linkLength(z))>0 ){ |
| 681 | *pTokenType = TOKEN_LINK; |
| 682 | return n; |
| 683 | } |
| 684 | }else if( (p->state & ALLOW_LINKS)!=0 && z[0]=='[' && (n = linkLength(z))>0 ){ |
| 685 | *pTokenType = TOKEN_LINK; |
| 686 | return n; |
| 687 | } |
| 688 | *pTokenType = TOKEN_TEXT; |
| 689 | return 1 + textLength(z+1, p->state); |
| 690 | } |
| 691 | |
| 692 | /* |
| 693 | ** Parse only Wiki links, return everything else as TOKEN_RAW. |
| 694 | ** |
| @@ -1382,11 +1395,11 @@ | |
| 1395 | zDisplay = zTarget; |
| 1396 | }else{ |
| 1397 | while( fossil_isspace(*zDisplay) ) zDisplay++; |
| 1398 | } |
| 1399 | openHyperlink(p, zTarget, zClose, sizeof(zClose), zOrig); |
| 1400 | if( linksOnly || zClose[0]==0 || p->inVerbatim ){ |
| 1401 | if( cS1 ) z[iS1] = cS1; |
| 1402 | if( zClose[0]!=']' ){ |
| 1403 | blob_appendf(p->pOut, "[%h]%s", zTarget, zClose); |
| 1404 | }else{ |
| 1405 | blob_appendf(p->pOut, "%h%s", zTarget, zClose); |
| @@ -1506,22 +1519,26 @@ | |
| 1519 | /* Enter <verbatim> processing. With verbatim enabled, all other |
| 1520 | ** markup other than the corresponding end-tag with the same ID is |
| 1521 | ** ignored. |
| 1522 | */ |
| 1523 | if( markup.iCode==MARKUP_VERBATIM ){ |
| 1524 | int ii, vAttrDidAppend=0; |
| 1525 | p->zVerbatimId = 0; |
| 1526 | p->inVerbatim = 1; |
| 1527 | p->preVerbState = p->state; |
| 1528 | p->state &= ~ALLOW_WIKI; |
| 1529 | for(ii=0; ii<markup.nAttr; ii++){ |
| 1530 | if( markup.aAttr[ii].iACode == ATTR_ID ){ |
| 1531 | p->zVerbatimId = markup.aAttr[ii].zValue; |
| 1532 | }else if( markup.aAttr[ii].iACode == ATTR_TYPE ){ |
| 1533 | if( fossil_stricmp(markup.aAttr[ii].zValue, "allow-links")==0 ){ |
| 1534 | p->state |= ALLOW_LINKS; |
| 1535 | }else{ |
| 1536 | blob_appendf(p->pOut, "<pre name='code' class='%s'>", |
| 1537 | markup.aAttr[ii].zValue); |
| 1538 | vAttrDidAppend=1; |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | if( !vAttrDidAppend ) { |
| 1543 | endAutoParagraph(p); |
| 1544 | blob_append(p->pOut, "<pre class='verbatim'>",-1); |
| 1545 |