Fossil SCM

Add <code>--lint-footnotes</code> option to the <code>test-markdown-render</code> command. If this flag is given and footnotes in the input have issues, then print to <var>stderr</var> the counters of "misrefs", "strays" and "split-defs" and exit with error. This should partially address a concern [forum:/forumpost/119b0be29a2b096b|raised at the forum].

george 2022-02-18 01:33 markdown-footnotes
Commit 1f525713ff85cf5fc1ef0c61521c298bbb330eef69e073f01fc194c27ad2067a
+1
--- src/main.c
+++ src/main.c
@@ -324,10 +324,11 @@
324324
} reqPayload; /* request payload object (if any) */
325325
cson_array *warnings; /* response warnings */
326326
int timerId; /* fetched from fossil_timer_start() */
327327
} json;
328328
#endif /* FOSSIL_ENABLE_JSON */
329
+ int ftntsIssues[3]; /* Counts for misref, strayed, joined */
329330
int diffCnt[3]; /* Counts for DIFF_NUMSTAT: files, ins, del */
330331
};
331332
332333
/*
333334
** Macro for debugging:
334335
--- src/main.c
+++ src/main.c
@@ -324,10 +324,11 @@
324 } reqPayload; /* request payload object (if any) */
325 cson_array *warnings; /* response warnings */
326 int timerId; /* fetched from fossil_timer_start() */
327 } json;
328 #endif /* FOSSIL_ENABLE_JSON */
 
329 int diffCnt[3]; /* Counts for DIFF_NUMSTAT: files, ins, del */
330 };
331
332 /*
333 ** Macro for debugging:
334
--- src/main.c
+++ src/main.c
@@ -324,10 +324,11 @@
324 } reqPayload; /* request payload object (if any) */
325 cson_array *warnings; /* response warnings */
326 int timerId; /* fetched from fossil_timer_start() */
327 } json;
328 #endif /* FOSSIL_ENABLE_JSON */
329 int ftntsIssues[3]; /* Counts for misref, strayed, joined */
330 int diffCnt[3]; /* Counts for DIFF_NUMSTAT: files, ins, del */
331 };
332
333 /*
334 ** Macro for debugging:
335
--- src/markdown.c
+++ src/markdown.c
@@ -2713,10 +2713,11 @@
27132713
}
27142714
blob_reset( allNotes );
27152715
rndr.notes.all = filtered;
27162716
rndr.notes.nLbled = n;
27172717
assert( COUNT_FOOTNOTES(allNotes) == rndr.notes.nLbled );
2718
+ g.ftntsIssues[2] += nDups;
27182719
}
27192720
}
27202721
fn = CAST_AS_FOOTNOTES( allNotes );
27212722
for(i=0; i<rndr.notes.nLbled; i++){
27222723
fn[i].index = i;
@@ -2780,18 +2781,20 @@
27802781
}
27812782
}
27822783
if( rndr.notes.misref.nUsed ){
27832784
rndr.make.footnote_item(all_items, 0, -1,
27842785
rndr.notes.misref.nUsed, rndr.make.opaque);
2786
+ g.ftntsIssues[0] += rndr.notes.misref.nUsed;
27852787
}
27862788
while( ++j < COUNT_FOOTNOTES(notes) ){
27872789
const struct footnote* x = CAST_AS_FOOTNOTES(notes) + j;
27882790
assert( !x->nUsed );
27892791
assert( !x->bRndred );
27902792
assert( (&x->id) + 1 == &x->text ); /* see html_footnote_item() */
27912793
assert( (&x->upc)- 1 == &x->text );
27922794
rndr.make.footnote_item(all_items,&x->text,0,0,rndr.make.opaque);
2795
+ g.ftntsIssues[1]++;
27932796
}
27942797
rndr.make.footnotes(ob, all_items, rndr.make.opaque);
27952798
release_work_buffer(&rndr, all_items);
27962799
}
27972800
release_work_buffer(&rndr, notes);
27982801
--- src/markdown.c
+++ src/markdown.c
@@ -2713,10 +2713,11 @@
2713 }
2714 blob_reset( allNotes );
2715 rndr.notes.all = filtered;
2716 rndr.notes.nLbled = n;
2717 assert( COUNT_FOOTNOTES(allNotes) == rndr.notes.nLbled );
 
