Fossil SCM

Toggle Pikchr between SVG and source code using ctrl-click. Or if the Pikchr was created using the "toggle" tag, an plain old single-click will suffice.

drh 2020-09-17 21:09 trunk
Commit d88444e265f3f78f72fe5c3fd34c1e191d7ff6a32954f8f32c8a40b9360c2b96
1 file changed +12 -15
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -348,52 +348,49 @@
348348
char *zIn = fossil_strndup(zSrc, nSrc);
349349
char *zOut = pikchr(zIn, "pikchr", 0, &w, &h);
350350
if( w>0 && h>0 ){
351351
static int nSvg = 0;
352352
const char *zSafeNonce = safe_html_nonce(1);
353
- Blob css;
354
- blob_init(&css,0,0);
355
- blob_appendf(&css,"max-width:%dpx;",w);
353
+ const char *zCss = "";
354
+ const char *zClickOk = "e.ctrlKey";
356355
blob_append(ob, zSafeNonce, -1);
357356
blob_append_char(ob, '\n');
358357
while( nArg>0 ){
359358
int i;
360359
for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
361360
if( i==6 && strncmp(zArg, "center", 6)==0 ){
362
- blob_appendf(&css, "display:block;margin:auto;");
363
- break;
361
+ zCss = "display:block;margin:auto;";
364362
}else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
365
- blob_appendf(&css, "margin-left:4em;");
366
- break;
363
+ zCss = "margin-left:4em;";
367364
}else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
368
- blob_appendf(&css, "float:left;padding=4em;");
369
- break;
365
+ zCss = "float:left;padding=4em;";
370366
}else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
371
- blob_appendf(&css, "float:right;padding=4em;");
372
- break;
367
+ zCss = "float:right;padding=4em;";
368
+ }else if( i==6 && strncmp(zArg, "toggle", 6)==0 ){
369
+ zClickOk = "1";
373370
}
374371
while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
375372
zArg += i;
376373
nArg -= i;
377374
}
378375
blob_appendf(ob, "<div id='svgid-%d'>\n", ++nSvg);
379
- blob_appendf(ob, "<div class='pikchr-svg' style='%s'>\n", blob_str(&css));
376
+ blob_appendf(ob, "<div class='pikchr-svg'");
377
+ blob_appendf(ob, " style='max-width:%dpx;%s'>\n", w, zCss);
380378
blob_append(ob, zOut, -1);
381379
blob_appendf(ob, "</div>\n");
382
- blob_reset(&css);
383380
blob_appendf(ob, "<pre class='hidden'><code>"
384381
"%s</code></pre>\n", zIn);
385382
blob_appendf(ob, "</div>\n");
386383
blob_appendf(ob,
387384
"<script nonce='%s'>\n"
388385
"document.getElementById('svgid-%d').onclick=function(e){\n"
389
- " if(e.ctrlKey){\n"
386
+ " if(%s){\n"
390387
" for(var c of this.children){c.classList.toggle('hidden');}\n"
391388
" }\n"
392389
"}\n"
393390
"</script>\n",
394
- style_nonce(), nSvg);
391
+ style_nonce(), nSvg, zClickOk);
395392
blob_appendf(ob, "%s\n", zSafeNonce);
396393
}else{
397394
blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
398395
}
399396
fossil_free(zIn);
400397
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -348,52 +348,49 @@
348 char *zIn = fossil_strndup(zSrc, nSrc);
349 char *zOut = pikchr(zIn, "pikchr", 0, &w, &h);
350 if( w>0 && h>0 ){
351 static int nSvg = 0;
352 const char *zSafeNonce = safe_html_nonce(1);
353 Blob css;
354 blob_init(&css,0,0);
355 blob_appendf(&css,"max-width:%dpx;",w);
356 blob_append(ob, zSafeNonce, -1);
357 blob_append_char(ob, '\n');
358 while( nArg>0 ){
359 int i;
360 for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
361 if( i==6 && strncmp(zArg, "center", 6)==0 ){
362 blob_appendf(&css, "display:block;margin:auto;");
363 break;
364 }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
365 blob_appendf(&css, "margin-left:4em;");
366 break;
367 }else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
368 blob_appendf(&css, "float:left;padding=4em;");
369 break;
370 }else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
371 blob_appendf(&css, "float:right;padding=4em;");
372 break;
 
