Fossil SCM

Part 2 of 2 of [91a73ec348d7609f]: add --dark-pikchr to the test-wiki-render and test-markdown-render commands.

stephan 2024-03-05 08:44 trunk
Commit aac2a3508649ffed87c9c966685ba5499feecb2f1c0a41f68441ba57eaf3695b
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -597,10 +597,41 @@
597597
html_escape(ob, blob_buffer(link), blob_size(link));
598598
}
599599
blob_append_literal(ob, "</a>");
600600
return 1;
601601
}
602
+
603
+/*
604
+** Flags for use with/via pikchr_to_html_add_flags().
605
+*/
606
+static int pikchrToHtmlFlags = 0;
607
+/*
608
+** Sets additional pikchr_process() flags to use for all future calls
609
+** to pikch_to_html(). This is intended to be used by commands such as
610
+** test-wiki-render and test-markdown-render to set the
611
+** PIKCHR_PROCESS_DARK_MODE flag for all embedded pikchr elements.
612
+**
613
+** Not all PIKCHR_PROCESS flags are legal, as pikchr_to_html()
614
+** hard-codes a subset of flags and passing arbitrary flags here may
615
+** interfere with that.
616
+**
617
+** The only tested/intended use of this function is to pass it either
618
+** 0 or PIKCHR_PROCESS_DARK_MODE.
619
+**
620
+** Design note: this is not implemented as an additional argument to
621
+** pikchr_to_html() because the commands for which dark-mode rendering
622
+** are now supported (test-wiki-render and test-markdown-render) are
623
+** far removed from their corresponding pikchr_to_html() calls and
624
+** there is no direct path from those commands to those calls. A
625
+** cleaner, but much more invasive, approach would be to add a flag to
626
+** markdown_to_html(), extend the WIKI_... flags with
627
+** WIKI_DARK_PIKCHR, and extend both wiki.c:Renderer and
628
+** markdown_html.c:MarkdownToHtml to contain and pass on that flag.
629
+*/
630
+void pikchr_to_html_add_flags( int f ){
631
+ pikchrToHtmlFlags = f;
632
+}
602633
603634
/*
604635
** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
605636
** text and insert the result in place of the original.
606637
*/
@@ -610,11 +641,12 @@
610641
const char *zArg, int nArg /* Addition arguments */
611642
){
612643
int pikFlags = PIKCHR_PROCESS_NONCE
613644
| PIKCHR_PROCESS_DIV
614645
| PIKCHR_PROCESS_SRC
615
- | PIKCHR_PROCESS_ERR_PRE;
646
+ | PIKCHR_PROCESS_ERR_PRE
647
+ | pikchrToHtmlFlags;
616648
Blob bSrc = empty_blob;
617649
const char *zPikVar;
618650
double rPikVar;
619651
620652
while( nArg>0 ){
621653
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -597,10 +597,41 @@
597 html_escape(ob, blob_buffer(link), blob_size(link));
598 }
599 blob_append_literal(ob, "</a>");
600 return 1;
601 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
603 /*
604 ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
605 ** text and insert the result in place of the original.
606 */
@@ -610,11 +641,12 @@
610 const char *zArg, int nArg /* Addition arguments */
611 ){
612 int pikFlags = PIKCHR_PROCESS_NONCE
613 | PIKCHR_PROCESS_DIV
614 | PIKCHR_PROCESS_SRC
615 | PIKCHR_PROCESS_ERR_PRE;
 
616 Blob bSrc = empty_blob;
617 const char *zPikVar;
618 double rPikVar;
619
620 while( nArg>0 ){
621
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -597,10 +597,41 @@
597 html_escape(ob, blob_buffer(link), blob_size(link));
598 }
599 blob_append_literal(ob, "</a>");
600 return 1;
601 }
602
603 /*
604 ** Flags for use with/via pikchr_to_html_add_flags().
605 */
606 static int pikchrToHtmlFlags = 0;
607 /*
608 ** Sets additional pikchr_process() flags to use for all future calls
609 ** to pikch_to_html(). This is intended to be used by commands such as
610 ** test-wiki-render and test-markdown-render to set the
611 ** PIKCHR_PROCESS_DARK_MODE flag for all embedded pikchr elements.
612 **
613 ** Not all PIKCHR_PROCESS flags are legal, as pikchr_to_html()
614 ** hard-codes a subset of flags and passing arbitrary flags here may
615 ** interfere with that.
616 **
617 ** The only tested/intended use of this function is to pass it either
618 ** 0 or PIKCHR_PROCESS_DARK_MODE.
619 **
620 ** Design note: this is not implemented as an additional argument to
621 ** pikchr_to_html() because the commands for which dark-mode rendering
622 ** are now supported (test-wiki-render and test-markdown-render) are
623 ** far removed from their corresponding pikchr_to_html() calls and
624 ** there is no direct path from those commands to those calls. A
625 ** cleaner, but much more invasive, approach would be to add a flag to
626 ** markdown_to_html(), extend the WIKI_... flags with
627 ** WIKI_DARK_PIKCHR, and extend both wiki.c:Renderer and
628 ** markdown_html.c:MarkdownToHtml to contain and pass on that flag.
629 */
630 void pikchr_to_html_add_flags( int f ){
631 pikchrToHtmlFlags = f;
632 }
633
634 /*
635 ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that
636 ** text and insert the result in place of the original.
637 */
@@ -610,11 +641,12 @@
641 const char *zArg, int nArg /* Addition arguments */
642 ){
643 int pikFlags = PIKCHR_PROCESS_NONCE
644 | PIKCHR_PROCESS_DIV
645 | PIKCHR_PROCESS_SRC
646 | PIKCHR_PROCESS_ERR_PRE
647 | pikchrToHtmlFlags;
648 Blob bSrc = empty_blob;
649 const char *zPikVar;
650 double rPikVar;
651
652 while( nArg>0 ){
653
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -460,10 +460,11 @@
460460
int wikiList; /* Current wiki list type */
461461
int inVerbatim; /* True in <verbatim> mode */
462462
int preVerbState; /* Value of state prior to verbatim */
463463
int wantAutoParagraph; /* True if a <p> is desired */
464464
int inAutoParagraph; /* True if within an automatic paragraph */
465
+ int pikchrHtmlFlags; /* Flags for pikchr_to_html() */
465466
const char *zVerbatimId; /* The id= attribute of <verbatim> */
466467
int nStack; /* Number of elements on the stack */
467468
int nAlloc; /* Space allocated for aStack */
468469
struct sStack {
469470
short iCode; /* Markup code */
@@ -1874,10 +1875,11 @@
18741875
** --htmlonly Set the WIKI_HTMLONLY flag
18751876
** --linksonly Set the WIKI_LINKSONLY flag
18761877
** --nobadlinks Set the WIKI_NOBADLINKS flag
18771878
** --inline Set the WIKI_INLINE flag
18781879
** --noblock Set the WIKI_NOBLOCK flag
1880
+** --dark-pikchr Render pikchrs in dark mode
18791881
*/
18801882
void test_wiki_render(void){
18811883
Blob in, out;
18821884
int flags = 0;
18831885
if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
@@ -1884,10 +1886,13 @@
18841886
if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
18851887
if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
18861888
if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
18871889
if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
18881890
if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
1891
+ if( find_option("dark-pikchr",0,0)!=0 ){
1892
+ pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
1893
+ }
18891894
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
18901895
verify_all_options();
18911896
if( g.argc!=3 ) usage("FILE");
18921897
blob_zero(&out);
18931898
blob_read_from_file(&in, g.argv[2], ExtFILE);
@@ -1903,18 +1908,22 @@
19031908
** Render markdown in FILE as HTML on stdout.
19041909
** Options:
19051910
**
19061911
** --safe Restrict the output to use only "safe" HTML
19071912
** --lint-footnotes Print stats for footnotes-related issues
1913
+** --dark-pikchr Render pikchrs in dark mode
19081914
*/
19091915
void test_markdown_render(void){
19101916
Blob in, out;
19111917
int i;
19121918
int bSafe = 0, bFnLint = 0;
19131919
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
19141920
bSafe = find_option("safe",0,0)!=0;
19151921
bFnLint = find_option("lint-footnotes",0,0)!=0;
1922
+ if( find_option("dark-pikchr",0,0)!=0 ){
1923
+ pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
1924
+ }
19161925
verify_all_options();
19171926
for(i=2; i<g.argc; i++){
19181927
blob_zero(&out);
19191928
blob_read_from_file(&in, g.argv[i], ExtFILE);
19201929
if( g.argc>3 ){
19211930
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -460,10 +460,11 @@
460 int wikiList; /* Current wiki list type */
461 int inVerbatim; /* True in <verbatim> mode */
462 int preVerbState; /* Value of state prior to verbatim */
463 int wantAutoParagraph; /* True if a <p> is desired */
464 int inAutoParagraph; /* True if within an automatic paragraph */
 
465 const char *zVerbatimId; /* The id= attribute of <verbatim> */
466 int nStack; /* Number of elements on the stack */
467 int nAlloc; /* Space allocated for aStack */
468 struct sStack {
469 short iCode; /* Markup code */
@@ -1874,10 +1875,11 @@
1874 ** --htmlonly Set the WIKI_HTMLONLY flag
1875 ** --linksonly Set the WIKI_LINKSONLY flag
1876 ** --nobadlinks Set the WIKI_NOBADLINKS flag
1877 ** --inline Set the WIKI_INLINE flag
1878 ** --noblock Set the WIKI_NOBLOCK flag
 
1879 */
1880 void test_wiki_render(void){
1881 Blob in, out;
1882 int flags = 0;
1883 if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
@@ -1884,10 +1886,13 @@
1884 if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
1885 if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
1886 if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
1887 if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
1888 if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
 
 
 
1889 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
1890 verify_all_options();
1891 if( g.argc!=3 ) usage("FILE");
1892 blob_zero(&out);
1893 blob_read_from_file(&in, g.argv[2], ExtFILE);
@@ -1903,18 +1908,22 @@
1903 ** Render markdown in FILE as HTML on stdout.
1904 ** Options:
1905 **
1906 ** --safe Restrict the output to use only "safe" HTML
1907 ** --lint-footnotes Print stats for footnotes-related issues
 
1908 */
1909 void test_markdown_render(void){
1910 Blob in, out;
1911 int i;
1912 int bSafe = 0, bFnLint = 0;
1913 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
1914 bSafe = find_option("safe",0,0)!=0;
1915 bFnLint = find_option("lint-footnotes",0,0)!=0;
 
 
 
1916 verify_all_options();
1917 for(i=2; i<g.argc; i++){
1918 blob_zero(&out);
1919 blob_read_from_file(&in, g.argv[i], ExtFILE);
1920 if( g.argc>3 ){
1921
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -460,10 +460,11 @@
460 int wikiList; /* Current wiki list type */
461 int inVerbatim; /* True in <verbatim> mode */
462 int preVerbState; /* Value of state prior to verbatim */
463 int wantAutoParagraph; /* True if a <p> is desired */
464 int inAutoParagraph; /* True if within an automatic paragraph */
465 int pikchrHtmlFlags; /* Flags for pikchr_to_html() */
466 const char *zVerbatimId; /* The id= attribute of <verbatim> */
467 int nStack; /* Number of elements on the stack */
468 int nAlloc; /* Space allocated for aStack */
469 struct sStack {
470 short iCode; /* Markup code */
@@ -1874,10 +1875,11 @@
1875 ** --htmlonly Set the WIKI_HTMLONLY flag
1876 ** --linksonly Set the WIKI_LINKSONLY flag
1877 ** --nobadlinks Set the WIKI_NOBADLINKS flag
1878 ** --inline Set the WIKI_INLINE flag
1879 ** --noblock Set the WIKI_NOBLOCK flag
1880 ** --dark-pikchr Render pikchrs in dark mode
1881 */
1882 void test_wiki_render(void){
1883 Blob in, out;
1884 int flags = 0;
1885 if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
@@ -1884,10 +1886,13 @@
1886 if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
1887 if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
1888 if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
1889 if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
1890 if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
1891 if( find_option("dark-pikchr",0,0)!=0 ){
1892 pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
1893 }
1894 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
1895 verify_all_options();
1896 if( g.argc!=3 ) usage("FILE");
1897 blob_zero(&out);
1898 blob_read_from_file(&in, g.argv[2], ExtFILE);
@@ -1903,18 +1908,22 @@
1908 ** Render markdown in FILE as HTML on stdout.
1909 ** Options:
1910 **
1911 ** --safe Restrict the output to use only "safe" HTML
1912 ** --lint-footnotes Print stats for footnotes-related issues
1913 ** --dark-pikchr Render pikchrs in dark mode
1914 */
1915 void test_markdown_render(void){
1916 Blob in, out;
1917 int i;
1918 int bSafe = 0, bFnLint = 0;
1919 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
1920 bSafe = find_option("safe",0,0)!=0;
1921 bFnLint = find_option("lint-footnotes",0,0)!=0;
1922 if( find_option("dark-pikchr",0,0)!=0 ){
1923 pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
1924 }
1925 verify_all_options();
1926 for(i=2; i<g.argc; i++){
1927 blob_zero(&out);
1928 blob_read_from_file(&in, g.argv[i], ExtFILE);
1929 if( g.argc>3 ){
1930

Keyboard Shortcuts

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