Fossil SCM

Enhancements to wiki_convert() that can optionally mark questionable text.

drh 2025-03-21 19:46 trunk
Commit f0d9fe2b0cd3cd60c32c91a5eeb6415f517b9a37b9314925ad3f2025ad6883bd
+1 -8
--- src/search.c
+++ src/search.c
@@ -619,18 +619,11 @@
619619
int nLimit = zLimit ? atoi(zLimit) : -1000;
620620
int width;
621621
int nTty = 0; /* VT100 highlight color for matching text */
622622
const char *zHighlight = 0;
623623
624
- /* Only colorize the output if talking to a tty and NO_COLOR does not
625
- ** exist or is false. */
626
- if( fossil_isatty(1) ){
627
- char *zNoColor = fossil_getenv("NO_COLOR");
628
- if( zNoColor==0 || zNoColor[0]==0 || is_false(zNoColor) ){
629
- nTty = 91;
630
- }
631
- }
624
+ nTty = terminal_is_vt100();
632625
633626
/* Undocumented option to change highlight color */
634627
zHighlight = find_option("highlight",0,1);
635628
if( zHighlight ) nTty = atoi(zHighlight);
636629
637630
--- src/search.c
+++ src/search.c
@@ -619,18 +619,11 @@
619 int nLimit = zLimit ? atoi(zLimit) : -1000;
620 int width;
621 int nTty = 0; /* VT100 highlight color for matching text */
622 const char *zHighlight = 0;
623
624 /* Only colorize the output if talking to a tty and NO_COLOR does not
625 ** exist or is false. */
626 if( fossil_isatty(1) ){
627 char *zNoColor = fossil_getenv("NO_COLOR");
628 if( zNoColor==0 || zNoColor[0]==0 || is_false(zNoColor) ){
629 nTty = 91;
630 }
631 }
632
633 /* Undocumented option to change highlight color */
634 zHighlight = find_option("highlight",0,1);
635 if( zHighlight ) nTty = atoi(zHighlight);
636
637
--- src/search.c
+++ src/search.c
@@ -619,18 +619,11 @@
619 int nLimit = zLimit ? atoi(zLimit) : -1000;
620 int width;
621 int nTty = 0; /* VT100 highlight color for matching text */
622 const char *zHighlight = 0;
623
624 nTty = terminal_is_vt100();
 
 
 
 
 
 
 
625
626 /* Undocumented option to change highlight color */
627 zHighlight = find_option("highlight",0,1);
628 if( zHighlight ) nTty = atoi(zHighlight);
629
630
--- src/terminal.c
+++ src/terminal.c
@@ -138,5 +138,18 @@
138138
void test_terminal_size_cmd(void){
139139
TerminalSize ts;
140140
terminal_get_size(&ts);
141141
fossil_print("%d %d\n", ts.nColumns, ts.nLines);
142142
}
143
+
144
+/*
145
+** Return true if it is reasonable is emit VT100 escape codes.
146
+*/
147
+int terminal_is_vt100(void){
148
+ char *zNoColor;
149
+ if( !fossil_isatty(1) ) return 0;
150
+ zNoColor =fossil_getenv("NO_COLOR");
151
+ if( zNoColor==0 ) return 1;
152
+ if( zNoColor[0]==0 ) return 1;
153
+ if( is_false(zNoColor) ) return 1;
154
+ return 0;
155
+}
143156
--- src/terminal.c
+++ src/terminal.c
@@ -138,5 +138,18 @@
138 void test_terminal_size_cmd(void){
139 TerminalSize ts;
140 terminal_get_size(&ts);
141 fossil_print("%d %d\n", ts.nColumns, ts.nLines);
142 }
 
 
 
 
 
 
 
 
 
 
 
 
 