373 }
374 while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
375 zArg += i;
376 nArg -= i;
377 }
378 blob_appendf(ob, "<div id='svgid-%d'>\n", ++nSvg);
379 blob_appendf(ob, "<div class='pikchr-svg' style='%s'>\n", blob_str(&css));
 
380 blob_append(ob, zOut, -1);
381 blob_appendf(ob, "</div>\n");
382 blob_reset(&css);
383 blob_appendf(ob, "<pre class='hidden'><code>"
384 "%s</code></pre>\n", zIn);
385 blob_appendf(ob, "</div>\n");
386 blob_appendf(ob,
387 "<script nonce='%s'>\n"
388 "document.getElementById('svgid-%d').onclick=function(e){\n"
389 " if(e.ctrlKey){\n"
390 " for(var c of this.children){c.classList.toggle('hidden');}\n"
391 " }\n"
392 "}\n"
393 "</script>\n",
394 style_nonce(), nSvg);
395 blob_appendf(ob, "%s\n", zSafeNonce);
396 }else{
397 blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
398 }
399 fossil_free(zIn);
400
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -348,52 +348,49 @@
348 char *zIn = fossil_strndup(zSrc, nSrc);
349 char *zOut = pikchr(zIn, "pikchr", 0, &w, &h);
350 if( w>0 && h>0 ){
351 static int nSvg = 0;
352 const char *zSafeNonce = safe_html_nonce(1);
353 const char *zCss = "";
354 const char *zClickOk = "e.ctrlKey";
 
355 blob_append(ob, zSafeNonce, -1);
356 blob_append_char(ob, '\n');
357 while( nArg>0 ){
358 int i;
359 for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){}
360 if( i==6 && strncmp(zArg, "center", 6)==0 ){
361 zCss = "display:block;margin:auto;";
 
362 }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){
363 zCss = "margin-left:4em;";
 
364 }else if( i==10 && strncmp(zArg, "float-left", 10)==0 ){
365 zCss = "float:left;padding=4em;";
 
366 }else if( i==11 && strncmp(zArg, "float-right", 11)==0 ){
367 zCss = "float:right;padding=4em;";
368 }else if( i==6 && strncmp(zArg, "toggle", 6)==0 ){
369 zClickOk = "1";
370 }
371 while( i<nArg && fossil_isspace(zArg[i]) ){ i++; }
372 zArg += i;
373 nArg -= i;
374 }
375 blob_appendf(ob, "<div id='svgid-%d'>\n", ++nSvg);
376 blob_appendf(ob, "<div class='pikchr-svg'");
377 blob_appendf(ob, " style='max-width:%dpx;%s'>\n", w, zCss);
378 blob_append(ob, zOut, -1);
379 blob_appendf(ob, "</div>\n");
 
380 blob_appendf(ob, "<pre class='hidden'><code>"
381 "%s</code></pre>\n", zIn);
382 blob_appendf(ob, "</div>\n");
383 blob_appendf(ob,
384 "<script nonce='%s'>\n"
385 "document.getElementById('svgid-%d').onclick=function(e){\n"
386 " if(%s){\n"
387 " for(var c of this.children){c.classList.toggle('hidden');}\n"
388 " }\n"
389 "}\n"
390 "</script>\n",
391 style_nonce(), nSvg, zClickOk);
392 blob_appendf(ob, "%s\n", zSafeNonce);
393 }else{
394 blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut);
395 }
396 fossil_free(zIn);
397

Keyboard Shortcuts

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