| | @@ -23,22 +23,24 @@ |
| 23 | 23 | |
| 24 | 24 | #if INTERFACE |
| 25 | 25 | /* |
| 26 | 26 | ** Allowed wiki transformation operations |
| 27 | 27 | */ |
| 28 | | -#define WIKI_HTMLONLY 0x001 /* HTML markup only. No wiki */ |
| 29 | | -#define WIKI_INLINE 0x002 /* Do not surround with <p>..</p> */ |
| 30 | | -#define WIKI_NOBLOCK 0x004 /* No block markup of any kind */ |
| 31 | | -#define WIKI_BUTTONS 0x008 /* Allow sub-menu buttons */ |
| 32 | | -#define WIKI_NOBADLINKS 0x010 /* Ignore broken hyperlinks */ |
| 33 | | -#define WIKI_LINKSONLY 0x020 /* No markup. Only decorate links */ |
| 34 | | -#define WIKI_NEWLINE 0x040 /* Honor \n - break lines at each \n */ |
| 35 | | -#define WIKI_MARKDOWN_URL 0x080 /* Hyperlink targets as in markdown */ |
| 36 | | -#define WIKI_SAFE 0x100 /* Make the result safe for embedding */ |
| 37 | | -#define WIKI_TARGET_BLANK 0x200 /* Hyperlinks go to a new window */ |
| 38 | | -#define WIKI_NOBRACKET 0x400 /* Omit extra [..] around hyperlinks */ |
| 39 | | -#define WIKI_MARKDOWN_SPAN 0x800 /* Interpret span elements of markdown */ |
| 28 | +#define WIKI_HTMLONLY 0x0001 /* HTML markup only. No wiki */ |
| 29 | +#define WIKI_INLINE 0x0002 /* Do not surround with <p>..</p> */ |
| 30 | +#define WIKI_NOBLOCK 0x0004 /* No block markup of any kind */ |
| 31 | +#define WIKI_BUTTONS 0x0008 /* Allow sub-menu buttons */ |
| 32 | +#define WIKI_NOBADLINKS 0x0010 /* Ignore broken hyperlinks */ |
| 33 | +#define WIKI_LINKSONLY 0x0020 /* No markup. Only decorate links */ |
| 34 | +#define WIKI_NEWLINE 0x0040 /* Honor \n - break lines at each \n */ |
| 35 | +#define WIKI_SAFE 0x0080 /* Make the result safe for embedding */ |
| 36 | +#define WIKI_TARGET_BLANK 0x0100 /* Hyperlinks go to a new window */ |
| 37 | +#define WIKI_NOBRACKET 0x0200 /* Omit extra [..] around hyperlinks */ |
| 38 | +#define WIKI_MARKDOWN_URL 0x0400 /* Process link targets as in markdown */ |
| 39 | +#define WIKI_MARKDOWN_FONT 0x0800 /* Accept markdown font/style markup */ |
| 40 | +#define WIKI_MARKDOWN_LINK 0x1000 /* Accept markdown hyperlinks */ |
| 41 | +#define WIKI_MARKDOWN_INLINE 0x1800 /* Combo of _FONT and _LINK */ |
| 40 | 42 | #endif |
| 41 | 43 | |
| 42 | 44 | |
| 43 | 45 | /* |
| 44 | 46 | ** These are the only markup attributes allowed. |
| | @@ -569,21 +571,21 @@ |
| 569 | 571 | ** |
| 570 | 572 | ** < |
| 571 | 573 | ** & |
| 572 | 574 | ** \n |
| 573 | 575 | ** [ |
| 574 | | -** _ * ` \ <-- WIKI_MARKDOWN_SPAN only. |
| 576 | +** _ * ` \ <-- WIKI_MARKDOWN_FONT only. |
| 575 | 577 | ** |
| 576 | 578 | ** The "[" is only considered if flags contain ALLOW_LINKS or ALLOW_WIKI. |
| 577 | 579 | ** The "\n" is only considered interesting if the flags constains ALLOW_WIKI. |
| 578 | 580 | ** The markdown span characters, _ * ` and \, are only considered if both |
| 579 | | -** ALLOW_WIKI and WIKI_MARKDOWN_SPAN are set. |
| 581 | +** ALLOW_WIKI and WIKI_MARKDOWN_FONT are set. |
| 580 | 582 | */ |
| 581 | 583 | static int textLength(const char *z, int flags){ |
| 582 | 584 | const char *zReject; |
| 583 | 585 | if( flags & ALLOW_WIKI ){ |
| 584 | | - if( flags & WIKI_MARKDOWN_SPAN ){ |
| 586 | + if( flags & WIKI_MARKDOWN_FONT ){ |
| 585 | 587 | zReject = "_*`\\\n[<&"; |
| 586 | 588 | }else{ |
| 587 | 589 | zReject = "\n[<&"; |
| 588 | 590 | } |
| 589 | 591 | }else if( flags & ALLOW_LINKS ){ |
| | @@ -1675,11 +1677,11 @@ |
| 1675 | 1677 | char cS1 = 0; |
| 1676 | 1678 | int iS1 = 0; |
| 1677 | 1679 | |
| 1678 | 1680 | startAutoParagraph(p); |
| 1679 | 1681 | if( z[n]=='(' |
| 1680 | | - && (p->state & WIKI_MARKDOWN_SPAN)!=0 |
| 1682 | + && (p->state & WIKI_MARKDOWN_LINK)!=0 |
| 1681 | 1683 | && (zEnd = strchr(z+n+1,')'))!=0 |
| 1682 | 1684 | ){ |
| 1683 | 1685 | /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */ |
| 1684 | 1686 | if( n>2 ){ |
| 1685 | 1687 | zDisplay = &z[1]; |
| | @@ -1727,21 +1729,21 @@ |
| 1727 | 1729 | blob_append(p->pOut, zClose, -1); |
| 1728 | 1730 | } |
| 1729 | 1731 | break; |
| 1730 | 1732 | } |
| 1731 | 1733 | case TOKEN_BACKSLASH: { |
| 1732 | | - if( (p->state & WIKI_MARKDOWN_SPAN)==0 ){ |
| 1734 | + if( (p->state & WIKI_MARKDOWN_FONT)==0 ){ |
| 1733 | 1735 | /* Ignore backslashes in traditional Wiki */ |
| 1734 | 1736 | blob_append_char(p->pOut, '\\'); |
| 1735 | 1737 | n = 1; |
| 1736 | 1738 | }else{ |
| 1737 | 1739 | blob_append_char(p->pOut, z[1]); |
| 1738 | 1740 | } |
| 1739 | 1741 | break; |
| 1740 | 1742 | } |
| 1741 | 1743 | case TOKEN_MDCODE: { |
| 1742 | | - if( (p->state & WIKI_MARKDOWN_SPAN)==0 ){ |
| 1744 | + if( (p->state & WIKI_MARKDOWN_FONT)==0 ){ |
| 1743 | 1745 | blob_append(p->pOut, z, n); |
| 1744 | 1746 | }else{ |
| 1745 | 1747 | int x = verbatimLength(p, z+n, n); |
| 1746 | 1748 | if( x==0 ){ |
| 1747 | 1749 | blob_append(p->pOut, z, n); |
| | @@ -1787,17 +1789,17 @@ |
| 1787 | 1789 | ** Originally, Fossil-Wiki would just display this as literal |
| 1788 | 1790 | ** text, but as of 2025-03-04, it actually inserts an <a>..</a> |
| 1789 | 1791 | ** for the hyperlink. The <...> delimiters are retained, however. |
| 1790 | 1792 | ** Except in markdown-span mode, the <...> delimiters are omitted. |
| 1791 | 1793 | */ |
| 1792 | | - if( (p->state & WIKI_MARKDOWN_SPAN)==0 ){ |
| 1794 | + if( (p->state & WIKI_MARKDOWN_LINK)==0 ){ |
| 1793 | 1795 | blob_append(p->pOut, "<", 4); |
| 1794 | 1796 | } |
| 1795 | 1797 | z[n-1] = 0; |
| 1796 | 1798 | blob_appendf(p->pOut, "<a href=\"%h\">%h</a>", z+1, z+1); |
| 1797 | 1799 | z[n-1] = '>'; |
| 1798 | | - if( (p->state & WIKI_MARKDOWN_SPAN)==0 ){ |
| 1800 | + if( (p->state & WIKI_MARKDOWN_LINK)==0 ){ |
| 1799 | 1801 | blob_append(p->pOut, ">", 4); |
| 1800 | 1802 | } |
| 1801 | 1803 | break; |
| 1802 | 1804 | } |
| 1803 | 1805 | case TOKEN_MARKUP: { |
| | @@ -2071,19 +2073,21 @@ |
| 2071 | 2073 | ** Translate the input FILE from Fossil-wiki into HTML and write |
| 2072 | 2074 | ** the resulting HTML on standard output. |
| 2073 | 2075 | ** |
| 2074 | 2076 | ** Options: |
| 2075 | 2077 | ** --buttons Set the WIKI_BUTTONS flag |
| 2076 | | -** --dark-pikchr Render pikchrs in dark mode |
| 2077 | | -** --htmlonly Set the WIKI_HTMLONLY flag |
| 2078 | | -** --inline Set the WIKI_INLINE flag |
| 2079 | | -** --linksonly Set the WIKI_LINKSONLY flag |
| 2080 | | -** --md-span Allow markdown span syntax: links and emphasis marks |
| 2081 | | -** --nobadlinks Set the WIKI_NOBADLINKS flag |
| 2082 | | -** --noblock Set the WIKI_NOBLOCK flag |
| 2083 | | -** --text Run the output through html_to_plaintext(). |
| 2084 | | -** --tokenize Output a tokenization of the input file |
| 2078 | +** --dark-pikchr Render pikchrs in dark mode |
| 2079 | +** --htmlonly Set the WIKI_HTMLONLY flag |
| 2080 | +** --inline Set the WIKI_INLINE flag |
| 2081 | +** --linksonly Set the WIKI_LINKSONLY flag |
| 2082 | +** --markdown Allow all in-line markdown syntax |
| 2083 | +** --markdown-link Allow markdown hyperlink syntax |
| 2084 | +** --markdown-style Allow markdown font and style markup |
| 2085 | +** --nobadlinks Set the WIKI_NOBADLINKS flag |
| 2086 | +** --noblock Set the WIKI_NOBLOCK flag |
| 2087 | +** --text Run the output through html_to_plaintext(). |
| 2088 | +** --tokenize Output a tokenization of the input file |
| 2085 | 2089 | */ |
| 2086 | 2090 | void test_wiki_render(void){ |
| 2087 | 2091 | Blob in, out; |
| 2088 | 2092 | int flags = 0; |
| 2089 | 2093 | int bText, bTokenize; |
| | @@ -2091,11 +2095,13 @@ |
| 2091 | 2095 | if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY; |
| 2092 | 2096 | if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY; |
| 2093 | 2097 | if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS; |
| 2094 | 2098 | if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE; |
| 2095 | 2099 | if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK; |
| 2096 | | - if( find_option("md-span",0,0)!=0 ) flags |= WIKI_MARKDOWN_SPAN; |
| 2100 | + if( find_option("markdown",0,0)!=0 ) flags |= WIKI_MARKDOWN_INLINE; |
| 2101 | + if( find_option("markdown-style",0,0)!=0 ) flags |= WIKI_MARKDOWN_FONT; |
| 2102 | + if( find_option("markdown-link",0,0)!=0 ) flags |= WIKI_MARKDOWN_LINK; |
| 2097 | 2103 | if( find_option("dark-pikchr",0,0)!=0 ){ |
| 2098 | 2104 | pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE ); |
| 2099 | 2105 | } |
| 2100 | 2106 | bText = find_option("text",0,0)!=0; |
| 2101 | 2107 | bTokenize = find_option("tokenize",0,0)!=0; |
| | @@ -2254,11 +2260,11 @@ |
| 2254 | 2260 | case TOKEN_LINK: { |
| 2255 | 2261 | char *zTarget, *zEnd; |
| 2256 | 2262 | int i; |
| 2257 | 2263 | |
| 2258 | 2264 | if( z[n]=='(' |
| 2259 | | - && (flags & WIKI_MARKDOWN_SPAN)!=0 |
| 2265 | + && (flags & WIKI_MARKDOWN_LINK)!=0 |
| 2260 | 2266 | && (zEnd = strchr(z+n+1,')'))!=0 |
| 2261 | 2267 | ){ |
| 2262 | 2268 | /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */ |
| 2263 | 2269 | z += n+1; |
| 2264 | 2270 | zTarget = z; |
| 2265 | 2271 | |