Fossil SCM
Part 2 of 2 of [91a73ec348d7609f]: add --dark-pikchr to the test-wiki-render and test-markdown-render commands.
Commit
aac2a3508649ffed87c9c966685ba5499feecb2f1c0a41f68441ba57eaf3695b
Parent
91a73ec348d7609…
2 files changed
+33
-1
+9
+33
-1
| --- src/markdown_html.c | ||
| +++ src/markdown_html.c | ||
| @@ -597,10 +597,41 @@ | ||
| 597 | 597 | html_escape(ob, blob_buffer(link), blob_size(link)); |
| 598 | 598 | } |
| 599 | 599 | blob_append_literal(ob, "</a>"); |
| 600 | 600 | return 1; |
| 601 | 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 | +} | |
| 602 | 633 | |
| 603 | 634 | /* |
| 604 | 635 | ** The nSrc bytes at zSrc[] are Pikchr input text (allegedly). Process that |
| 605 | 636 | ** text and insert the result in place of the original. |
| 606 | 637 | */ |
| @@ -610,11 +641,12 @@ | ||
| 610 | 641 | const char *zArg, int nArg /* Addition arguments */ |
| 611 | 642 | ){ |
| 612 | 643 | int pikFlags = PIKCHR_PROCESS_NONCE |
| 613 | 644 | | PIKCHR_PROCESS_DIV |
| 614 | 645 | | PIKCHR_PROCESS_SRC |
| 615 | - | PIKCHR_PROCESS_ERR_PRE; | |
| 646 | + | PIKCHR_PROCESS_ERR_PRE | |
| 647 | + | pikchrToHtmlFlags; | |
| 616 | 648 | Blob bSrc = empty_blob; |
| 617 | 649 | const char *zPikVar; |
| 618 | 650 | double rPikVar; |
| 619 | 651 | |
| 620 | 652 | while( nArg>0 ){ |
| 621 | 653 |
| --- 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 |
+9
| --- src/wikiformat.c | ||
| +++ src/wikiformat.c | ||
| @@ -460,10 +460,11 @@ | ||
| 460 | 460 | int wikiList; /* Current wiki list type */ |
| 461 | 461 | int inVerbatim; /* True in <verbatim> mode */ |
| 462 | 462 | int preVerbState; /* Value of state prior to verbatim */ |
| 463 | 463 | int wantAutoParagraph; /* True if a <p> is desired */ |
| 464 | 464 | int inAutoParagraph; /* True if within an automatic paragraph */ |
| 465 | + int pikchrHtmlFlags; /* Flags for pikchr_to_html() */ | |
| 465 | 466 | const char *zVerbatimId; /* The id= attribute of <verbatim> */ |
| 466 | 467 | int nStack; /* Number of elements on the stack */ |
| 467 | 468 | int nAlloc; /* Space allocated for aStack */ |
| 468 | 469 | struct sStack { |
| 469 | 470 | short iCode; /* Markup code */ |
| @@ -1874,10 +1875,11 @@ | ||
| 1874 | 1875 | ** --htmlonly Set the WIKI_HTMLONLY flag |
| 1875 | 1876 | ** --linksonly Set the WIKI_LINKSONLY flag |
| 1876 | 1877 | ** --nobadlinks Set the WIKI_NOBADLINKS flag |
| 1877 | 1878 | ** --inline Set the WIKI_INLINE flag |
| 1878 | 1879 | ** --noblock Set the WIKI_NOBLOCK flag |
| 1880 | +** --dark-pikchr Render pikchrs in dark mode | |
| 1879 | 1881 | */ |
| 1880 | 1882 | void test_wiki_render(void){ |
| 1881 | 1883 | Blob in, out; |
| 1882 | 1884 | int flags = 0; |
| 1883 | 1885 | if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS; |
| @@ -1884,10 +1886,13 @@ | ||
| 1884 | 1886 | if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY; |
| 1885 | 1887 | if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY; |
| 1886 | 1888 | if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS; |
| 1887 | 1889 | if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE; |
| 1888 | 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 | + } | |
| 1889 | 1894 | db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0); |
| 1890 | 1895 | verify_all_options(); |
| 1891 | 1896 | if( g.argc!=3 ) usage("FILE"); |
| 1892 | 1897 | blob_zero(&out); |
| 1893 | 1898 | blob_read_from_file(&in, g.argv[2], ExtFILE); |
| @@ -1903,18 +1908,22 @@ | ||
| 1903 | 1908 | ** Render markdown in FILE as HTML on stdout. |
| 1904 | 1909 | ** Options: |
| 1905 | 1910 | ** |
| 1906 | 1911 | ** --safe Restrict the output to use only "safe" HTML |
| 1907 | 1912 | ** --lint-footnotes Print stats for footnotes-related issues |
| 1913 | +** --dark-pikchr Render pikchrs in dark mode | |
| 1908 | 1914 | */ |
| 1909 | 1915 | void test_markdown_render(void){ |
| 1910 | 1916 | Blob in, out; |
| 1911 | 1917 | int i; |
| 1912 | 1918 | int bSafe = 0, bFnLint = 0; |
| 1913 | 1919 | db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0); |
| 1914 | 1920 | bSafe = find_option("safe",0,0)!=0; |
| 1915 | 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 | + } | |
| 1916 | 1925 | verify_all_options(); |
| 1917 | 1926 | for(i=2; i<g.argc; i++){ |
| 1918 | 1927 | blob_zero(&out); |
| 1919 | 1928 | blob_read_from_file(&in, g.argv[i], ExtFILE); |
| 1920 | 1929 | if( g.argc>3 ){ |
| 1921 | 1930 |
| --- 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 |