Fossil

Diff
Login

Differences From Artifact [2befacbb7b]:

To Artifact [ea3f9314f5]:


498
499
500
501
502
503
504













505
506
507
508
509
510
511
512
513
514
515
516



























517
518
519
520
521
522
523
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563







+
+
+
+
+
+
+
+
+
+
+
+
+












+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







  struct sStack {
    short iCode;                 /* Markup code */
    short allowWiki;             /* ALLOW_WIKI if wiki allowed before tag */
    const char *zId;             /* ID attribute or NULL */
  } *aStack;
};


/*
** SETTING: wiki-use-html                         boolean default=off
**
** If enabled, recognize only HTML in Fossil Wiki text.  Other wiki markup
** is ignored.  In other words, this setting make HTML the wiki markup
** language.
**
** CAUTION: When enabled, this setting allows *all* HTML text through,
** unsanitized.  Only use this setting in closed environments where all
** inputs are from trusted users, as the ability to inject arbitrary
** HTML can be misused by rapscallions.
*/
/*
** Return TRUE if HTML should be used as the sole markup language for wiki.
**
** On first invocation, this routine consults the "wiki-use-html" setting.
** It caches the result for subsequent invocations, under the assumption
** that the setting will not change.
*/
static int wikiUsesHtml(void){
  static int r = -1;
  if( r<0 ) r = db_get_boolean("wiki-use-html", 0);
  return r;
}

/*
** SETTING:  wiki-classic                     boolean default=off
**
** When enabled, this setting causes Fossil Wiki text to be rendered
** in the original circa-2007 style which omits the enhancements added
** in 2025.  Enable this setting if you have an older repository with
** a lot of wiki-formatted text that does not render well using the
** new enhancements.
**
** The specific wiki formatting enhancements that are disabled when
** then setting is turned on are:
**
**    *    Markdown hyperlinks:   [display-text](URL)
**    *    Bracket hyperlinks:    <URL>
**    *    Font changes:          *italic*   **bold**   `teletype`
**    *    Backslash escapes:     \\<  \\[  \\*  \\'  \\_  \\\\    and so forth
*/
/*
** Return TRUE limit wiki formatting to the classic circa-2007 style
** and omit the 2025 enhancements.
*/
static int wikiClassic(void){
  static int r = -1;
  if( r<0 ) r = db_get_boolean("wiki-classic", 0);
  return r;
}

/*
** z points to a "<" character.  Check to see if this is the start of
** a valid markup.  If it is, return the total number of characters in
** the markup including the initial "<" and the terminating ">".  If
** it is not well-formed markup, return 0.
*/
2064
2065
2066
2067
2068
2069
2070







2071
2072
2073
2074
2075
2076
2077
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124







+
+
+
+
+
+
+







