Fossil SCM

Add the --text option to test-wiki-render and test-markdown-render.

drh 2025-03-03 15:13 trunk
Commit 3ea3cd5ca50838a2d1be3fdd6200e0a03e5916022735599df4a6f7aa8d8fd6f0
1 file changed +24 -5
+24 -5
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1870,35 +1870,45 @@
18701870
** Translate the input FILE from Fossil-wiki into HTML and write
18711871
** the resulting HTML on standard output.
18721872
**
18731873
** Options:
18741874
** --buttons Set the WIKI_BUTTONS flag
1875
+** --dark-pikchr Render pikchrs in dark mode
18751876
** --htmlonly Set the WIKI_HTMLONLY flag
1877
+** --inline Set the WIKI_INLINE flag
18761878
** --linksonly Set the WIKI_LINKSONLY flag
18771879
** --nobadlinks Set the WIKI_NOBADLINKS flag
1878
-** --inline Set the WIKI_INLINE flag
18791880
** --noblock Set the WIKI_NOBLOCK flag
1880
-** --dark-pikchr Render pikchrs in dark mode
1881
+** --text Run the output through html_to_plaintext().
18811882
*/
18821883
void test_wiki_render(void){
18831884
Blob in, out;
18841885
int flags = 0;
1886
+ int bText;
18851887
if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
18861888
if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
18871889
if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
18881890
if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
18891891
if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
18901892
if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
18911893
if( find_option("dark-pikchr",0,0)!=0 ){
18921894
pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
18931895
}
1896
+ bText = find_option("text",0,0)!=0;
18941897
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
18951898
verify_all_options();
18961899
if( g.argc!=3 ) usage("FILE");
18971900
blob_zero(&out);
18981901
blob_read_from_file(&in, g.argv[2], ExtFILE);
18991902
wiki_convert(&in, &out, flags);
1903
+ if( bText ){
1904
+ Blob txt;
1905
+ blob_init(&txt, 0, 0);
1906
+ html_to_plaintext(blob_str(&out),&txt);
1907
+ blob_reset(&out);
1908
+ out = txt;
1909
+ }
19001910
blob_write_to_file(&out, "-");
19011911
}
19021912
19031913
/*
19041914
** COMMAND: test-markdown-render
@@ -1906,24 +1916,26 @@
19061916
** Usage: %fossil test-markdown-render FILE ...
19071917
**
19081918
** Render markdown in FILE as HTML on stdout.
19091919
** Options:
19101920
**
1911
-** --safe Restrict the output to use only "safe" HTML
1921
+** --dark-pikchr Render pikchrs in dark mode
19121922
** --lint-footnotes Print stats for footnotes-related issues
1913
-** --dark-pikchr Render pikchrs in dark mode
1923
+** --safe Restrict the output to use only "safe" HTML
1924
+** --text Run the output through html_to_plaintext().
19141925
*/
19151926
void test_markdown_render(void){
19161927
Blob in, out;
19171928
int i;
1918
- int bSafe = 0, bFnLint = 0;
1929
+ int bSafe = 0, bFnLint = 0, bText = 0;
19191930
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
19201931
bSafe = find_option("safe",0,0)!=0;
19211932
bFnLint = find_option("lint-footnotes",0,0)!=0;
19221933
if( find_option("dark-pikchr",0,0)!=0 ){
19231934
pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
19241935
}
1936
+ bText = find_option("text",0,0)!=0;
19251937
verify_all_options();
19261938
for(i=2; i<g.argc; i++){
19271939
blob_zero(&out);
19281940
blob_read_from_file(&in, g.argv[i], ExtFILE);
19291941
if( g.argc>3 ){
@@ -1930,10 +1942,17 @@
19301942
fossil_print("<!------ %h ------->\n", g.argv[i]);
19311943
}
19321944
markdown_to_html(&in, 0, &out);
19331945
safe_html_context( bSafe ? DOCSRC_UNTRUSTED : DOCSRC_TRUSTED );
19341946
safe_html(&out);
1947
+ if( bText ){
1948
+ Blob txt;
1949
+ blob_init(&txt, 0, 0);
1950
+ html_to_plaintext(blob_str(&out), &txt);
1951
+ blob_reset(&out);
1952
+ out = txt;
1953
+ }
19351954
blob_write_to_file(&out, "-");
19361955
blob_reset(&in);
19371956
blob_reset(&out);
19381957
}
19391958
if( bFnLint && (g.ftntsIssues[0] || g.ftntsIssues[1]
19401959
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1870,35 +1870,45 @@
1870 ** Translate the input FILE from Fossil-wiki into HTML and write
1871 ** the resulting HTML on standard output.
1872 **
1873 ** Options:
1874 ** --buttons Set the WIKI_BUTTONS flag
 
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;
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);
1899 wiki_convert(&in, &out, flags);
 
 
 
 
 
 
 
1900 blob_write_to_file(&out, "-");
1901 }
1902
1903 /*
1904 ** COMMAND: test-markdown-render
@@ -1906,24 +1916,26 @@
1906 ** Usage: %fossil test-markdown-render FILE ...
1907 **
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,10 +1942,17 @@
1930 fossil_print("<!------ %h ------->\n", g.argv[i]);
1931 }
1932 markdown_to_html(&in, 0, &out);
1933 safe_html_context( bSafe ? DOCSRC_UNTRUSTED : DOCSRC_TRUSTED );
1934 safe_html(&out);
 
 
 
 
 
 
 
1935 blob_write_to_file(&out, "-");
1936 blob_reset(&in);
1937 blob_reset(&out);
1938 }
1939 if( bFnLint && (g.ftntsIssues[0] || g.ftntsIssues[1]
1940
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1870,35 +1870,45 @@
1870 ** Translate the input FILE from Fossil-wiki into HTML and write
1871 ** the resulting HTML on standard output.
1872 **
1873 ** Options:
1874 ** --buttons Set the WIKI_BUTTONS flag
1875 ** --dark-pikchr Render pikchrs in dark mode
1876 ** --htmlonly Set the WIKI_HTMLONLY flag
1877 ** --inline Set the WIKI_INLINE flag
1878 ** --linksonly Set the WIKI_LINKSONLY flag
1879 ** --nobadlinks Set the WIKI_NOBADLINKS flag
 
1880 ** --noblock Set the WIKI_NOBLOCK flag
1881 ** --text Run the output through html_to_plaintext().
1882 */
1883 void test_wiki_render(void){
1884 Blob in, out;
1885 int flags = 0;
1886 int bText;
1887 if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
1888 if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
1889 if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
1890 if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
1891 if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
1892 if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
1893 if( find_option("dark-pikchr",0,0)!=0 ){
1894 pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
1895 }
1896 bText = find_option("text",0,0)!=0;
1897 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
1898 verify_all_options();
1899 if( g.argc!=3 ) usage("FILE");
1900 blob_zero(&out);
1901 blob_read_from_file(&in, g.argv[2], ExtFILE);
1902 wiki_convert(&in, &out, flags);
1903 if( bText ){
1904 Blob txt;
1905 blob_init(&txt, 0, 0);
1906 html_to_plaintext(blob_str(&out),&txt);
1907 blob_reset(&out);
1908 out = txt;
1909 }
1910 blob_write_to_file(&out, "-");
1911 }
1912
1913 /*
1914 ** COMMAND: test-markdown-render
@@ -1906,24 +1916,26 @@
1916 ** Usage: %fossil test-markdown-render FILE ...
1917 **
1918 ** Render markdown in FILE as HTML on stdout.
1919 ** Options:
1920 **
1921 ** --dark-pikchr Render pikchrs in dark mode
1922 ** --lint-footnotes Print stats for footnotes-related issues
1923 ** --safe Restrict the output to use only "safe" HTML
1924 ** --text Run the output through html_to_plaintext().
1925 */
1926 void test_markdown_render(void){
1927 Blob in, out;
1928 int i;
1929 int bSafe = 0, bFnLint = 0, bText = 0;
1930 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
1931 bSafe = find_option("safe",0,0)!=0;
1932 bFnLint = find_option("lint-footnotes",0,0)!=0;
1933 if( find_option("dark-pikchr",0,0)!=0 ){
1934 pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
1935 }
1936 bText = find_option("text",0,0)!=0;
1937 verify_all_options();
1938 for(i=2; i<g.argc; i++){
1939 blob_zero(&out);
1940 blob_read_from_file(&in, g.argv[i], ExtFILE);
1941 if( g.argc>3 ){
@@ -1930,10 +1942,17 @@
1942 fossil_print("<!------ %h ------->\n", g.argv[i]);
1943 }
1944 markdown_to_html(&in, 0, &out);
1945 safe_html_context( bSafe ? DOCSRC_UNTRUSTED : DOCSRC_TRUSTED );
1946 safe_html(&out);
1947 if( bText ){
1948 Blob txt;
1949 blob_init(&txt, 0, 0);
1950 html_to_plaintext(blob_str(&out), &txt);
1951 blob_reset(&out);
1952 out = txt;
1953 }
1954 blob_write_to_file(&out, "-");
1955 blob_reset(&in);
1956 blob_reset(&out);
1957 }
1958 if( bFnLint && (g.ftntsIssues[0] || g.ftntsIssues[1]
1959

Keyboard Shortcuts

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