Fossil SCM

Make use of the new PIKCHR_INCLUDE_SOURCE flag via /pikchrshow and the pikchr CLI command.

stephan 2020-09-15 13:42 trunk
Commit 7da8813eefa123d2c68b9f0542f77c665d10bc178075495b56118bcdd4f7cc53
1 file changed +22 -15
+22 -15
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -27,10 +27,11 @@
2727
#define PIKCHR_PROCESS_TH1 0x01
2828
#define PIKCHR_PROCESS_TH1_NOSVG 0x02
2929
#define PIKCHR_PROCESS_DIV 0x04
3030
#define PIKCHR_PROCESS_NONCE 0x08
3131
#define PIKCHR_PROCESS_ERR_PRE 0x10
32
+#define PIKCHR_PROCESS_NO_SRC 0x20
3233
#endif
3334
3435
/*
3536
** Processes a pikchr script, optionally with embedded TH1. zIn is the
3637
** input script. pikFlags may be a bitmask of any of the
@@ -50,12 +51,17 @@
5051
**
5152
** - PIKCHR_PROCESS_TH1_NOSVG means that processing stops after the
5253
** TH1 step, thus the output will be (presumably) a
5354
** TH1-generated/processed pikchr script, and not an SVG. If this flag
5455
** 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.
5763
**
5864
** - PIKCHR_PROCESS_DIV: if set, the SVG result is wrapped in a DIV
5965
** element which specifies a max-width style value based on the SVG's
6066
** calculated size.
6167
**
@@ -94,12 +100,14 @@
94100
blob_append(pOut, blob_str(&bIn), blob_size(&bIn));
95101
}else{
96102
int w = 0, h = 0;
97103
const char * zContent = blob_str(&bIn);
98104
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);
101109
if( w>0 && h>0 ){
102110
const char *zNonce = (PIKCHR_PROCESS_NONCE & pikFlags)
103111
? safe_html_nonce(1) : 0;
104112
if(zNonce){
105113
blob_append(pOut, zNonce, -1);
@@ -259,20 +267,15 @@
259267
CX("<legend></legend>"
260268
/* Reminder: Firefox does not properly flexbox a LEGEND
261269
element, always flowing it in column mode. */);
262270
CX("<div id='pikchrshow-output'>");
263271
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);
274277
} CX("</div>"/*#pikchrshow-output*/);
275278
} CX("</fieldset>"/*#pikchrshow-output-wrapper*/);
276279
} CX("</div>"/*sbs-wrapper*/);
277280
if(!builtin_bundle_all_fossil_js_apis()){
278281
builtin_emit_fossil_js_apis("dom", "fetch", "copybutton",
@@ -298,10 +301,13 @@
298301
**
299302
** -div On success, adds a DIV wrapper around the
300303
** resulting SVG output which limits its max-width to
301304
** its computed maximum ideal size, in order to mimic
302305
** how fossil's web-based components work.
306
+**
307
+** -svg-src Stores the input pikchr's source code in the SVG's
308
+** metadata.
303309
**
304310
** -th Process the input using TH1 before passing it to pikchr.
305311
**
306312
** -th-novar Disable $var and $<var> TH1 processing. Use this if the
307313
** pikchr script uses '$' for its own purposes and that
@@ -338,11 +344,12 @@
338344
const char * zOutfile = "-";
339345
const int fWithDiv = find_option("div",0,0)!=0;
340346
const int fTh1 = find_option("th",0,0)!=0;
341347
const int fNosvg = find_option("th-nosvg",0,0)!=0;
342348
int isErr = 0;
343
- int pikFlags = 0;
349
+ int pikFlags = find_option("svg-src",0,0)!=0
350
+ ? 0 : PIKCHR_PROCESS_NO_SRC;
344351
u32 fThFlags = TH_INIT_NO_ENCODE
345352
| (find_option("th-novar",0,0)!=0 ? TH_R2B_NO_VARS : 0);
346353
347354
Th_InitTraceLog()/*processes -th-trace flag*/;
348355
verify_all_options();
349356
--- 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

Keyboard Shortcuts

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