143
--- src/terminal.c
+++ src/terminal.c
@@ -138,5 +138,18 @@
138 void test_terminal_size_cmd(void){
139 TerminalSize ts;
140 terminal_get_size(&ts);
141 fossil_print("%d %d\n", ts.nColumns, ts.nLines);
142 }
143
144 /*
145 ** Return true if it is reasonable is emit VT100 escape codes.
146 */
147 int terminal_is_vt100(void){
148 char *zNoColor;
149 if( !fossil_isatty(1) ) return 0;
150 zNoColor =fossil_getenv("NO_COLOR");
151 if( zNoColor==0 ) return 1;
152 if( zNoColor[0]==0 ) return 1;
153 if( is_false(zNoColor) ) return 1;
154 return 0;
155 }
156
+57 -8
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -35,19 +35,21 @@
3535
#define WIKI_MARKDOWNLINKS 0x0080 /* Resolve hyperlinks as in markdown */
3636
#define WIKI_SAFE 0x0100 /* Make the result safe for embedding */
3737
#define WIKI_TARGET_BLANK 0x0200 /* Hyperlinks go to a new window */
3838
#define WIKI_NOBRACKET 0x0400 /* Omit extra [..] around hyperlinks */
3939
#define WIKI_ADMIN 0x0800 /* Ignore g.perm.Hyperlink */
40
+#define WIKI_MARK 0x1000 /* Add <mark>..</mark> around problems */
4041
4142
/*
4243
** Return values from wiki_convert
4344
*/
4445
#define RENDER_LINK 0x0001 /* One or more hyperlinks rendered */
4546
#define RENDER_ENTITY 0x0002 /* One or more HTML entities (ex: &lt;) */
4647
#define RENDER_TAG 0x0004 /* One or more HTML tags */
4748
#define RENDER_BLOCKTAG 0x0008 /* One or more HTML block tags (ex: <p>) */
4849
#define RENDER_BLOCK 0x0010 /* Block wiki (paragraphs, etc.) */
50
+#define RENDER_MARK 0x0020 /* Output contains <mark>..</mark> */
4951
#define RENDER_BADLINK 0x0100 /* Bad hyperlink syntax seen */
5052
#define RENDER_BADTARGET 0x0200 /* Bad hyperlink target */
5153
#define RENDER_BADTAG 0x0400 /* Bad HTML tag or tag syntax */
5254
#define RENDER_BADENTITY 0x0800 /* Bad HTML entity syntax */
5355
#define RENDER_BADHTML 0x1000 /* Bad HTML seen */
@@ -754,18 +756,24 @@
754756
}
755757
if( z[0]=='[' ){
756758
if( (n = linkLength(z))>0 ){
757759
*pTokenType = TOKEN_LINK;
758760
return n;
761
+ }else if( p->state & WIKI_MARK ){
762
+ blob_append_string(p->pOut, "<mark>");
763
+ p->mRender |= RENDER_BADLINK|RENDER_MARK;
759764
}else{
760765
p->mRender |= RENDER_BADLINK;
761766
}
762767
}
763768
}else if( (p->state & ALLOW_LINKS)!=0 && z[0]=='[' ){
764769
if( (n = linkLength(z))>0 ){
765770
*pTokenType = TOKEN_LINK;
766771
return n;
772
+ }else if( p->state & WIKI_MARK ){
773
+ blob_append_string(p->pOut, "<mark>");
774
+ p->mRender |= RENDER_BADLINK|RENDER_MARK;
767775
}else{
768776
p->mRender |= RENDER_BADLINK;
769777
}
770778
}
771779
*pTokenType = TOKEN_TEXT;
@@ -1358,10 +1366,14 @@
13581366
}
13591367
}
13601368
}else if( !in_this_repo(zTarget) ){
13611369
if( (mFlags & (WIKI_LINKSONLY|WIKI_NOBADLINKS))!=0 ){
13621370
zTerm = "";
1371
+ }else if( (mFlags & WIKI_MARK)!=0 ){
1372
+ blob_appendf(pOut, "<mark>%s", zLB);
1373
+ zTerm = "]</mark>";
1374
+ rc |= RENDER_MARK;
13631375
}else{
13641376
blob_appendf(pOut, "<span class=\"brokenlink\">%s", zLB);
13651377
zTerm = "]</span>";
13661378
}
13671379
rc |= RENDER_BADTARGET;
@@ -1390,10 +1402,14 @@
13901402
blob_appendf(pOut, "<a href=\"%R/timeline?c=%T\"%s>", zTarget, zExtra);
13911403
}else if( mFlags & WIKI_MARKDOWNLINKS ){
13921404
/* If none of the above, and if rendering links for markdown, then
13931405
** create a link to the literal text of the target */
13941406
blob_appendf(pOut, "<a href=\"%h\"%s>", zTarget, zExtra);
1407
+ }else if( mFlags & WIKI_MARK ){
1408
+ blob_appendf(pOut, "<mark>[");
1409
+ zTerm = "]</mark>";
1410
+ rc |= RENDER_BADTARGET|RENDER_MARK;
13951411
}else if( zOrig && zTarget>=&zOrig[2]
13961412
&& zTarget[-1]=='[' && !fossil_isspace(zTarget[-2]) ){
13971413
/* If the hyperlink markup is not preceded by whitespace, then it
13981414
** is probably a C-language subscript or similar, not really a
13991415
** hyperlink. Just ignore it. */
@@ -1628,15 +1644,28 @@
16281644
}
16291645
break;
16301646
}
16311647
case TOKEN_CHARACTER: {
16321648
startAutoParagraph(p);
1649
+ if( p->state & WIKI_MARK ){
1650
+ blob_append_string(p->pOut, "<mark>");
1651
+ p->mRender |= RENDER_MARK;
1652
+ }
16331653
if( z[0]=='<' ){
16341654
blob_append_string(p->pOut, "&lt;");
16351655
}else if( z[0]=='&' ){
16361656
blob_append_string(p->pOut, "&amp;");
16371657
}
1658
+ if( p->state & WIKI_MARK ){
1659
+ if( fossil_isalnum(z[1]) || (z[1]=='/' && fossil_isalnum(z[2])) ){
1660
+ int kk;
1661
+ for(kk=2; fossil_isalnum(z[kk]); kk++){}
1662
+ blob_append(p->pOut, &z[1], kk-1);
1663
+ n = kk;
1664
+ }
1665
+ blob_append_string(p->pOut, "</mark>");
1666
+ }
16381667
break;
16391668
}
16401669
case TOKEN_LINK: {
16411670
char *zTarget;
16421671
char *zDisplay = 0;
@@ -1755,12 +1784,19 @@
17551784
*/
17561785
if( markup.iCode==MARKUP_INVALID ){
17571786
p->mRender |= RENDER_BADTAG;
17581787
unparseMarkup(&markup);
17591788
startAutoParagraph(p);
1760
- blob_append_string(p->pOut, "&lt;");
1761
- n = 1;
1789
+ if( p->state & WIKI_MARK ){
1790
+ p->mRender |= RENDER_MARK;
1791
+ blob_append_string(p->pOut, "<mark>");
1792
+ htmlize_to_blob(p->pOut, z, n);
1793
+ blob_append_string(p->pOut, "</mark>");
1794
+ }else{
1795
+ blob_append_string(p->pOut, "&lt;");
1796
+ htmlize_to_blob(p->pOut, z+1, n-1);
1797
+ }
17621798
}else
17631799
17641800
/* If the markup is not font-change markup ignore it if the
17651801
** font-change-only flag is set.
17661802
*/
@@ -1941,56 +1977,69 @@
19411977
** the resulting HTML on standard output.
19421978
**
19431979
** Options:
19441980
** --buttons Set the WIKI_BUTTONS flag
19451981
** --dark-pikchr Render pikchrs in dark mode
1982
+** --flow Render as text using comment_format
19461983
** --htmlonly Set the WIKI_HTMLONLY flag
19471984
** --inline Set the WIKI_INLINE flag
19481985
** --linksonly Set the WIKI_LINKSONLY flag
1986
+** --mark Add <mark>...</mark> around problems
19491987
** --nobadlinks Set the WIKI_NOBADLINKS flag
1950
-** --noblock Set the WIKI_NOBLOCK flag
1951
-** --text Run the output through html_to_plaintext().
1952
-** --type Break down the return code from wiki_convert().
1988
+** --text Run the output through html_to_plaintext()
1989
+** --type Break down the return code from wiki_convert()
19531990
*/
19541991
void test_wiki_render(void){
19551992
Blob in, out;
19561993
int flags = 0;
19571994
int bText;
1995
+ int bFlow = 0;
19581996
int showType = 0;
19591997
int mType;
19601998
if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
19611999
if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
19622000
if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
19632001
if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
19642002
if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
1965
- if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
2003
+ if( find_option("mark",0,0)!=0 ) flags |= WIKI_MARK;
19662004
if( find_option("dark-pikchr",0,0)!=0 ){
19672005
pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
19682006
}
19692007
bText = find_option("text",0,0)!=0;
2008
+ bFlow = find_option("flow",0,0)!=0;
19702009
showType = find_option("type",0,0)!=0;
19712010
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
19722011
verify_all_options();
19732012
if( g.argc!=3 ) usage("FILE");
19742013
blob_zero(&out);
19752014
blob_read_from_file(&in, g.argv[2], ExtFILE);
19762015
mType = wiki_convert(&in, &out, flags);
19772016
if( bText ){
19782017
Blob txt;
2018
+ int htot = 0;
2019
+ if( terminal_is_vt100() ) htot |= HTOT_VT100;
2020
+ if( bFlow ) htot |= HTOT_NO_WS;
19792021
blob_init(&txt, 0, 0);
1980
- html_to_plaintext(blob_str(&out),&txt, HTOT_VT100);
2022
+ html_to_plaintext(blob_str(&out),&txt, htot);
19812023
blob_reset(&out);
19822024
out = txt;
19832025
}
1984
- blob_write_to_file(&out, "-");
2026
+ if( bFlow ){
2027
+ fossil_print(" ");
2028
+ comment_print(blob_str(&out), 0, 3, terminal_get_width(80)-3,
2029
+ get_comment_format());
2030
+ }else{
2031
+ blob_write_to_file(&out, "-");
2032
+ }
19852033
if( showType ){
19862034
fossil_print("%.*c\nResult Codes:", terminal_get_width(80)-1, '*');
19872035
if( mType & RENDER_LINK ) fossil_print(" LINK");
19882036
if( mType & RENDER_ENTITY ) fossil_print(" ENTITY");
19892037
if( mType & RENDER_TAG ) fossil_print(" TAG");
19902038
if( mType & RENDER_BLOCKTAG ) fossil_print(" BLOCKTAG");
19912039
if( mType & RENDER_BLOCK ) fossil_print(" BLOCK");
2040
+ if( mType & RENDER_MARK ) fossil_print(" MARK");
19922041
if( mType & RENDER_BADLINK ) fossil_print(" BADLINK");
19932042
if( mType & RENDER_BADTARGET ) fossil_print(" BADTARGET");
19942043
if( mType & RENDER_BADTAG ) fossil_print(" BADTAG");
19952044
if( mType & RENDER_BADENTITY ) fossil_print(" BADENTITY");
19962045
if( mType & RENDER_BADHTML ) fossil_print(" BADHTML");
19972046
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -35,19 +35,21 @@
35 #define WIKI_MARKDOWNLINKS 0x0080 /* Resolve hyperlinks as in markdown */
36 #define WIKI_SAFE 0x0100 /* Make the result safe for embedding */
37 #define WIKI_TARGET_BLANK 0x0200 /* Hyperlinks go to a new window */
38 #define WIKI_NOBRACKET 0x0400 /* Omit extra [..] around hyperlinks */
39 #define WIKI_ADMIN 0x0800 /* Ignore g.perm.Hyperlink */
 
40
41 /*
42 ** Return values from wiki_convert
43 */
44 #define RENDER_LINK 0x0001 /* One or more hyperlinks rendered */
45 #define RENDER_ENTITY 0x0002 /* One or more HTML entities (ex: &lt;) */
46 #define RENDER_TAG 0x0004 /* One or more HTML tags */
47 #define RENDER_BLOCKTAG 0x0008 /* One or more HTML block tags (ex: <p>) */
48 #define RENDER_BLOCK 0x0010 /* Block wiki (paragraphs, etc.) */
 
49 #define RENDER_BADLINK 0x0100 /* Bad hyperlink syntax seen */
50 #define RENDER_BADTARGET 0x0200 /* Bad hyperlink target */
51 #define RENDER_BADTAG 0x0400 /* Bad HTML tag or tag syntax */
52 #define RENDER_BADENTITY 0x0800 /* Bad HTML entity syntax */
53 #define RENDER_BADHTML 0x1000 /* Bad HTML seen */
@@ -754,18 +756,24 @@
754 }
755 if( z[0]=='[' ){
756 if( (n = linkLength(z))>0 ){
757 *pTokenType = TOKEN_LINK;
758 return n;
 
 
 
759 }else{
760 p->mRender |= RENDER_BADLINK;
761 }
762 }
763 }else if( (p->state & ALLOW_LINKS)!=0 && z[0]=='[' ){
764 if( (n = linkLength(z))>0 ){
765 *pTokenType = TOKEN_LINK;
766 return n;
 
 
 
767 }else{
768 p->mRender |= RENDER_BADLINK;
769 }
770 }
771 *pTokenType = TOKEN_TEXT;
@@ -1358,10 +1366,14 @@
1358 }
1359 }
1360 }else if( !in_this_repo(zTarget) ){
1361 if( (mFlags & (WIKI_LINKSONLY|WIKI_NOBADLINKS))!=0 ){
1362 zTerm = "";
 
 
 
 
1363 }else{
1364 blob_appendf(pOut, "<span class=\"brokenlink\">%s", zLB);
1365 zTerm = "]</span>";
1366 }
1367 rc |= RENDER_BADTARGET;
@@ -1390,10 +1402,14 @@
1390 blob_appendf(pOut, "<a href=\"%R/timeline?c=%T\"%s>", zTarget, zExtra);
1391 }else if( mFlags & WIKI_MARKDOWNLINKS ){
1392 /* If none of the above, and if rendering links for markdown, then
1393 ** create a link to the literal text of the target */
1394 blob_appendf(pOut, "<a href=\"%h\"%s>", zTarget, zExtra);
 
 
 
 
1395 }else if( zOrig && zTarget>=&zOrig[2]
1396 && zTarget[-1]=='[' && !fossil_isspace(zTarget[-2]) ){
1397 /* If the hyperlink markup is not preceded by whitespace, then it
1398 ** is probably a C-language subscript or similar, not really a
1399 ** hyperlink. Just ignore it. */
@@ -1628,15 +1644,28 @@
1628 }
1629 break;
1630 }
1631 case TOKEN_CHARACTER: {
1632 startAutoParagraph(p);
 
 
 
 
1633 if( z[0]=='<' ){
1634 blob_append_string(p->pOut, "&lt;");
1635 }else if( z[0]=='&' ){
1636 blob_append_string(p->pOut, "&amp;");
1637 }
 
 
 
 
 
 
 
 
 
1638 break;
1639 }
1640 case TOKEN_LINK: {
1641 char *zTarget;
1642 char *zDisplay = 0;
@@ -1755,12 +1784,19 @@
1755 */
1756 if( markup.iCode==MARKUP_INVALID ){
1757 p->mRender |= RENDER_BADTAG;
1758 unparseMarkup(&markup);
1759 startAutoParagraph(p);
1760 blob_append_string(p->pOut, "&lt;");
1761 n = 1;
 
 
 
 
 
 
 
1762 }else
1763
1764 /* If the markup is not font-change markup ignore it if the
1765 ** font-change-only flag is set.
1766 */
@@ -1941,56 +1977,69 @@
1941 ** the resulting HTML on standard output.
1942 **
1943 ** Options:
1944 ** --buttons Set the WIKI_BUTTONS flag
1945 ** --dark-pikchr Render pikchrs in dark mode
 
1946 ** --htmlonly Set the WIKI_HTMLONLY flag
1947 ** --inline Set the WIKI_INLINE flag
1948 ** --linksonly Set the WIKI_LINKSONLY flag
 
1949 ** --nobadlinks Set the WIKI_NOBADLINKS flag
1950 ** --noblock Set the WIKI_NOBLOCK flag
1951 ** --text Run the output through html_to_plaintext().
1952 ** --type Break down the return code from wiki_convert().
1953 */
1954 void test_wiki_render(void){
1955 Blob in, out;
1956 int flags = 0;
1957 int bText;
 
1958 int showType = 0;
1959 int mType;
1960 if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
1961 if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
1962 if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
1963 if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
1964 if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
1965 if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
1966 if( find_option("dark-pikchr",0,0)!=0 ){
1967 pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
1968 }
1969 bText = find_option("text",0,0)!=0;
 
1970 showType = find_option("type",0,0)!=0;
1971 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
1972 verify_all_options();
1973 if( g.argc!=3 ) usage("FILE");
1974 blob_zero(&out);
1975 blob_read_from_file(&in, g.argv[2], ExtFILE);
1976 mType = wiki_convert(&in, &out, flags);
1977 if( bText ){
1978 Blob txt;
 
 
 
1979 blob_init(&txt, 0, 0);
1980 html_to_plaintext(blob_str(&out),&txt, HTOT_VT100);
1981 blob_reset(&out);
1982 out = txt;
1983 }
1984 blob_write_to_file(&out, "-");
 
 
 
 
 
 
1985 if( showType ){
1986 fossil_print("%.*c\nResult Codes:", terminal_get_width(80)-1, '*');
1987 if( mType & RENDER_LINK ) fossil_print(" LINK");
1988 if( mType & RENDER_ENTITY ) fossil_print(" ENTITY");
1989 if( mType & RENDER_TAG ) fossil_print(" TAG");
1990 if( mType & RENDER_BLOCKTAG ) fossil_print(" BLOCKTAG");
1991 if( mType & RENDER_BLOCK ) fossil_print(" BLOCK");
 
1992 if( mType & RENDER_BADLINK ) fossil_print(" BADLINK");
1993 if( mType & RENDER_BADTARGET ) fossil_print(" BADTARGET");
1994 if( mType & RENDER_BADTAG ) fossil_print(" BADTAG");
1995 if( mType & RENDER_BADENTITY ) fossil_print(" BADENTITY");
1996 if( mType & RENDER_BADHTML ) fossil_print(" BADHTML");
1997
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -35,19 +35,21 @@
35 #define WIKI_MARKDOWNLINKS 0x0080 /* Resolve hyperlinks as in markdown */
36 #define WIKI_SAFE 0x0100 /* Make the result safe for embedding */
37 #define WIKI_TARGET_BLANK 0x0200 /* Hyperlinks go to a new window */
38 #define WIKI_NOBRACKET 0x0400 /* Omit extra [..] around hyperlinks */
39 #define WIKI_ADMIN 0x0800 /* Ignore g.perm.Hyperlink */
40 #define WIKI_MARK 0x1000 /* Add <mark>..</mark> around problems */
41
42 /*
43 ** Return values from wiki_convert
44 */
45 #define RENDER_LINK 0x0001 /* One or more hyperlinks rendered */
46 #define RENDER_ENTITY 0x0002 /* One or more HTML entities (ex: &lt;) */
47 #define RENDER_TAG 0x0004 /* One or more HTML tags */
48 #define RENDER_BLOCKTAG 0x0008 /* One or more HTML block tags (ex: <p>) */
49 #define RENDER_BLOCK 0x0010 /* Block wiki (paragraphs, etc.) */
50 #define RENDER_MARK 0x0020 /* Output contains <mark>..</mark> */
51 #define RENDER_BADLINK 0x0100 /* Bad hyperlink syntax seen */
52 #define RENDER_BADTARGET 0x0200 /* Bad hyperlink target */
53 #define RENDER_BADTAG 0x0400 /* Bad HTML tag or tag syntax */
54 #define RENDER_BADENTITY 0x0800 /* Bad HTML entity syntax */
55 #define RENDER_BADHTML 0x1000 /* Bad HTML seen */
@@ -754,18 +756,24 @@
756 }
757 if( z[0]=='[' ){
758 if( (n = linkLength(z))>0 ){
759 *pTokenType = TOKEN_LINK;
760 return n;
761 }else if( p->state & WIKI_MARK ){
762 blob_append_string(p->pOut, "<mark>");
763 p->mRender |= RENDER_BADLINK|RENDER_MARK;
764 }else{
765 p->mRender |= RENDER_BADLINK;
766 }
767 }
768 }else if( (p->state & ALLOW_LINKS)!=0 && z[0]=='[' ){
769 if( (n = linkLength(z))>0 ){
770 *pTokenType = TOKEN_LINK;
771 return n;
772 }else if( p->state & WIKI_MARK ){
773 blob_append_string(p->pOut, "<mark>");
774 p->mRender |= RENDER_BADLINK|RENDER_MARK;
775 }else{
776 p->mRender |= RENDER_BADLINK;
777 }
778 }
779 *pTokenType = TOKEN_TEXT;
@@ -1358,10 +1366,14 @@
1366 }
1367 }
1368 }else if( !in_this_repo(zTarget) ){
1369 if( (mFlags & (WIKI_LINKSONLY|WIKI_NOBADLINKS))!=0 ){
1370 zTerm = "";
1371 }else if( (mFlags & WIKI_MARK)!=0 ){
1372 blob_appendf(pOut, "<mark>%s", zLB);
1373 zTerm = "]</mark>";
1374 rc |= RENDER_MARK;
1375 }else{
1376 blob_appendf(pOut, "<span class=\"brokenlink\">%s", zLB);
1377 zTerm = "]</span>";
1378 }
1379 rc |= RENDER_BADTARGET;
@@ -1390,10 +1402,14 @@
1402 blob_appendf(pOut, "<a href=\"%R/timeline?c=%T\"%s>", zTarget, zExtra);
1403 }else if( mFlags & WIKI_MARKDOWNLINKS ){
1404 /* If none of the above, and if rendering links for markdown, then
1405 ** create a link to the literal text of the target */
1406 blob_appendf(pOut, "<a href=\"%h\"%s>", zTarget, zExtra);
1407 }else if( mFlags & WIKI_MARK ){
1408 blob_appendf(pOut, "<mark>[");
1409 zTerm = "]</mark>";
1410 rc |= RENDER_BADTARGET|RENDER_MARK;
1411 }else if( zOrig && zTarget>=&zOrig[2]
1412 && zTarget[-1]=='[' && !fossil_isspace(zTarget[-2]) ){
1413 /* If the hyperlink markup is not preceded by whitespace, then it
1414 ** is probably a C-language subscript or similar, not really a
1415 ** hyperlink. Just ignore it. */
@@ -1628,15 +1644,28 @@
1644 }
1645 break;
1646 }
1647 case TOKEN_CHARACTER: {
1648 startAutoParagraph(p);
1649 if( p->state & WIKI_MARK ){
1650 blob_append_string(p->pOut, "<mark>");
1651 p->mRender |= RENDER_MARK;
1652 }
1653 if( z[0]=='<' ){
1654 blob_append_string(p->pOut, "&lt;");
1655 }else if( z[0]=='&' ){
1656 blob_append_string(p->pOut, "&amp;");
1657 }
1658 if( p->state & WIKI_MARK ){
1659 if( fossil_isalnum(z[1]) || (z[1]=='/' && fossil_isalnum(z[2])) ){
1660 int kk;
1661 for(kk=2; fossil_isalnum(z[kk]); kk++){}
1662 blob_append(p->pOut, &z[1], kk-1);
1663 n = kk;
1664 }
1665 blob_append_string(p->pOut, "</mark>");
1666 }
1667 break;
1668 }
1669 case TOKEN_LINK: {
1670 char *zTarget;
1671 char *zDisplay = 0;
@@ -1755,12 +1784,19 @@
1784 */
1785 if( markup.iCode==MARKUP_INVALID ){
1786 p->mRender |= RENDER_BADTAG;
1787 unparseMarkup(&markup);
1788 startAutoParagraph(p);
1789 if( p->state & WIKI_MARK ){
1790 p->mRender |= RENDER_MARK;
1791 blob_append_string(p->pOut, "<mark>");
1792 htmlize_to_blob(p->pOut, z, n);
1793 blob_append_string(p->pOut, "</mark>");
1794 }else{
1795 blob_append_string(p->pOut, "&lt;");
1796 htmlize_to_blob(p->pOut, z+1, n-1);
1797 }
1798 }else
1799
1800 /* If the markup is not font-change markup ignore it if the
1801 ** font-change-only flag is set.
1802 */
@@ -1941,56 +1977,69 @@
1977 ** the resulting HTML on standard output.
1978 **
1979 ** Options:
1980 ** --buttons Set the WIKI_BUTTONS flag
1981 ** --dark-pikchr Render pikchrs in dark mode
1982 ** --flow Render as text using comment_format
1983 ** --htmlonly Set the WIKI_HTMLONLY flag
1984 ** --inline Set the WIKI_INLINE flag
1985 ** --linksonly Set the WIKI_LINKSONLY flag
1986 ** --mark Add <mark>...</mark> around problems
1987 ** --nobadlinks Set the WIKI_NOBADLINKS flag
1988 ** --text Run the output through html_to_plaintext()
1989 ** --type Break down the return code from wiki_convert()
 
1990 */
1991 void test_wiki_render(void){
1992 Blob in, out;
1993 int flags = 0;
1994 int bText;
1995 int bFlow = 0;
1996 int showType = 0;
1997 int mType;
1998 if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
1999 if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
2000 if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
2001 if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
2002 if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
2003 if( find_option("mark",0,0)!=0 ) flags |= WIKI_MARK;
2004 if( find_option("dark-pikchr",0,0)!=0 ){
2005 pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
2006 }
2007 bText = find_option("text",0,0)!=0;
2008 bFlow = find_option("flow",0,0)!=0;
2009 showType = find_option("type",0,0)!=0;
2010 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
2011 verify_all_options();
2012 if( g.argc!=3 ) usage("FILE");
2013 blob_zero(&out);
2014 blob_read_from_file(&in, g.argv[2], ExtFILE);
2015 mType = wiki_convert(&in, &out, flags);
2016 if( bText ){
2017 Blob txt;
2018 int htot = 0;
2019 if( terminal_is_vt100() ) htot |= HTOT_VT100;
2020 if( bFlow ) htot |= HTOT_NO_WS;
2021 blob_init(&txt, 0, 0);
2022 html_to_plaintext(blob_str(&out),&txt, htot);
2023 blob_reset(&out);
2024 out = txt;
2025 }
2026 if( bFlow ){
2027 fossil_print(" ");
2028 comment_print(blob_str(&out), 0, 3, terminal_get_width(80)-3,
2029 get_comment_format());
2030 }else{
2031 blob_write_to_file(&out, "-");
2032 }
2033 if( showType ){
2034 fossil_print("%.*c\nResult Codes:", terminal_get_width(80)-1, '*');
2035 if( mType & RENDER_LINK ) fossil_print(" LINK");
2036 if( mType & RENDER_ENTITY ) fossil_print(" ENTITY");
2037 if( mType & RENDER_TAG ) fossil_print(" TAG");
2038 if( mType & RENDER_BLOCKTAG ) fossil_print(" BLOCKTAG");
2039 if( mType & RENDER_BLOCK ) fossil_print(" BLOCK");
2040 if( mType & RENDER_MARK ) fossil_print(" MARK");
2041 if( mType & RENDER_BADLINK ) fossil_print(" BADLINK");
2042 if( mType & RENDER_BADTARGET ) fossil_print(" BADTARGET");
2043 if( mType & RENDER_BADTAG ) fossil_print(" BADTAG");
2044 if( mType & RENDER_BADENTITY ) fossil_print(" BADENTITY");
2045 if( mType & RENDER_BADHTML ) fossil_print(" BADHTML");
2046

Keyboard Shortcuts

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