Fossil SCM

Experimental double-click to toggle between SVG and pikchr source.

drh 2020-09-17 17:58 trunk
Commit 3c786c6fc3603d8204708750fffc981f5d9a96c1642917c31853ef6d5cbd3047
1 file changed +68
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -333,10 +333,11 @@
333333
}
334334
BLOB_APPEND_LITERAL(ob, "</a>");
335335
return 1;
336336
}
337337
338
+#if 0
338339
/*
339340
** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
340341
** text and insert the result in place of the original.
341342
*/
342343
void pikchr_to_html(
@@ -372,10 +373,77 @@
372373
blob_append(&bSrc, zSrc, nSrc)
373374
/*have to dupe input to ensure a NUL-terminated source string */;
374375
pikchr_process(blob_str(&bSrc), pikFlags, 0, ob);
375376
blob_reset(&bSrc);
376377
}
378
+#endif
379
+
380
+/*
381
+** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
382
+** text and insert the result in place of the original.
383
+*/
384
+void pikchr_to_html(
385
+ Blob *ob, /* Write the generated SVG here */
386
+ const char *zSrc, int nSrc, /* The Pikchr source text */
387
+ const char *zArg, int nArg /* Addition arguments */
388
+){
389
+ int w = 0, h = 0;
390
+ char *zIn = fossil_strndup(zSrc, nSrc);
391
+ char *zOut = pikchr(zIn, "pikchr", PIKCHR_INCLUDE_SOURCE, &w, &h);
392
+ if( w>0 && h>0 ){
393
+ static int nSvg = 0;
394
+ const char *zSafeNonce = safe_html_nonce(1);
395
+ Blob css;
396
+ blob_init(&css,0,0);
397
+ blob_appendf(&css,"max-width:%dpx;",w);
398
+ blob_append(ob, zSafeNonce, -1);
399
+ blob_append_char(ob, '\n');
400
+ while( nArg>0 ){
401
+ int i;
402
+ for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
403
+ if( i==6 && strncmp(zArg, "center", 6)==0 ){
404
+ blob_appendf(&css, "display:block;margin:auto;");
405
+ break;
406
+ }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
407
+ blob_appendf(&css, "margin-left:4em;");
408
+ break;
409
+ }else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
410
+ blob_appendf(&css, "float:left;padding=4em;");
411
+ break;
412
+ }else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
413
+ blob_appendf(&css, "float:right;padding=4em;");
414
+ break;
415
+ }
416
+ while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
417
+ zArg += i;
418
+ nArg -= i;
419
+ }
420
+ blob_appendf(ob, "<div id='svgid-%d'>\n", ++nSvg);
421
+ blob_appendf(ob, "<div class='pikchr-svg' style='%s'>\n", blob_str(&css));
422
+ blob_append(ob, zOut, -1);
423
+ blob_appendf(ob, "</div>\n");
424
+ blob_reset(&css);
425
+ blob_appendf(ob, "<pre class='pikchr-src' style='display:none;'>"
426
+ "%s</pre>\n", zIn);
427
+ blob_appendf(ob, "</div>\n");
428
+ blob_appendf(ob, "%s\n", zSafeNonce);
429
+ blob_appendf(ob,
430
+ "<script nonce='%s'>\n"
431
+ "document.getElementById('svgid-%d').ondblclick=function(){\n"
432
+ " for(var c of this.children){"
433
+ " c.style.display = c.style.display=='none'?'block':'none';"
434
+ " }\n"
435
+ "}\n"
436
+ "</script>\n",
437
+ style_nonce(), nSvg);
438
+ }else{
439
+ blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
440
+ }
441
+ fossil_free(zIn);
442
+ free(zOut);
443
+}
444
+
377445
378446
379447
/* Invoked for `...` blocks where there are nSep grave accents in a
380448
** row that serve as the delimiter. According to CommonMark:
381449
**
382450
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -333,10 +333,11 @@
333 }
334 BLOB_APPEND_LITERAL(ob, "</a>");
335 return 1;
336 }
337
 
338 /*
339 ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
340 ** text and insert the result in place of the original.
341 */
342 void pikchr_to_html(
@@ -372,10 +373,77 @@
372 blob_append(&bSrc, zSrc, nSrc)
373 /*have to dupe input to ensure a NUL-terminated source string */;
374 pikchr_process(blob_str(&bSrc), pikFlags, 0, ob);
375 blob_reset(&bSrc);
376 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
378
379 /* Invoked for `...` blocks where there are nSep grave accents in a
380 ** row that serve as the delimiter. According to CommonMark:
381 **
382
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -333,10 +333,11 @@
333 }
334 BLOB_APPEND_LITERAL(ob, "</a>");
335 return 1;
336 }
337
338 #if 0
339 /*
340 ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
341 ** text and insert the result in place of the original.
342 */
343 void pikchr_to_html(
@@ -372,10 +373,77 @@
373 blob_append(&bSrc, zSrc, nSrc)
374 /*have to dupe input to ensure a NUL-terminated source string */;
375 pikchr_process(blob_str(&bSrc), pikFlags, 0, ob);
376 blob_reset(&bSrc);
377 }
378 #endif
379
380 /*
381 ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
382 ** text and insert the result in place of the original.
383 */
384 void pikchr_to_html(
385 Blob *ob, /* Write the generated SVG here */
386 const char *zSrc, int nSrc, /* The Pikchr source text */
387 const char *zArg, int nArg /* Addition arguments */
388 ){
389 int w = 0, h = 0;
390 char *zIn = fossil_strndup(zSrc, nSrc);
391 char *zOut = pikchr(zIn, "pikchr", PIKCHR_INCLUDE_SOURCE, &w, &h);
392 if( w>0 && h>0 ){
393 static int nSvg = 0;
394 const char *zSafeNonce = safe_html_nonce(1);
395 Blob css;
396 blob_init(&css,0,0);
397 blob_appendf(&css,"max-width:%dpx;",w);
398 blob_append(ob, zSafeNonce, -1);
399 blob_append_char(ob, '\n');
400 while( nArg>0 ){
401 int i;
402 for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
403 if( i==6 && strncmp(zArg, "center", 6)==0 ){
404 blob_appendf(&css, "display:block;margin:auto;");
405 break;
406 }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
407 blob_appendf(&css, "margin-left:4em;");
408 break;
409 }else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
410 blob_appendf(&css, "float:left;padding=4em;");
411 break;
412 }else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
413 blob_appendf(&css, "float:right;padding=4em;");
414 break;
415 }
416 while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
417 zArg += i;
418 nArg -= i;
419 }
420 blob_appendf(ob, "<div id='svgid-%d'>\n", ++nSvg);
421 blob_appendf(ob, "<div class='pikchr-svg' style='%s'>\n", blob_str(&css));
422 blob_append(ob, zOut, -1);
423 blob_appendf(ob, "</div>\n");
424 blob_reset(&css);
425 blob_appendf(ob, "<pre class='pikchr-src' style='display:none;'>"
426 "%s</pre>\n", zIn);
427 blob_appendf(ob, "</div>\n");
428 blob_appendf(ob, "%s\n", zSafeNonce);
429 blob_appendf(ob,
430 "<script nonce='%s'>\n"
431 "document.getElementById('svgid-%d').ondblclick=function(){\n"
432 " for(var c of this.children){"
433 " c.style.display = c.style.display=='none'?'block':'none';"
434 " }\n"
435 "}\n"
436 "</script>\n",
437 style_nonce(), nSvg);
438 }else{
439 blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
440 }
441 fossil_free(zIn);
442 free(zOut);
443 }
444
445
446
447 /* Invoked for `...` blocks where there are nSep grave accents in a
448 ** row that serve as the delimiter. According to CommonMark:
449 **
450

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button