Fossil

Check-in [81caad6c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Further refine the fenced code block rendering in markdown to try to comply with the CommonMark spec.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 81caad6ce6bc412c80b0d1221ca500caad39af5da205dc679025e6233a447b26
User & Date: drh 2019-08-08 22:26:50
Context
2019-08-08
23:04
Fix the www/fossil_prompt.sh Fossilized Bash Prompt script so that it works even if the current check-in comment contains grave accents (backticks). check-in: c49f3ef4 user: drh tags: trunk
22:26
Further refine the fenced code block rendering in markdown to try to comply with the CommonMark spec. check-in: 81caad6c user: drh tags: trunk
20:35
A triple grave accent quoted text (```....```) in markdown is rendered as <pre>...</pre>. check-in: 2077ffe6 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/markdown_html.c.

323
324
325
326
327
328
329









330
331
332
333
334
335
336
337



338
339





















340
341
342
343
344
345
346
  }else{
    html_escape(ob, blob_buffer(link), blob_size(link));
  }
  BLOB_APPEND_LITERAL(ob, "</a>");
  return 1;
}










static int html_code_span(
  struct Blob *ob,
  struct Blob *text,  /* The stuff in between the code span marks */
  int nSep,           /* Number of grave accents marks as delimiters */
  void *opaque
){
  if( text ){
    blob_append(ob, nSep>=3 ? "<pre>" : "<code>", -1);



    html_escape(ob, blob_buffer(text), blob_size(text));
    blob_append(ob, nSep>=3 ? "</pre>" : "</code>", -1);





















  }
  return 1;
}

static int html_double_emphasis(
  struct Blob *ob,
  struct Blob *text,







>
>
>
>
>
>
>
>
>

|




|
|
>
>
>

<
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350

351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
  }else{
    html_escape(ob, blob_buffer(link), blob_size(link));
  }
  BLOB_APPEND_LITERAL(ob, "</a>");
  return 1;
}

/* Invoked for `...` blocks where there are nSep grave accents in a
** row that serve as the delimiter.  According to CommonMark:
**
**   *  https://spec.commonmark.org/0.29/#fenced-code-blocks
**   *  https://spec.commonmark.org/0.29/#code-spans
**
** If nSep is 1 or 2, then this is a code-span which is inline.
** If nSep is 3 or more, then this is a fenced code block
*/
static int html_code_span(
  struct Blob *ob,    /* Write the output here */
  struct Blob *text,  /* The stuff in between the code span marks */
  int nSep,           /* Number of grave accents marks as delimiters */
  void *opaque
){
  if( text==0 ){
    /* no-op */
  }else if( nSep<=2 ){
    /* One or two graves: an in-line code span */
    BLOB_APPEND_LITERAL(ob, "<code>");
    html_escape(ob, blob_buffer(text), blob_size(text));

    BLOB_APPEND_LITERAL(ob, "</code>");
  }else{
    /* Three or more graves: a fenced code block */
    int n = blob_size(text);
    const char *z = blob_buffer(text);
    int i;
    for(i=0; i<n && z[i]!='\n'; i++){}
    if( i>=n ){
      blob_appendf(ob, "<pre><code>%.*s</code></pre>", n, z);
    }else{
      int k, j;
      i++;
      for(k=0; k<i && fossil_isspace(z[k]); k++){}
      if( k==i ){
        blob_appendf(ob, "<pre><code>%.*s</code></pre>", n-i, z+i);
      }else{
        for(j=k+1; j<i && !fossil_isspace(z[j]); j++){}
        blob_appendf(ob, "<pre><code class='language-%#h'>%.*s</code></pre>",
                          j-k, z+k, n-i, z+i);
      }
    }
  }
  return 1;
}

static int html_double_emphasis(
  struct Blob *ob,
  struct Blob *text,