2718 }
2719 }
2720 fn = CAST_AS_FOOTNOTES( allNotes );
2721 for(i=0; i<rndr.notes.nLbled; i++){
2722 fn[i].index = i;
@@ -2780,18 +2781,20 @@
2780 }
2781 }
2782 if( rndr.notes.misref.nUsed ){
2783 rndr.make.footnote_item(all_items, 0, -1,
2784 rndr.notes.misref.nUsed, rndr.make.opaque);
 
2785 }
2786 while( ++j < COUNT_FOOTNOTES(notes) ){
2787 const struct footnote* x = CAST_AS_FOOTNOTES(notes) + j;
2788 assert( !x->nUsed );
2789 assert( !x->bRndred );
2790 assert( (&x->id) + 1 == &x->text ); /* see html_footnote_item() */
2791 assert( (&x->upc)- 1 == &x->text );
2792 rndr.make.footnote_item(all_items,&x->text,0,0,rndr.make.opaque);
 
2793 }
2794 rndr.make.footnotes(ob, all_items, rndr.make.opaque);
2795 release_work_buffer(&rndr, all_items);
2796 }
2797 release_work_buffer(&rndr, notes);
2798
--- src/markdown.c
+++ src/markdown.c
@@ -2713,10 +2713,11 @@
2713 }
2714 blob_reset( allNotes );
2715 rndr.notes.all = filtered;
2716 rndr.notes.nLbled = n;
2717 assert( COUNT_FOOTNOTES(allNotes) == rndr.notes.nLbled );
2718 g.ftntsIssues[2] += nDups;
2719 }
2720 }
2721 fn = CAST_AS_FOOTNOTES( allNotes );
2722 for(i=0; i<rndr.notes.nLbled; i++){
2723 fn[i].index = i;
@@ -2780,18 +2781,20 @@
2781 }
2782 }
2783 if( rndr.notes.misref.nUsed ){
2784 rndr.make.footnote_item(all_items, 0, -1,
2785 rndr.notes.misref.nUsed, rndr.make.opaque);
2786 g.ftntsIssues[0] += rndr.notes.misref.nUsed;
2787 }
2788 while( ++j < COUNT_FOOTNOTES(notes) ){
2789 const struct footnote* x = CAST_AS_FOOTNOTES(notes) + j;
2790 assert( !x->nUsed );
2791 assert( !x->bRndred );
2792 assert( (&x->id) + 1 == &x->text ); /* see html_footnote_item() */
2793 assert( (&x->upc)- 1 == &x->text );
2794 rndr.make.footnote_item(all_items,&x->text,0,0,rndr.make.opaque);
2795 g.ftntsIssues[1]++;
2796 }
2797 rndr.make.footnotes(ob, all_items, rndr.make.opaque);
2798 release_work_buffer(&rndr, all_items);
2799 }
2800 release_work_buffer(&rndr, notes);
2801
+13 -2
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1893,18 +1893,20 @@
18931893
** Usage: %fossil test-markdown-render FILE ...
18941894
**
18951895
** Render markdown in FILE as HTML on stdout.
18961896
** Options:
18971897
**
1898
-** --safe Restrict the output to use only "safe" HTML
1898
+** --safe Restrict the output to use only "safe" HTML
1899
+** --lint-footnotes Print stats for footnotes-related issues
18991900
*/
19001901
void test_markdown_render(void){
19011902
Blob in, out;
19021903
int i;
1903
- int bSafe = 0;
1904
+ int bSafe = 0, bFnLint = 0;
19041905
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
19051906
bSafe = find_option("safe",0,0)!=0;
1907
+ bFnLint = find_option("lint-footnotes",0,0)!=0;
19061908
verify_all_options();
19071909
for(i=2; i<g.argc; i++){
19081910
blob_zero(&out);
19091911
blob_read_from_file(&in, g.argv[i], ExtFILE);
19101912
if( g.argc>3 ){
@@ -1914,10 +1916,19 @@
19141916
safe_html_context( bSafe ? DOCSRC_UNTRUSTED : DOCSRC_TRUSTED );
19151917
safe_html(&out);
19161918
blob_write_to_file(&out, "-");
19171919
blob_reset(&in);
19181920
blob_reset(&out);
1921
+ }
1922
+ if( bFnLint && (g.ftntsIssues[0] || g.ftntsIssues[1] || g.ftntsIssues[2])){
1923
+ fossil_fatal("There were issues with footnotes:\n"
1924
+ " %8i misreference%s\n"
1925
+ " %8i unreferenced\n"
1926
+ " %8i splitted",
1927
+ g.ftntsIssues[0], g.ftntsIssues[0]==1?"":"s",
1928
+ g.ftntsIssues[1],
1929
+ g.ftntsIssues[2]);
19191930
}
19201931
}
19211932
19221933
/*
19231934
** Search for a <title>...</title> at the beginning of a wiki page.
19241935
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1893,18 +1893,20 @@
1893 ** Usage: %fossil test-markdown-render FILE ...
1894 **
1895 ** Render markdown in FILE as HTML on stdout.
1896 ** Options:
1897 **
1898 ** --safe Restrict the output to use only "safe" HTML
 
1899 */
1900 void test_markdown_render(void){
1901 Blob in, out;
1902 int i;
1903 int bSafe = 0;
1904 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
1905 bSafe = find_option("safe",0,0)!=0;
 
1906 verify_all_options();
1907 for(i=2; i<g.argc; i++){
1908 blob_zero(&out);
1909 blob_read_from_file(&in, g.argv[i], ExtFILE);
1910 if( g.argc>3 ){
@@ -1914,10 +1916,19 @@
1914 safe_html_context( bSafe ? DOCSRC_UNTRUSTED : DOCSRC_TRUSTED );
1915 safe_html(&out);
1916 blob_write_to_file(&out, "-");
1917 blob_reset(&in);
1918 blob_reset(&out);
 
 
 
 
 
 
 
 
 
1919 }
1920 }
1921
1922 /*
1923 ** Search for a <title>...</title> at the beginning of a wiki page.
1924
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1893,18 +1893,20 @@
1893 ** Usage: %fossil test-markdown-render FILE ...
1894 **
1895 ** Render markdown in FILE as HTML on stdout.
1896 ** Options:
1897 **
1898 ** --safe Restrict the output to use only "safe" HTML
1899 ** --lint-footnotes Print stats for footnotes-related issues
1900 */
1901 void test_markdown_render(void){
1902 Blob in, out;
1903 int i;
1904 int bSafe = 0, bFnLint = 0;
1905 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
1906 bSafe = find_option("safe",0,0)!=0;
1907 bFnLint = find_option("lint-footnotes",0,0)!=0;
1908 verify_all_options();
1909 for(i=2; i<g.argc; i++){
1910 blob_zero(&out);
1911 blob_read_from_file(&in, g.argv[i], ExtFILE);
1912 if( g.argc>3 ){
@@ -1914,10 +1916,19 @@
1916 safe_html_context( bSafe ? DOCSRC_UNTRUSTED : DOCSRC_TRUSTED );
1917 safe_html(&out);
1918 blob_write_to_file(&out, "-");
1919 blob_reset(&in);
1920 blob_reset(&out);
1921 }
1922 if( bFnLint && (g.ftntsIssues[0] || g.ftntsIssues[1] || g.ftntsIssues[2])){
1923 fossil_fatal("There were issues with footnotes:\n"
1924 " %8i misreference%s\n"
1925 " %8i unreferenced\n"
1926 " %8i splitted",
1927 g.ftntsIssues[0], g.ftntsIssues[0]==1?"":"s",
1928 g.ftntsIssues[1],
1929 g.ftntsIssues[2]);
1930 }
1931 }
1932
1933 /*
1934 ** Search for a <title>...</title> at the beginning of a wiki page.
1935

Keyboard Shortcuts

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