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.
Commit
d88444e265f3f78f72fe5c3fd34c1e191d7ff6a32954f8f32c8a40b9360c2b96
Parent
5c92bbfca7e3675…
1 file changed
+12
-15
+12
-15
| --- src/markdown_html.c | ||
| +++ src/markdown_html.c | ||
| @@ -348,52 +348,49 @@ | ||
| 348 | 348 | char *zIn = fossil_strndup(zSrc, nSrc); |
| 349 | 349 | char *zOut = pikchr(zIn, "pikchr", 0, &w, &h); |
| 350 | 350 | if( w>0 && h>0 ){ |
| 351 | 351 | static int nSvg = 0; |
| 352 | 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); | |
| 353 | + const char *zCss = ""; | |
| 354 | + const char *zClickOk = "e.ctrlKey"; | |
| 356 | 355 | blob_append(ob, zSafeNonce, -1); |
| 357 | 356 | blob_append_char(ob, '\n'); |
| 358 | 357 | while( nArg>0 ){ |
| 359 | 358 | int i; |
| 360 | 359 | for(i=0; i<nArg && !fossil_isspace(zArg[i]); i++){} |
| 361 | 360 | if( i==6 && strncmp(zArg, "center", 6)==0 ){ |
| 362 | - blob_appendf(&css, "display:block;margin:auto;"); | |
| 363 | - break; | |
| 361 | + zCss = "display:block;margin:auto;"; | |
| 364 | 362 | }else if( i==6 && strncmp(zArg, "indent", 6)==0 ){ |
| 365 | - blob_appendf(&css, "margin-left:4em;"); | |
| 366 | - break; | |
| 363 | + zCss = "margin-left:4em;"; | |
| 367 | 364 | }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;"; | |
| 370 | 366 | }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"; | |
| 373 | 370 | } |
| 374 | 371 | while( i<nArg && fossil_isspace(zArg[i]) ){ i++; } |
| 375 | 372 | zArg += i; |
| 376 | 373 | nArg -= i; |
| 377 | 374 | } |
| 378 | 375 | 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); | |
| 380 | 378 | blob_append(ob, zOut, -1); |
| 381 | 379 | blob_appendf(ob, "</div>\n"); |
| 382 | - blob_reset(&css); | |
| 383 | 380 | blob_appendf(ob, "<pre class='hidden'><code>" |
| 384 | 381 | "%s</code></pre>\n", zIn); |
| 385 | 382 | blob_appendf(ob, "</div>\n"); |
| 386 | 383 | blob_appendf(ob, |
| 387 | 384 | "<script nonce='%s'>\n" |
| 388 | 385 | "document.getElementById('svgid-%d').onclick=function(e){\n" |
| 389 | - " if(e.ctrlKey){\n" | |
| 386 | + " if(%s){\n" | |
| 390 | 387 | " for(var c of this.children){c.classList.toggle('hidden');}\n" |
| 391 | 388 | " }\n" |
| 392 | 389 | "}\n" |
| 393 | 390 | "</script>\n", |
| 394 | - style_nonce(), nSvg); | |
| 391 | + style_nonce(), nSvg, zClickOk); | |
| 395 | 392 | blob_appendf(ob, "%s\n", zSafeNonce); |
| 396 | 393 | }else{ |
| 397 | 394 | blob_appendf(ob, "<pre>\n%s\n</pre>\n", zOut); |
| 398 | 395 | } |
| 399 | 396 | fossil_free(zIn); |
| 400 | 397 |
| --- 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 |