Fossil

Check-in [3c786c6f]
Login

Check-in [3c786c6f]

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

Overview
Comment:Experimental double-click to toggle between SVG and pikchr source.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 3c786c6fc3603d8204708750fffc981f5d9a96c1642917c31853ef6d5cbd3047
User & Date: drh 2020-09-17 17:58:45
Context
2020-09-17
18:04
Put the javascript for SVG/source toggling inside of the safe-html nonce so that it survives safing. ... (check-in: ebf5b595 user: drh tags: trunk)
17:58
Experimental double-click to toggle between SVG and pikchr source. ... (check-in: 3c786c6f user: drh tags: trunk)
17:17
Pedantic CSS tweaks. ... (check-in: 5b93a4da user: stephan tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/markdown_html.c.

331
332
333
334
335
336
337

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


/*
** The nSrc bytes at zSrc[] are Pikchr input text (allegedly).  Process that
** text and insert the result in place of the original.
*/
void pikchr_to_html(
  Blob *ob,                     /* Write the generated SVG here */
  const char *zSrc, int nSrc,   /* The Pikchr source text */







>







331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
  }else{
    html_escape(ob, blob_buffer(link), blob_size(link));
  }
  BLOB_APPEND_LITERAL(ob, "</a>");
  return 1;
}

#if 0
/*
** The nSrc bytes at zSrc[] are Pikchr input text (allegedly).  Process that
** text and insert the result in place of the original.
*/
void pikchr_to_html(
  Blob *ob,                     /* Write the generated SVG here */
  const char *zSrc, int nSrc,   /* The Pikchr source text */
370
371
372
373
374
375
376



































































377
378
379
380
381
382
383
    nArg -= i;
  }
  blob_append(&bSrc, zSrc, nSrc)
    /*have to dupe input to ensure a NUL-terminated source string */;
  pikchr_process(blob_str(&bSrc), pikFlags, 0, ob);
  blob_reset(&bSrc);
}





































































/* 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







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







371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
    nArg -= i;
  }
  blob_append(&bSrc, zSrc, nSrc)
    /*have to dupe input to ensure a NUL-terminated source string */;
  pikchr_process(blob_str(&bSrc), pikFlags, 0, ob);
  blob_reset(&bSrc);
}
#endif

/*
** The nSrc bytes at zSrc[] are Pikchr input text (allegedly).  Process that
** text and insert the result in place of the original.
*/
void pikchr_to_html(
  Blob *ob,                     /* Write the generated SVG here */
  const char *zSrc, int nSrc,   /* The Pikchr source text */
  const char *zArg, int nArg    /* Addition arguments */
){
  int w = 0, h = 0;
  char *zIn = fossil_strndup(zSrc, nSrc);
  char *zOut = pikchr(zIn, "pikchr", PIKCHR_INCLUDE_SOURCE, &w, &h);
  if( w>0 && h>0 ){
    static int nSvg = 0;
    const char *zSafeNonce = safe_html_nonce(1);
    Blob css;
    blob_init(&css,0,0);
    blob_appendf(&css,"max-width:%dpx;",w);
    blob_append(ob, zSafeNonce, -1);
    blob_append_char(ob, '\n');
    while( nArg>0 ){
      int i;
      for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
      if( i==6 && strncmp(zArg, "center", 6)==0 ){
        blob_appendf(&css, "display:block;margin:auto;");
        break;
      }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
        blob_appendf(&css, "margin-left:4em;");
        break;
      }else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
        blob_appendf(&css, "float:left;padding=4em;");
        break;
      }else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
        blob_appendf(&css, "float:right;padding=4em;");
        break;
      }
      while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
      zArg += i;
      nArg -= i;
    }
    blob_appendf(ob, "<div id='svgid-%d'>\n", ++nSvg);
    blob_appendf(ob, "<div class='pikchr-svg' style='%s'>\n", blob_str(&css));
    blob_append(ob, zOut, -1);
    blob_appendf(ob, "</div>\n");
    blob_reset(&css);
    blob_appendf(ob, "<pre class='pikchr-src' style='display:none;'>"
                     "%s</pre>\n", zIn);
    blob_appendf(ob, "</div>\n");
    blob_appendf(ob, "%s\n", zSafeNonce);
    blob_appendf(ob,
      "<script nonce='%s'>\n"
      "document.getElementById('svgid-%d').ondblclick=function(){\n"
      "  for(var c of this.children){"
      "    c.style.display = c.style.display=='none'?'block':'none';"
      "  }\n"
      "}\n"
      "</script>\n",
      style_nonce(), nSvg);
  }else{
    blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
  }
  fossil_free(zIn);
  free(zOut);
}



/* 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