Fossil SCM

For the console-based timeline, run comment text through wiki_convert() and then through html_to_plaintext() before display, in order to translate markup.

drh 2025-03-11 10:44 trunk
Commit 6ab9994de6a5b3ca385258a77b520414e4cd00837228702fb6dd070928f7142e
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -235,10 +235,11 @@
235235
char *zSql = sqlite3_mprintf("ATTACH %Q AS 'configdb' KEY ''",
236236
g.zConfigDbName);
237237
sqlite3_exec(db, zSql, 0, 0, 0);
238238
sqlite3_free(zSql);
239239
}
240
+ (void)timeline_query_for_tty(); /* Registers wiki_to_text() as side-effect */
240241
/* Arrange to trace close operations so that static prepared statements
241242
** will get cleaned up when the shell closes the database connection */
242243
if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
243244
sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
244245
db_protect_only(PROTECT_NONE);
245246
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -235,10 +235,11 @@
235 char *zSql = sqlite3_mprintf("ATTACH %Q AS 'configdb' KEY ''",
236 g.zConfigDbName);
237 sqlite3_exec(db, zSql, 0, 0, 0);
238 sqlite3_free(zSql);
239 }
 
240 /* Arrange to trace close operations so that static prepared statements
241 ** will get cleaned up when the shell closes the database connection */
242 if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
243 sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
244 db_protect_only(PROTECT_NONE);
245
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -235,10 +235,11 @@
235 char *zSql = sqlite3_mprintf("ATTACH %Q AS 'configdb' KEY ''",
236 g.zConfigDbName);
237 sqlite3_exec(db, zSql, 0, 0, 0);
238 sqlite3_free(zSql);
239 }
240 (void)timeline_query_for_tty(); /* Registers wiki_to_text() as side-effect */
241 /* Arrange to trace close operations so that static prepared statements
242 ** will get cleaned up when the shell closes the database connection */
243 if( g.fSqlTrace ) mTrace |= SQLITE_TRACE_PROFILE;
244 sqlite3_trace_v2(db, mTrace, db_sql_trace, 0);
245 db_protect_only(PROTECT_NONE);
246
+38 -1
--- src/timeline.c
+++ src/timeline.c
@@ -3435,22 +3435,54 @@
34353435
fossil_print("+++ no more data (%d) +++\n", nEntry);
34363436
}
34373437
}
34383438
if( fchngQueryInit ) db_finalize(&fchngQuery);
34393439
}
3440
+
3441
+/*
3442
+** wiki_to_text(TEXT)
3443
+**
3444
+** Return a plain-text rendering of Fossil-Wiki TEXT.
3445
+*/
3446
+static void wiki_to_text_sqlfunc(
3447
+ sqlite3_context *context,
3448
+ int argc,
3449
+ sqlite3_value **argv
3450
+){
3451
+ const char *zIn, *zOut;
3452
+ int nIn, nOut;
3453
+ Blob in, html, txt;
3454
+ zIn = (const char*)sqlite3_value_text(argv[0]);
3455
+ if( zIn==0 ) return;
3456
+ nIn = sqlite3_value_bytes(argv[0]);
3457
+ blob_init(&in, zIn, nIn);
3458
+ blob_init(&html, 0, 0);
3459
+ wiki_convert(&in, &html, WIKI_INLINE);
3460
+ blob_reset(&in);
3461
+ blob_init(&txt, 0, 0);
3462
+ html_to_plaintext(blob_str(&html), &txt);
3463
+ blob_reset(&html);
3464
+ nOut = blob_size(&txt);
3465
+ zOut = blob_str(&txt);
3466
+ while( fossil_isspace(zOut[0]) ){ zOut++; nOut--; }
3467
+ while( nOut>0 && fossil_isspace(zOut[nOut-1]) ){ nOut--; }
3468
+ sqlite3_result_text(context, zOut, nOut, SQLITE_TRANSIENT);
3469
+ blob_reset(&txt);
3470
+}
34403471
34413472
/*
34423473
** Return a pointer to a static string that forms the basis for
34433474
** a timeline query for display on a TTY.
34443475
*/
34453476
const char *timeline_query_for_tty(void){
3477
+ static int once = 0;
34463478
static const char zBaseSql[] =
34473479
@ SELECT
34483480
@ blob.rid AS rid,
34493481
@ uuid,
34503482
@ datetime(event.mtime,toLocal()) AS mDateTime,
3451
- @ coalesce(ecomment,comment)
3483
+ @ wiki_to_text(coalesce(ecomment,comment))
34523484
@ || ' (user: ' || coalesce(euser,user,'?')
34533485
@ || (SELECT case when length(x)>0 then ' tags: ' || x else '' end
34543486
@ FROM (SELECT group_concat(substr(tagname,5), ', ') AS x
34553487
@ FROM tag, tagxref
34563488
@ WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid
@@ -3474,10 +3506,15 @@
34743506
@ AND tagxref.tagtype>0
34753507
@ AND tagxref.rid=blob.rid
34763508
@ WHERE blob.rid=event.objid
34773509
@ AND tag.tagname='branch'
34783510
;
3511
+ if( !once && g.db ){
3512
+ once = 1;
3513
+ sqlite3_create_function(g.db, "wiki_to_text", 1, SQLITE_UTF8, 0,
3514
+ wiki_to_text_sqlfunc, 0, 0);
3515
+ }
34793516
return zBaseSql;
34803517
}
34813518
34823519
/*
34833520
** Return true if the input string is a date in the ISO 8601 format:
34843521
--- src/timeline.c
+++ src/timeline.c
@@ -3435,22 +3435,54 @@
3435 fossil_print("+++ no more data (%d) +++\n", nEntry);
3436 }
3437 }
3438 if( fchngQueryInit ) db_finalize(&fchngQuery);
3439 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3440
3441 /*
3442 ** Return a pointer to a static string that forms the basis for
3443 ** a timeline query for display on a TTY.
3444 */
3445 const char *timeline_query_for_tty(void){
 
3446 static const char zBaseSql[] =
3447 @ SELECT
3448 @ blob.rid AS rid,
3449 @ uuid,
3450 @ datetime(event.mtime,toLocal()) AS mDateTime,
3451 @ coalesce(ecomment,comment)
3452 @ || ' (user: ' || coalesce(euser,user,'?')
3453 @ || (SELECT case when length(x)>0 then ' tags: ' || x else '' end
3454 @ FROM (SELECT group_concat(substr(tagname,5), ', ') AS x
3455 @ FROM tag, tagxref
3456 @ WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid
@@ -3474,10 +3506,15 @@
3474 @ AND tagxref.tagtype>0
3475 @ AND tagxref.rid=blob.rid
3476 @ WHERE blob.rid=event.objid
3477 @ AND tag.tagname='branch'
3478 ;
 
 
 
 
 
3479 return zBaseSql;
3480 }
3481
3482 /*
3483 ** Return true if the input string is a date in the ISO 8601 format:
3484
--- src/timeline.c
+++ src/timeline.c
@@ -3435,22 +3435,54 @@
3435 fossil_print("+++ no more data (%d) +++\n", nEntry);
3436 }
3437 }
3438 if( fchngQueryInit ) db_finalize(&fchngQuery);
3439 }
3440
3441 /*
3442 ** wiki_to_text(TEXT)
3443 **
3444 ** Return a plain-text rendering of Fossil-Wiki TEXT.
3445 */
3446 static void wiki_to_text_sqlfunc(
3447 sqlite3_context *context,
3448 int argc,
3449 sqlite3_value **argv
3450 ){
3451 const char *zIn, *zOut;
3452 int nIn, nOut;
3453 Blob in, html, txt;
3454 zIn = (const char*)sqlite3_value_text(argv[0]);
3455 if( zIn==0 ) return;
3456 nIn = sqlite3_value_bytes(argv[0]);
3457 blob_init(&in, zIn, nIn);
3458 blob_init(&html, 0, 0);
3459 wiki_convert(&in, &html, WIKI_INLINE);
3460 blob_reset(&in);
3461 blob_init(&txt, 0, 0);
3462 html_to_plaintext(blob_str(&html), &txt);
3463 blob_reset(&html);
3464 nOut = blob_size(&txt);
3465 zOut = blob_str(&txt);
3466 while( fossil_isspace(zOut[0]) ){ zOut++; nOut--; }
3467 while( nOut>0 && fossil_isspace(zOut[nOut-1]) ){ nOut--; }
3468 sqlite3_result_text(context, zOut, nOut, SQLITE_TRANSIENT);
3469 blob_reset(&txt);
3470 }
3471
3472 /*
3473 ** Return a pointer to a static string that forms the basis for
3474 ** a timeline query for display on a TTY.
3475 */
3476 const char *timeline_query_for_tty(void){
3477 static int once = 0;
3478 static const char zBaseSql[] =
3479 @ SELECT
3480 @ blob.rid AS rid,
3481 @ uuid,
3482 @ datetime(event.mtime,toLocal()) AS mDateTime,
3483 @ wiki_to_text(coalesce(ecomment,comment))
3484 @ || ' (user: ' || coalesce(euser,user,'?')
3485 @ || (SELECT case when length(x)>0 then ' tags: ' || x else '' end
3486 @ FROM (SELECT group_concat(substr(tagname,5), ', ') AS x
3487 @ FROM tag, tagxref
3488 @ WHERE tagname GLOB 'sym-*' AND tag.tagid=tagxref.tagid
@@ -3474,10 +3506,15 @@
3506 @ AND tagxref.tagtype>0
3507 @ AND tagxref.rid=blob.rid
3508 @ WHERE blob.rid=event.objid
3509 @ AND tag.tagname='branch'
3510 ;
3511 if( !once && g.db ){
3512 once = 1;
3513 sqlite3_create_function(g.db, "wiki_to_text", 1, SQLITE_UTF8, 0,
3514 wiki_to_text_sqlfunc, 0, 0);
3515 }
3516 return zBaseSql;
3517 }
3518
3519 /*
3520 ** Return true if the input string is a date in the ISO 8601 format:
3521
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1891,11 +1891,11 @@
18911891
** --htmlonly Set the WIKI_HTMLONLY flag
18921892
** --inline Set the WIKI_INLINE flag
18931893
** --linksonly Set the WIKI_LINKSONLY flag
18941894
** --nobadlinks Set the WIKI_NOBADLINKS flag
18951895
** --noblock Set the WIKI_NOBLOCK flag
1896
-** --text Run the output through html_to_plaintext().
1896
+** --text Run the output through html_to_plaintext().
18971897
*/
18981898
void test_wiki_render(void){
18991899
Blob in, out;
19001900
int flags = 0;
19011901
int bText;
19021902
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1891,11 +1891,11 @@
1891 ** --htmlonly Set the WIKI_HTMLONLY flag
1892 ** --inline Set the WIKI_INLINE flag
1893 ** --linksonly Set the WIKI_LINKSONLY flag
1894 ** --nobadlinks Set the WIKI_NOBADLINKS flag
1895 ** --noblock Set the WIKI_NOBLOCK flag
1896 ** --text Run the output through html_to_plaintext().
1897 */
1898 void test_wiki_render(void){
1899 Blob in, out;
1900 int flags = 0;
1901 int bText;
1902
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1891,11 +1891,11 @@
1891 ** --htmlonly Set the WIKI_HTMLONLY flag
1892 ** --inline Set the WIKI_INLINE flag
1893 ** --linksonly Set the WIKI_LINKSONLY flag
1894 ** --nobadlinks Set the WIKI_NOBADLINKS flag
1895 ** --noblock Set the WIKI_NOBLOCK flag
1896 ** --text Run the output through html_to_plaintext().
1897 */
1898 void test_wiki_render(void){
1899 Blob in, out;
1900 int flags = 0;
1901 int bText;
1902

Keyboard Shortcuts

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