Fossil SCM
Experimental double-click to toggle between SVG and pikchr source.
Commit
3c786c6fc3603d8204708750fffc981f5d9a96c1642917c31853ef6d5cbd3047
Parent
5b93a4da7304df3…
1 file changed
+68
+68
| --- src/markdown_html.c | ||
| +++ src/markdown_html.c | ||
| @@ -333,10 +333,11 @@ | ||
| 333 | 333 | } |
| 334 | 334 | BLOB_APPEND_LITERAL(ob, "</a>"); |
| 335 | 335 | return 1; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | +#if 0 | |
| 338 | 339 | /* |
| 339 | 340 | ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that |
| 340 | 341 | ** text and insert the result in place of the original. |
| 341 | 342 | */ |
| 342 | 343 | void pikchr_to_html( |
| @@ -372,10 +373,77 @@ | ||
| 372 | 373 | blob_append(&bSrc, zSrc, nSrc) |
| 373 | 374 | /*have to dupe input to ensure a NUL-terminated source string */; |
| 374 | 375 | pikchr_process(blob_str(&bSrc), pikFlags, 0, ob); |
| 375 | 376 | blob_reset(&bSrc); |
| 376 | 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 | + | |
| 377 | 445 | |
| 378 | 446 | |
| 379 | 447 | /* Invoked for `...` blocks where there are nSep grave accents in a |
| 380 | 448 | ** row that serve as the delimiter. According to CommonMark: |
| 381 | 449 | ** |
| 382 | 450 |
| --- 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 |