Fossil SCM

Changed th1 enable_htmlify call semantics. Fixed a bug introduced in [e7dcfc90f0] which entirely broke th1 rendering in skins.

stephan 2020-09-14 00:06 pikchr-th
Commit 7996a7940a7140bfb6171b7a79669a0765971217ab1c31975cb6fd6456989feb
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -228,10 +228,11 @@
228228
blob_read_from_file(&bIn, zInfile, ExtFILE);
229229
if(fTh1){
230230
Blob out = empty_blob;
231231
db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0)
232232
/* ^^^ needed for certain TH1 functions to work */;
233
+ /*Th_FossilInit(fThFlags);*/
233234
isErr = Th_RenderToBlob(blob_str(&bIn), &out, fThFlags)
234235
? 1 : 0;
235236
if(isErr){
236237
blob_reset(&bOut);
237238
bOut = out;
238239
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -228,10 +228,11 @@
228 blob_read_from_file(&bIn, zInfile, ExtFILE);
229 if(fTh1){
230 Blob out = empty_blob;
231 db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0)
232 /* ^^^ needed for certain TH1 functions to work */;
 
233 isErr = Th_RenderToBlob(blob_str(&bIn), &out, fThFlags)
234 ? 1 : 0;
235 if(isErr){
236 blob_reset(&bOut);
237 bOut = out;
238
--- src/pikchrshow.c
+++ src/pikchrshow.c
@@ -228,10 +228,11 @@
228 blob_read_from_file(&bIn, zInfile, ExtFILE);
229 if(fTh1){
230 Blob out = empty_blob;
231 db_find_and_open_repository(OPEN_ANY_SCHEMA | OPEN_OK_NOT_FOUND, 0)
232 /* ^^^ needed for certain TH1 functions to work */;
233 /*Th_FossilInit(fThFlags);*/
234 isErr = Th_RenderToBlob(blob_str(&bIn), &out, fThFlags)
235 ? 1 : 0;
236 if(isErr){
237 blob_reset(&bOut);
238 bOut = out;
239
+24 -15
--- src/th_main.c
+++ src/th_main.c
@@ -291,36 +291,45 @@
291291
}
292292
return rc;
293293
}
294294
295295
/*
296
-** TH1 command: enable_htmlify BOOLEAN
296
+** TH1 command: enable_htmlify ?BOOLEAN?
297297
**
298298
** Enable or disable the HTML escaping done by all output which
299299
** originates from TH1 (via sendText()).
300
+**
301
+** If passed no arguments it instead returns 0 or 1 to indicate the
302
+** current state.
300303
*/
301304
static int enableHtmlifyCmd(
302305
Th_Interp *interp,
303306
void *p,
304307
int argc,
305308
const char **argv,
306309
int *argl
307310
){
308
- int rc, buul;
309
- if( argc<2 || argc>3 ){
311
+ int rc = 0, buul;
312
+ if( argc>3 ){
310313
return Th_WrongNumArgs(interp,
311
- "enable_htmlify [TRACE_LABEL] BOOLEAN");
312
- }
313
- rc = Th_ToInt(interp, argv[argc-1], argl[argc-1], &buul);
314
- if( g.thTrace ){
315
- Th_Trace("enable_htmlify {%.*s} -> %d<br />\n",
316
- argl[1],argv[1],buul);
317
- }
318
- if(buul){
319
- g.th1Flags &= ~TH_INIT_NO_ENCODE;
320
- }else{
321
- g.th1Flags |= TH_INIT_NO_ENCODE;
314
+ "enable_htmlify [TRACE_LABEL] ?BOOLEAN?");
315
+ }
316
+ buul = (TH_INIT_NO_ENCODE & g.th1Flags) ? 0 : 1;
317
+ Th_SetResultInt(g.interp, buul);
318
+ if(argc>1){
319
+ if( g.thTrace ){
320
+ Th_Trace("enable_htmlify {%.*s} -> %d<br />\n",
321
+ argl[1],argv[1],buul);
322
+ }
323
+ rc = Th_ToInt(interp, argv[argc-1], argl[argc-1], &buul);
324
+ if(!rc){
325
+ if(buul){
326
+ g.th1Flags &= ~TH_INIT_NO_ENCODE;
327
+ }else{
328
+ g.th1Flags |= TH_INIT_NO_ENCODE;
329
+ }
330
+ }
322331
}
323332
return rc;
324333
}
325334
326335
/*
@@ -2737,11 +2746,11 @@
27372746
Blob * const origOut = Th_SetOutputBlob(pOut);
27382747
27392748
assert(0==(TH_R2B_MASK & TH_INIT_MASK) && "init/r2b mask conflict");
27402749
Th_FossilInit(mFlags & TH_INIT_MASK);
27412750
while( z[i] ){
2742
- if( 0!=(TH_R2B_NO_VARS & mFlags)
2751
+ if( 0==(TH_R2B_NO_VARS & mFlags)
27432752
&& z[i]=='$' && (n = validVarName(&z[i+1]))>0 ){
27442753
const char *zVar;
27452754
int nVar;
27462755
int encode = 1;
27472756
sendText(pOut,z, i, 0);
27482757
--- src/th_main.c
+++ src/th_main.c
@@ -291,36 +291,45 @@
291 }
292 return rc;
293 }
294
295 /*
296 ** TH1 command: enable_htmlify BOOLEAN
297 **
298 ** Enable or disable the HTML escaping done by all output which
299 ** originates from TH1 (via sendText()).
 
 
 
300 */
301 static int enableHtmlifyCmd(
302 Th_Interp *interp,
303 void *p,
304 int argc,
305 const char **argv,
306 int *argl
307 ){
308 int rc, buul;
309 if( argc<2 || argc>3 ){
310 return Th_WrongNumArgs(interp,
311 "enable_htmlify [TRACE_LABEL] BOOLEAN");
312 }
313 rc = Th_ToInt(interp, argv[argc-1], argl[argc-1], &buul);
314 if( g.thTrace ){
315 Th_Trace("enable_htmlify {%.*s} -> %d<br />\n",
316 argl[1],argv[1],buul);
317 }
318 if(buul){
319 g.th1Flags &= ~TH_INIT_NO_ENCODE;
320 }else{
321 g.th1Flags |= TH_INIT_NO_ENCODE;
 
 
 
 
 
 
322 }
323 return rc;
324 }
325
326 /*
@@ -2737,11 +2746,11 @@
2737 Blob * const origOut = Th_SetOutputBlob(pOut);
2738
2739 assert(0==(TH_R2B_MASK & TH_INIT_MASK) && "init/r2b mask conflict");
2740 Th_FossilInit(mFlags & TH_INIT_MASK);
2741 while( z[i] ){
2742 if( 0!=(TH_R2B_NO_VARS & mFlags)
2743 && z[i]=='$' && (n = validVarName(&z[i+1]))>0 ){
2744 const char *zVar;
2745 int nVar;
2746 int encode = 1;
2747 sendText(pOut,z, i, 0);
2748
--- src/th_main.c
+++ src/th_main.c
@@ -291,36 +291,45 @@
291 }
292 return rc;
293 }
294
295 /*
296 ** TH1 command: enable_htmlify ?BOOLEAN?
297 **
298 ** Enable or disable the HTML escaping done by all output which
299 ** originates from TH1 (via sendText()).
300 **
301 ** If passed no arguments it instead returns 0 or 1 to indicate the
302 ** current state.
303 */
304 static int enableHtmlifyCmd(
305 Th_Interp *interp,
306 void *p,
307 int argc,
308 const char **argv,
309 int *argl
310 ){
311 int rc = 0, buul;
312 if( argc>3 ){
313 return Th_WrongNumArgs(interp,
314 "enable_htmlify [TRACE_LABEL] ?BOOLEAN?");
315 }
316 buul = (TH_INIT_NO_ENCODE & g.th1Flags) ? 0 : 1;
317 Th_SetResultInt(g.interp, buul);
318 if(argc>1){
319 if( g.thTrace ){
320 Th_Trace("enable_htmlify {%.*s} -> %d<br />\n",
321 argl[1],argv[1],buul);
322 }
323 rc = Th_ToInt(interp, argv[argc-1], argl[argc-1], &buul);
324 if(!rc){
325 if(buul){
326 g.th1Flags &= ~TH_INIT_NO_ENCODE;
327 }else{
328 g.th1Flags |= TH_INIT_NO_ENCODE;
329 }
330 }
331 }
332 return rc;
333 }
334
335 /*
@@ -2737,11 +2746,11 @@
2746 Blob * const origOut = Th_SetOutputBlob(pOut);
2747
2748 assert(0==(TH_R2B_MASK & TH_INIT_MASK) && "init/r2b mask conflict");
2749 Th_FossilInit(mFlags & TH_INIT_MASK);
2750 while( z[i] ){
2751 if( 0==(TH_R2B_NO_VARS & mFlags)
2752 && z[i]=='$' && (n = validVarName(&z[i+1]))>0 ){
2753 const char *zVar;
2754 int nVar;
2755 int encode = 1;
2756 sendText(pOut,z, i, 0);
2757
+12 -7
--- www/th1.md
+++ www/th1.md
@@ -354,19 +354,23 @@
354354
time zone configured for the repository).
355355
356356
<a id="enable_htmlify"></a>TH1 enable\_htmlify Command
357357
------------------------------------------------------
358358
359
+ * enable\_htmlify
359360
* enable\_htmlify ?TRACE-LABEL? BOOLEAN
360361
361362
By default, certain output from `puts` and similar commands is escaped
362
-for HTML. That feature can be toggled off by passing `0` to this
363
-command and re-enabled by passing any non-0 value. The optional
364
-`TRACE-LABEL` argument causes the TH1 tracing output (if enabled) to
365
-add a marker when this command is invoked, and includes that label and
366
-the boolean argument's value in the trace. If tracing is disabled,
367
-that argument has no effect.
363
+for HTML. The first call form returns the current state of that
364
+feature: `1` for on and `0` for off. The second call form enables
365
+(non-0) or disables (0) that feature and returns the *pre-call* state
366
+of that feature (so that a second call can pass that value to restore
367
+it to its previous state). The optional `TRACE-LABEL` argument causes
368
+the TH1 tracing output (if enabled) to add a marker when the second
369
+form of this command is invoked, and includes that label and the
370
+boolean argument's value in the trace. If tracing is disabled, that
371
+argument has no effect.
368372
369373
370374
<a id="enable_output"></a>TH1 enable\_output Command
371375
------------------------------------------------------
372376
@@ -526,11 +530,12 @@
526530
<a id="puts"></a>TH1 puts Command
527531
-----------------------------------
528532
529533
* puts STRING
530534
531
-Outputs the STRING unchanged.
535
+Outputs the STRING unchanged, where "unchanged" might, depending on
536
+the context, mean "with some characters escaped for HTML."
532537
533538
<a id="query"></a>TH1 query Command
534539
-------------------------------------
535540
536541
* query ?-nocomplain? SQL CODE
537542
--- www/th1.md
+++ www/th1.md
@@ -354,19 +354,23 @@
354 time zone configured for the repository).
355
356 <a id="enable_htmlify"></a>TH1 enable\_htmlify Command
357 ------------------------------------------------------
358
 
359 * enable\_htmlify ?TRACE-LABEL? BOOLEAN
360
361 By default, certain output from `puts` and similar commands is escaped
362 for HTML. That feature can be toggled off by passing `0` to this
363 command and re-enabled by passing any non-0 value. The optional
364 `TRACE-LABEL` argument causes the TH1 tracing output (if enabled) to
365 add a marker when this command is invoked, and includes that label and
366 the boolean argument's value in the trace. If tracing is disabled,
367 that argument has no effect.
 
 
 
368
369
370 <a id="enable_output"></a>TH1 enable\_output Command
371 ------------------------------------------------------
372
@@ -526,11 +530,12 @@
526 <a id="puts"></a>TH1 puts Command
527 -----------------------------------
528
529 * puts STRING
530
531 Outputs the STRING unchanged.
 
532
533 <a id="query"></a>TH1 query Command
534 -------------------------------------
535
536 * query ?-nocomplain? SQL CODE
537
--- www/th1.md
+++ www/th1.md
@@ -354,19 +354,23 @@
354 time zone configured for the repository).
355
356 <a id="enable_htmlify"></a>TH1 enable\_htmlify Command
357 ------------------------------------------------------
358
359 * enable\_htmlify
360 * enable\_htmlify ?TRACE-LABEL? BOOLEAN
361
362 By default, certain output from `puts` and similar commands is escaped
363 for HTML. The first call form returns the current state of that
364 feature: `1` for on and `0` for off. The second call form enables
365 (non-0) or disables (0) that feature and returns the *pre-call* state
366 of that feature (so that a second call can pass that value to restore
367 it to its previous state). The optional `TRACE-LABEL` argument causes
368 the TH1 tracing output (if enabled) to add a marker when the second
369 form of this command is invoked, and includes that label and the
370 boolean argument's value in the trace. If tracing is disabled, that
371 argument has no effect.
372
373
374 <a id="enable_output"></a>TH1 enable\_output Command
375 ------------------------------------------------------
376
@@ -526,11 +530,12 @@
530 <a id="puts"></a>TH1 puts Command
531 -----------------------------------
532
533 * puts STRING
534
535 Outputs the STRING unchanged, where "unchanged" might, depending on
536 the context, mean "with some characters escaped for HTML."
537
538 <a id="query"></a>TH1 query Command
539 -------------------------------------
540
541 * query ?-nocomplain? SQL CODE
542

Keyboard Shortcuts

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