*/
void wiki_convert(Blob *pIn, Blob *pOut, int flags){
  Renderer renderer;

  memset(&renderer, 0, sizeof(renderer));
  renderer.renderFlags = flags;
  renderer.state = ALLOW_WIKI|AT_NEWLINE|AT_PARAGRAPH|flags;
  if( (flags & WIKI_OVERRIDE)==0 ){
    if( wikiClassic() ){
      renderer.state &= ~(WIKI_MARKDOWN_INLINE);
    }else{
      renderer.state |= WIKI_MARKDOWN_INLINE;
    }
  }
  if( flags & WIKI_INLINE ){
    renderer.wantAutoParagraph = 0;
  }else{
    renderer.wantAutoParagraph = 1;
  }
  if( wikiUsesHtml() ){
    renderer.state |= WIKI_HTMLONLY;
2131
2132
2133
2134
2135
2136
2137
2138


2139

2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155







2156
2157
2158
2159
2160
2161
2162
2178
2179
2180
2181
2182
2183
2184

2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218







-
+
+

+
















+
+
+
+
+
+
+







**
** Usage: %fossil test-wiki-render FILE [OPTIONS]
**
** Translate the input FILE from Fossil-wiki into HTML and write
** the resulting HTML on standard output.
**
** Options:
**    --buttons        Set the WIKI_BUTTONS flag
**    --buttons          Set the WIKI_BUTTONS flag
**    --classic          Use only classic wiki rules
**    --dark-pikchr      Render pikchrs in dark mode
**    --enhanced         Use 2025 enhanced wiki rules
**    --htmlonly         Set the WIKI_HTMLONLY flag
**    --inline           Set the WIKI_INLINE flag
**    --linksonly        Set the WIKI_LINKSONLY flag
**    --markdown         Allow all in-line markdown syntax
**    --markdown-link    Allow markdown hyperlink syntax
**    --markdown-style   Allow markdown font and style markup
**    --nobadlinks       Set the WIKI_NOBADLINKS flag
**    --noblock          Set the WIKI_NOBLOCK flag
**    --text             Run the output through html_to_plaintext().
**    --tokenize         Output a tokenization of the input file
*/
void test_wiki_render(void){
  Blob in, out;
  int flags = ALLOW_LINKS;
  int bText, bTokenize;
  if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
  if( find_option("classic",0,0)!=0 ){
    flags |= WIKI_OVERRIDE;
    flags &= ~(WIKI_MARKDOWN_INLINE);
  }
  if( find_option("enhanced",0,0)!=0 ){
    flags |= WIKI_OVERRIDE|WIKI_MARKDOWN_INLINE;
  }
  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("markdown",0,0)!=0 ) flags |= WIKI_MARKDOWN_INLINE;
  if( find_option("markdown-style",0,0)!=0 ) flags |= WIKI_MARKDOWN_FONT;
2279
2280
2281
2282
2283
2284
2285

2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304

2305
2306
2307

2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318

2319
2320
2321
2322
2323
2324
2325
2326
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356


2357
2358

2359



2360






2361




2362

2363
2364
2365
2366
2367
2368
2369







+














-
-


-
+
-
-
-
+
-
-
-
-
-
-

-
-
-
-
+
-







}

/*
** Parse text looking for wiki hyperlinks in one of the formats:
**
**       [target]
**       [target|...]
**       [display](target)
**
** Where "target" can be either an artifact ID prefix or a wiki page
** name.  For each such hyperlink found, add an entry to the
** backlink table.
*/
void wiki_extract_links(
  char *z,           /* The wiki text from which to extract links */
  Backlink *pBklnk,  /* Backlink extraction context */
  int flags          /* wiki parsing flags */
){
  Renderer renderer;
  int tokenType;
  ParsedMarkup markup;
  int n;
  int inlineOnly;
  int wikiHtmlOnly = 0;

  memset(&renderer, 0, sizeof(renderer));
  renderer.state = ALLOW_WIKI|AT_NEWLINE|AT_PARAGRAPH;
  renderer.state = ALLOW_WIKI;
  if( flags & WIKI_NOBLOCK ){
    renderer.state |= INLINE_MARKUP_ONLY;
  }

  if( wikiUsesHtml() ){
    renderer.state |= WIKI_HTMLONLY;
    wikiHtmlOnly = 1;
  }
  inlineOnly = (renderer.state & INLINE_MARKUP_ONLY)!=0;

  while( z[0] ){
    if( wikiHtmlOnly ){
      n = nextRawToken(z, &renderer, &tokenType);
    }else{
      n = nextWikiToken(z, &renderer, &tokenType);
    n = nextWikiToken(z, &renderer, &tokenType);
    }
    switch( tokenType ){
      case TOKEN_LINK: {
        char *zTarget, *zEnd;
        int i;

        if( z[n]=='('
         && (flags & WIKI_MARKDOWN_LINK)!=0
2400
2401
2402
2403
2404
2405
2406
2407

2408
2409
2410
2411
2412
2413
2414
2443
2444
2445
2446
2447
2448
2449

2450
2451
2452
2453
2454
2455
2456
2457







-
+







          }else{
            renderer.state &= ~ALLOW_WIKI;
          }
        }else

        /* Ignore block markup for in-line rendering.
        */
        if( inlineOnly && (markup.iType&MUTYPE_INLINE)==0 ){
        if( (markup.iType & MUTYPE_INLINE)==0 ){
          /* Do nothing */
        }else

        /* Generate end-tags */
        if( markup.endTag ){
          popStackToTag(&renderer, markup.iCode);
        }else