Fossil SCM
Make use of the new PIKCHR_INCLUDE_SOURCE flag via /pikchrshow and the pikchr CLI command.
Commit
7da8813eefa123d2c68b9f0542f77c665d10bc178075495b56118bcdd4f7cc53
Parent
041390d3f88afd4…
1 file changed
+22
-15
+22
-15
| --- src/pikchrshow.c | ||
| +++ src/pikchrshow.c | ||
| @@ -27,10 +27,11 @@ | ||
| 27 | 27 | #define PIKCHR_PROCESS_TH1 0x01 |
| 28 | 28 | #define PIKCHR_PROCESS_TH1_NOSVG 0x02 |
| 29 | 29 | #define PIKCHR_PROCESS_DIV 0x04 |
| 30 | 30 | #define PIKCHR_PROCESS_NONCE 0x08 |
| 31 | 31 | #define PIKCHR_PROCESS_ERR_PRE 0x10 |
| 32 | +#define PIKCHR_PROCESS_NO_SRC 0x20 | |
| 32 | 33 | #endif |
| 33 | 34 | |
| 34 | 35 | /* |
| 35 | 36 | ** Processes a pikchr script, optionally with embedded TH1. zIn is the |
| 36 | 37 | ** input script. pikFlags may be a bitmask of any of the |
| @@ -50,12 +51,17 @@ | ||
| 50 | 51 | ** |
| 51 | 52 | ** - PIKCHR_PROCESS_TH1_NOSVG means that processing stops after the |
| 52 | 53 | ** TH1 step, thus the output will be (presumably) a |
| 53 | 54 | ** TH1-generated/processed pikchr script, and not an SVG. If this flag |
| 54 | 55 | ** is set, PIKCHR_PROCESS_TH1 is assumed even if it is not specified. |
| 55 | -** The remaining flags listed below are ignored if this flag is | |
| 56 | -** specified. | |
| 56 | +** | |
| 57 | +** The remaining flags listed below are ignored if | |
| 58 | +** PIKCHR_PROCESS_TH1_NOSVG is specified: | |
| 59 | +** | |
| 60 | +** - PIKCHR_PROCESS_NO_SRC: by default the contents of zIn are stored | |
| 61 | +** in the resulting SVG content, as part of the image metadata. That | |
| 62 | +** is suppressed if this flag is set. | |
| 57 | 63 | ** |
| 58 | 64 | ** - PIKCHR_PROCESS_DIV: if set, the SVG result is wrapped in a DIV |
| 59 | 65 | ** element which specifies a max-width style value based on the SVG's |
| 60 | 66 | ** calculated size. |
| 61 | 67 | ** |
| @@ -94,12 +100,14 @@ | ||
| 94 | 100 | blob_append(pOut, blob_str(&bIn), blob_size(&bIn)); |
| 95 | 101 | }else{ |
| 96 | 102 | int w = 0, h = 0; |
| 97 | 103 | const char * zContent = blob_str(&bIn); |
| 98 | 104 | char *zOut; |
| 99 | - | |
| 100 | - zOut = pikchr(zContent, "pikchr", 0, &w, &h); | |
| 105 | + const unsigned int pikFlags2 = (PIKCHR_PROCESS_NO_SRC & pikFlags) | |
| 106 | + ? 0 : PIKCHR_INCLUDE_SOURCE; | |
| 107 | + | |
| 108 | + zOut = pikchr(zContent, "pikchr", pikFlags2, &w, &h); | |
| 101 | 109 | if( w>0 && h>0 ){ |
| 102 | 110 | const char *zNonce = (PIKCHR_PROCESS_NONCE & pikFlags) |
| 103 | 111 | ? safe_html_nonce(1) : 0; |
| 104 | 112 | if(zNonce){ |
| 105 | 113 | blob_append(pOut, zNonce, -1); |
| @@ -259,20 +267,15 @@ | ||
| 259 | 267 | CX("<legend></legend>" |
| 260 | 268 | /* Reminder: Firefox does not properly flexbox a LEGEND |
| 261 | 269 | element, always flowing it in column mode. */); |
| 262 | 270 | CX("<div id='pikchrshow-output'>"); |
| 263 | 271 | if(*zContent){ |
| 264 | - int w = 0, h = 0; | |
| 265 | - char *zOut = pikchr(zContent, "pikchr", 0, &w, &h); | |
| 266 | - if( w>0 && h>0 ){ | |
| 267 | - const char *zNonce = safe_html_nonce(1); | |
| 268 | - CX("%s<div style='max-width:%dpx;'>\n%s</div>%s", | |
| 269 | - zNonce, w, zOut, zNonce); | |
| 270 | - }else{ | |
| 271 | - CX("<pre>\n%s\n</pre>\n", zOut); | |
| 272 | - } | |
| 273 | - fossil_free(zOut); | |
| 272 | + Blob out = empty_blob; | |
| 273 | + pikchr_process(zContent, PIKCHR_PROCESS_ERR_PRE | |
| 274 | + | PIKCHR_PROCESS_DIV, 0, &out); | |
| 275 | + CX("%b", &out); | |
| 276 | + blob_reset(&out); | |
| 274 | 277 | } CX("</div>"/*#pikchrshow-output*/); |
| 275 | 278 | } CX("</fieldset>"/*#pikchrshow-output-wrapper*/); |
| 276 | 279 | } CX("</div>"/*sbs-wrapper*/); |
| 277 | 280 | if(!builtin_bundle_all_fossil_js_apis()){ |
| 278 | 281 | builtin_emit_fossil_js_apis("dom", "fetch", "copybutton", |
| @@ -298,10 +301,13 @@ | ||
| 298 | 301 | ** |
| 299 | 302 | ** -div On success, adds a DIV wrapper around the |
| 300 | 303 | ** resulting SVG output which limits its max-width to |
| 301 | 304 | ** its computed maximum ideal size, in order to mimic |
| 302 | 305 | ** how fossil's web-based components work. |
| 306 | +** | |
| 307 | +** -svg-src Stores the input pikchr's source code in the SVG's | |
| 308 | +** metadata. | |
| 303 | 309 | ** |
| 304 | 310 | ** -th Process the input using TH1 before passing it to pikchr. |
| 305 | 311 | ** |
| 306 | 312 | ** -th-novar Disable $var and $<var> TH1 processing. Use this if the |
| 307 | 313 | ** pikchr script uses '$' for its own purposes and that |
| @@ -338,11 +344,12 @@ | ||
| 338 | 344 | const char * zOutfile = "-"; |
| 339 | 345 | const int fWithDiv = find_option("div",0,0)!=0; |
| 340 | 346 | const int fTh1 = find_option("th",0,0)!=0; |
| 341 | 347 | const int fNosvg = find_option("th-nosvg",0,0)!=0; |
| 342 | 348 | int isErr = 0; |
| 343 | - int pikFlags = 0; | |
| 349 | + int pikFlags = find_option("svg-src",0,0)!=0 | |
| 350 | + ? 0 : PIKCHR_PROCESS_NO_SRC; | |
| 344 | 351 | u32 fThFlags = TH_INIT_NO_ENCODE |
| 345 | 352 | | (find_option("th-novar",0,0)!=0 ? TH_R2B_NO_VARS : 0); |
| 346 | 353 | |
| 347 | 354 | Th_InitTraceLog()/*processes -th-trace flag*/; |
| 348 | 355 | verify_all_options(); |
| 349 | 356 |
| --- src/pikchrshow.c | |
| +++ src/pikchrshow.c | |
| @@ -27,10 +27,11 @@ | |
| 27 | #define PIKCHR_PROCESS_TH1 0x01 |
| 28 | #define PIKCHR_PROCESS_TH1_NOSVG 0x02 |
| 29 | #define PIKCHR_PROCESS_DIV 0x04 |
| 30 | #define PIKCHR_PROCESS_NONCE 0x08 |
| 31 | #define PIKCHR_PROCESS_ERR_PRE 0x10 |
| 32 | #endif |
| 33 | |
| 34 | /* |
| 35 | ** Processes a pikchr script, optionally with embedded TH1. zIn is the |
| 36 | ** input script. pikFlags may be a bitmask of any of the |
| @@ -50,12 +51,17 @@ | |
| 50 | ** |
| 51 | ** - PIKCHR_PROCESS_TH1_NOSVG means that processing stops after the |
| 52 | ** TH1 step, thus the output will be (presumably) a |
| 53 | ** TH1-generated/processed pikchr script, and not an SVG. If this flag |
| 54 | ** is set, PIKCHR_PROCESS_TH1 is assumed even if it is not specified. |
| 55 | ** The remaining flags listed below are ignored if this flag is |
| 56 | ** specified. |
| 57 | ** |
| 58 | ** - PIKCHR_PROCESS_DIV: if set, the SVG result is wrapped in a DIV |
| 59 | ** element which specifies a max-width style value based on the SVG's |
| 60 | ** calculated size. |
| 61 | ** |
| @@ -94,12 +100,14 @@ | |
| 94 | blob_append(pOut, blob_str(&bIn), blob_size(&bIn)); |
| 95 | }else{ |
| 96 | int w = 0, h = 0; |
| 97 | const char * zContent = blob_str(&bIn); |
| 98 | char *zOut; |
| 99 | |
| 100 | zOut = pikchr(zContent, "pikchr", 0, &w, &h); |
| 101 | if( w>0 && h>0 ){ |
| 102 | const char *zNonce = (PIKCHR_PROCESS_NONCE & pikFlags) |
| 103 | ? safe_html_nonce(1) : 0; |
| 104 | if(zNonce){ |
| 105 | blob_append(pOut, zNonce, -1); |
| @@ -259,20 +267,15 @@ | |
| 259 | CX("<legend></legend>" |
| 260 | /* Reminder: Firefox does not properly flexbox a LEGEND |
| 261 | element, always flowing it in column mode. */); |
| 262 | CX("<div id='pikchrshow-output'>"); |
| 263 | if(*zContent){ |
| 264 | int w = 0, h = 0; |
| 265 | char *zOut = pikchr(zContent, "pikchr", 0, &w, &h); |
| 266 | if( w>0 && h>0 ){ |
| 267 | const char *zNonce = safe_html_nonce(1); |
| 268 | CX("%s<div style='max-width:%dpx;'>\n%s</div>%s", |
| 269 | zNonce, w, zOut, zNonce); |
| 270 | }else{ |
| 271 | CX("<pre>\n%s\n</pre>\n", zOut); |
| 272 | } |
| 273 | fossil_free(zOut); |
| 274 | } CX("</div>"/*#pikchrshow-output*/); |
| 275 | } CX("</fieldset>"/*#pikchrshow-output-wrapper*/); |
| 276 | } CX("</div>"/*sbs-wrapper*/); |
| 277 | if(!builtin_bundle_all_fossil_js_apis()){ |
| 278 | builtin_emit_fossil_js_apis("dom", "fetch", "copybutton", |
| @@ -298,10 +301,13 @@ | |
| 298 | ** |
| 299 | ** -div On success, adds a DIV wrapper around the |
| 300 | ** resulting SVG output which limits its max-width to |
| 301 | ** its computed maximum ideal size, in order to mimic |
| 302 | ** how fossil's web-based components work. |
| 303 | ** |
| 304 | ** -th Process the input using TH1 before passing it to pikchr. |
| 305 | ** |
| 306 | ** -th-novar Disable $var and $<var> TH1 processing. Use this if the |
| 307 | ** pikchr script uses '$' for its own purposes and that |
| @@ -338,11 +344,12 @@ | |
| 338 | const char * zOutfile = "-"; |
| 339 | const int fWithDiv = find_option("div",0,0)!=0; |
| 340 | const int fTh1 = find_option("th",0,0)!=0; |
| 341 | const int fNosvg = find_option("th-nosvg",0,0)!=0; |
| 342 | int isErr = 0; |
| 343 | int pikFlags = 0; |
| 344 | u32 fThFlags = TH_INIT_NO_ENCODE |
| 345 | | (find_option("th-novar",0,0)!=0 ? TH_R2B_NO_VARS : 0); |
| 346 | |
| 347 | Th_InitTraceLog()/*processes -th-trace flag*/; |
| 348 | verify_all_options(); |
| 349 |
| --- src/pikchrshow.c | |
| +++ src/pikchrshow.c | |
| @@ -27,10 +27,11 @@ | |
| 27 | #define PIKCHR_PROCESS_TH1 0x01 |
| 28 | #define PIKCHR_PROCESS_TH1_NOSVG 0x02 |
| 29 | #define PIKCHR_PROCESS_DIV 0x04 |
| 30 | #define PIKCHR_PROCESS_NONCE 0x08 |
| 31 | #define PIKCHR_PROCESS_ERR_PRE 0x10 |
| 32 | #define PIKCHR_PROCESS_NO_SRC 0x20 |
| 33 | #endif |
| 34 | |
| 35 | /* |
| 36 | ** Processes a pikchr script, optionally with embedded TH1. zIn is the |
| 37 | ** input script. pikFlags may be a bitmask of any of the |
| @@ -50,12 +51,17 @@ | |
| 51 | ** |
| 52 | ** - PIKCHR_PROCESS_TH1_NOSVG means that processing stops after the |
| 53 | ** TH1 step, thus the output will be (presumably) a |
| 54 | ** TH1-generated/processed pikchr script, and not an SVG. If this flag |
| 55 | ** is set, PIKCHR_PROCESS_TH1 is assumed even if it is not specified. |
| 56 | ** |
| 57 | ** The remaining flags listed below are ignored if |
| 58 | ** PIKCHR_PROCESS_TH1_NOSVG is specified: |
| 59 | ** |
| 60 | ** - PIKCHR_PROCESS_NO_SRC: by default the contents of zIn are stored |
| 61 | ** in the resulting SVG content, as part of the image metadata. That |
| 62 | ** is suppressed if this flag is set. |
| 63 | ** |
| 64 | ** - PIKCHR_PROCESS_DIV: if set, the SVG result is wrapped in a DIV |
| 65 | ** element which specifies a max-width style value based on the SVG's |
| 66 | ** calculated size. |
| 67 | ** |
| @@ -94,12 +100,14 @@ | |
| 100 | blob_append(pOut, blob_str(&bIn), blob_size(&bIn)); |
| 101 | }else{ |
| 102 | int w = 0, h = 0; |
| 103 | const char * zContent = blob_str(&bIn); |
| 104 | char *zOut; |
| 105 | const unsigned int pikFlags2 = (PIKCHR_PROCESS_NO_SRC & pikFlags) |
| 106 | ? 0 : PIKCHR_INCLUDE_SOURCE; |
| 107 | |
| 108 | zOut = pikchr(zContent, "pikchr", pikFlags2, &w, &h); |
| 109 | if( w>0 && h>0 ){ |
| 110 | const char *zNonce = (PIKCHR_PROCESS_NONCE & pikFlags) |
| 111 | ? safe_html_nonce(1) : 0; |
| 112 | if(zNonce){ |
| 113 | blob_append(pOut, zNonce, -1); |
| @@ -259,20 +267,15 @@ | |
| 267 | CX("<legend></legend>" |
| 268 | /* Reminder: Firefox does not properly flexbox a LEGEND |
| 269 | element, always flowing it in column mode. */); |
| 270 | CX("<div id='pikchrshow-output'>"); |
| 271 | if(*zContent){ |
| 272 | Blob out = empty_blob; |
| 273 | pikchr_process(zContent, PIKCHR_PROCESS_ERR_PRE |
| 274 | | PIKCHR_PROCESS_DIV, 0, &out); |
| 275 | CX("%b", &out); |
| 276 | blob_reset(&out); |
| 277 | } CX("</div>"/*#pikchrshow-output*/); |
| 278 | } CX("</fieldset>"/*#pikchrshow-output-wrapper*/); |
| 279 | } CX("</div>"/*sbs-wrapper*/); |
| 280 | if(!builtin_bundle_all_fossil_js_apis()){ |
| 281 | builtin_emit_fossil_js_apis("dom", "fetch", "copybutton", |
| @@ -298,10 +301,13 @@ | |
| 301 | ** |
| 302 | ** -div On success, adds a DIV wrapper around the |
| 303 | ** resulting SVG output which limits its max-width to |
| 304 | ** its computed maximum ideal size, in order to mimic |
| 305 | ** how fossil's web-based components work. |
| 306 | ** |
| 307 | ** -svg-src Stores the input pikchr's source code in the SVG's |
| 308 | ** metadata. |
| 309 | ** |
| 310 | ** -th Process the input using TH1 before passing it to pikchr. |
| 311 | ** |
| 312 | ** -th-novar Disable $var and $<var> TH1 processing. Use this if the |
| 313 | ** pikchr script uses '$' for its own purposes and that |
| @@ -338,11 +344,12 @@ | |
| 344 | const char * zOutfile = "-"; |
| 345 | const int fWithDiv = find_option("div",0,0)!=0; |
| 346 | const int fTh1 = find_option("th",0,0)!=0; |
| 347 | const int fNosvg = find_option("th-nosvg",0,0)!=0; |
| 348 | int isErr = 0; |
| 349 | int pikFlags = find_option("svg-src",0,0)!=0 |
| 350 | ? 0 : PIKCHR_PROCESS_NO_SRC; |
| 351 | u32 fThFlags = TH_INIT_NO_ENCODE |
| 352 | | (find_option("th-novar",0,0)!=0 ? TH_R2B_NO_VARS : 0); |
| 353 | |
| 354 | Th_InitTraceLog()/*processes -th-trace flag*/; |
| 355 | verify_all_options(); |
| 356 |