Fossil

Diff
Login

Differences From Artifact [3adca37710]:

To Artifact [8f9f26fac9]:


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define WIKI_NOBADLINKS     0x010  /* Ignore broken hyperlinks */
#define WIKI_LINKSONLY      0x020  /* No markup.  Only decorate links */
#define WIKI_NEWLINE        0x040  /* Honor \n - break lines at each \n */
#define WIKI_MARKDOWN_URL   0x080  /* Hyperlink targets as in markdown */
#define WIKI_SAFE           0x100  /* Make the result safe for embedding */
#define WIKI_TARGET_BLANK   0x200  /* Hyperlinks go to a new window */
#define WIKI_NOBRACKET      0x400  /* Omit extra [..] around hyperlinks */
#define WIKI_MARKDOWN_LINK  0x800  /* Markdown link syntax: [display](URL) */
#endif


/*
** These are the only markup attributes allowed.
*/
enum allowed_attr_t {







|







32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define WIKI_NOBADLINKS     0x010  /* Ignore broken hyperlinks */
#define WIKI_LINKSONLY      0x020  /* No markup.  Only decorate links */
#define WIKI_NEWLINE        0x040  /* Honor \n - break lines at each \n */
#define WIKI_MARKDOWN_URL   0x080  /* Hyperlink targets as in markdown */
#define WIKI_SAFE           0x100  /* Make the result safe for embedding */
#define WIKI_TARGET_BLANK   0x200  /* Hyperlinks go to a new window */
#define WIKI_NOBRACKET      0x400  /* Omit extra [..] around hyperlinks */
#define WIKI_MARKDOWN_SPAN  0x800  /* Interpret span elements of markdown */
#endif


/*
** These are the only markup attributes allowed.
*/
enum allowed_attr_t {
433
434
435
436
437
438
439

440
441
442
443
444
445
446
447
#define TOKEN_PARAGRAPH     4  /* blank lines */
#define TOKEN_NEWLINE       5  /* A single "\n" */
#define TOKEN_BUL_LI        6  /*  "  *  " */
#define TOKEN_NUM_LI        7  /*  "  #  " */
#define TOKEN_ENUM          8  /*  "  \(?\d+[.)]?  " */
#define TOKEN_INDENT        9  /*  "   " */
#define TOKEN_RAW           10 /* Output exactly (used when wiki-use-html==1) */

#define TOKEN_TEXT          11 /* None of the above */

/*
** State flags.  Save the lower 16 bits for the WIKI_* flags.
*/
#define AT_NEWLINE          0x0010000  /* At start of a line */
#define AT_PARAGRAPH        0x0020000  /* At start of a paragraph */
#define ALLOW_WIKI          0x0040000  /* Allow wiki markup */







>
|







433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#define TOKEN_PARAGRAPH     4  /* blank lines */
#define TOKEN_NEWLINE       5  /* A single "\n" */
#define TOKEN_BUL_LI        6  /*  "  *  " */
#define TOKEN_NUM_LI        7  /*  "  #  " */
#define TOKEN_ENUM          8  /*  "  \(?\d+[.)]?  " */
#define TOKEN_INDENT        9  /*  "   " */
#define TOKEN_RAW           10 /* Output exactly (used when wiki-use-html==1) */
#define TOKEN_AUTOLINK      11 /* <URL> */
#define TOKEN_TEXT          12 /* None of the above */

/*
** State flags.  Save the lower 16 bits for the WIKI_* flags.
*/
#define AT_NEWLINE          0x0010000  /* At start of a line */
#define AT_PARAGRAPH        0x0020000  /* At start of a paragraph */
#define ALLOW_WIKI          0x0040000  /* Allow wiki markup */
680
681
682
683
684
685
686
687






688
689
690



691
692
693
694
695
696
697
static int nextWikiToken(const char *z, Renderer *p, int *pTokenType){
  int n;
  if( z[0]=='<' ){
    n = html_tag_length(z);
    if( n>0 ){
      *pTokenType = TOKEN_MARKUP;
      return n;
    }else{






      *pTokenType = TOKEN_CHARACTER;
      return 1;
    }



  }
  if( z[0]=='&' && (p->inVerbatim || !isElement(z)) ){
    *pTokenType = TOKEN_CHARACTER;
    return 1;
  }
  if( (p->state & ALLOW_WIKI)!=0 ){
    if( z[0]=='\n' ){







<
>
>
>
>
>
>
|
|
|
>
>
>







681
682
683
684
685
686
687

688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
static int nextWikiToken(const char *z, Renderer *p, int *pTokenType){
  int n;
  if( z[0]=='<' ){
    n = html_tag_length(z);
    if( n>0 ){
      *pTokenType = TOKEN_MARKUP;
      return n;

    }
    if( z[1]=='h'
     && (strncmp(z,"<https://",9)==0 || strncmp(z,"<http://",8)==0)
    ){
      for(n=8; z[n] && z[n]!='>'; n++){}
      if( z[n]=='>' ){
        *pTokenType = TOKEN_AUTOLINK;
        return n+1;
      }
    }
    *pTokenType = TOKEN_CHARACTER;
    return 1;
  }
  if( z[0]=='&' && (p->inVerbatim || !isElement(z)) ){
    *pTokenType = TOKEN_CHARACTER;
    return 1;
  }
  if( (p->state & ALLOW_WIKI)!=0 ){
    if( z[0]=='\n' ){
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
        int savedState;
        char zClose[20];
        char cS1 = 0;
        int iS1 = 0;

        startAutoParagraph(p);
        if( z[n]=='('
         && (p->state & WIKI_MARKDOWN_LINK)!=0
         && (zEnd = strchr(z+n+1,')'))!=0
        ){
          /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
          if( n>2 ){
            zDisplay = &z[1];
            z[n] = 0;
          }else{







|







1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
        int savedState;
        char zClose[20];
        char cS1 = 0;
        int iS1 = 0;

        startAutoParagraph(p);
        if( z[n]=='('
         && (p->state & WIKI_MARKDOWN_SPAN)!=0
         && (zEnd = strchr(z+n+1,')'))!=0
        ){
          /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
          if( n>2 ){
            zDisplay = &z[1];
            z[n] = 0;
          }else{
1647
1648
1649
1650
1651
1652
1653












1654
1655
1656
1657
1658
1659
1660
      case TOKEN_RAW: {
        if( linksOnly ){
          htmlize_to_blob(p->pOut, z, n);
        }else{
          blob_append(p->pOut, z, n);
        }
        break;












      }
      case TOKEN_MARKUP: {
        const char *zId;
        int iDiv;
        int mAttr = parseMarkup(&markup, z);

        /* Convert <title> to <h1 align='center'> */







>
>
>
>
>
>
>
>
>
>
>
>







1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
      case TOKEN_RAW: {
        if( linksOnly ){
          htmlize_to_blob(p->pOut, z, n);
        }else{
          blob_append(p->pOut, z, n);
        }
        break;
      }
      case TOKEN_AUTOLINK: {
        /* URL enclosed in <...> */
        if( (p->state & WIKI_MARKDOWN_SPAN)==0 ){
          blob_append(p->pOut, "&lt;", 4);
          n = 1;
        }else{
          z[n-1] = 0;
          blob_appendf(p->pOut, "<a href=\"%h\">%h</a>", z+1, z+1);
          z[n-1] = '>';
        }
        break;
      }
      case TOKEN_MARKUP: {
        const char *zId;
        int iDiv;
        int mAttr = parseMarkup(&markup, z);

        /* Convert <title> to <h1 align='center'> */
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
**
** Options:
**    --buttons        Set the WIKI_BUTTONS flag
**    --dark-pikchr    Render pikchrs in dark mode
**    --htmlonly       Set the WIKI_HTMLONLY flag
**    --inline         Set the WIKI_INLINE flag
**    --linksonly      Set the WIKI_LINKSONLY flag
**    --md-links       Allow markdown link syntax
**    --nobadlinks     Set the WIKI_NOBADLINKS flag
**    --noblock        Set the WIKI_NOBLOCK flag
**    --text           Run the output through html_to_plaintext().
*/
void test_wiki_render(void){
  Blob in, out;
  int flags = 0;
  int bText;
  if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
  if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
  if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
  if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
  if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
  if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
  if( find_option("md-links",0,0)!=0 ) flags |= WIKI_MARKDOWN_LINK;
  if( find_option("dark-pikchr",0,0)!=0 ){
    pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
  }
  bText = find_option("text",0,0)!=0;
  db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
  verify_all_options();
  if( g.argc!=3 ) usage("FILE");







|














|







1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
**
** Options:
**    --buttons        Set the WIKI_BUTTONS flag
**    --dark-pikchr    Render pikchrs in dark mode
**    --htmlonly       Set the WIKI_HTMLONLY flag
**    --inline         Set the WIKI_INLINE flag
**    --linksonly      Set the WIKI_LINKSONLY flag
**    --md-span        Allow markdown span syntax: links and emphasis marks
**    --nobadlinks     Set the WIKI_NOBADLINKS flag
**    --noblock        Set the WIKI_NOBLOCK flag
**    --text           Run the output through html_to_plaintext().
*/
void test_wiki_render(void){
  Blob in, out;
  int flags = 0;
  int bText;
  if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
  if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
  if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
  if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
  if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
  if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
  if( find_option("md-span",0,0)!=0 ) flags |= WIKI_MARKDOWN_SPAN;
  if( find_option("dark-pikchr",0,0)!=0 ){
    pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
  }
  bText = find_option("text",0,0)!=0;
  db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
  verify_all_options();
  if( g.argc!=3 ) usage("FILE");
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
    }
    switch( tokenType ){
      case TOKEN_LINK: {
        char *zTarget, *zEnd;
        int i;

        if( z[n]=='('
         && (flags & WIKI_MARKDOWN_LINK)!=0
         && (zEnd = strchr(z+n+1,')'))!=0
        ){
          /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
          z += n+1;
          zTarget = z;
          for(i=1; z[i] && z[i]!=')' && z[i]!=' '; i++){}
          n = (int)(zEnd - z) + 1;







|







2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
    }
    switch( tokenType ){
      case TOKEN_LINK: {
        char *zTarget, *zEnd;
        int i;

        if( z[n]=='('
         && (flags & WIKI_MARKDOWN_SPAN)!=0
         && (zEnd = strchr(z+n+1,')'))!=0
        ){
          /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
          z += n+1;
          zTarget = z;
          for(i=1; z[i] && z[i]!=')' && z[i]!=' '; i++){}
          n = (int)(zEnd - z) + 1;