Fossil SCM

Markdown hyperlinks are only converted to links to wiki if the named wikipage actually exists. Otherwise, the link becomes a relative link. This is for backwards compatibility.

drh 2019-08-23 11:07 trunk
Commit 3b10e644686bc279a4e8606853572351d98ab5a68a225e66c3f435f097d19965
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -433,11 +433,15 @@
433433
char zClose[20];
434434
435435
if( zLink==0 || zLink[0]==0 ){
436436
zClose[0] = 0;
437437
}else{
438
- wiki_resolve_hyperlink(ob, 0, zLink, zClose, sizeof(zClose), 0, zTitle);
438
+ static const int flags =
439
+ WIKI_NOBADLINKS |
440
+ WIKI_MARKDOWNLINKS
441
+ ;
442
+ wiki_resolve_hyperlink(ob, flags, zLink, zClose, sizeof(zClose), 0, zTitle);
439443
}
440444
if( blob_size(content)==0 ){
441445
if( link ) BLOB_APPEND_BLOB(ob, link);
442446
}else{
443447
BLOB_APPEND_BLOB(ob, content);
444448
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -433,11 +433,15 @@
433 char zClose[20];
434
435 if( zLink==0 || zLink[0]==0 ){
436 zClose[0] = 0;
437 }else{
438 wiki_resolve_hyperlink(ob, 0, zLink, zClose, sizeof(zClose), 0, zTitle);
 
 
 
 
439 }
440 if( blob_size(content)==0 ){
441 if( link ) BLOB_APPEND_BLOB(ob, link);
442 }else{
443 BLOB_APPEND_BLOB(ob, content);
444
--- src/markdown_html.c
+++ src/markdown_html.c
@@ -433,11 +433,15 @@
433 char zClose[20];
434
435 if( zLink==0 || zLink[0]==0 ){
436 zClose[0] = 0;
437 }else{
438 static const int flags =
439 WIKI_NOBADLINKS |
440 WIKI_MARKDOWNLINKS
441 ;
442 wiki_resolve_hyperlink(ob, flags, zLink, zClose, sizeof(zClose), 0, zTitle);
443 }
444 if( blob_size(content)==0 ){
445 if( link ) BLOB_APPEND_BLOB(ob, link);
446 }else{
447 BLOB_APPEND_BLOB(ob, content);
448
+1
--- src/wiki.c
+++ src/wiki.c
@@ -1629,10 +1629,11 @@
16291629
** Render markdown wiki from FILE to stdout.
16301630
**
16311631
*/
16321632
void test_markdown_render(void){
16331633
Blob in, out;
1634
+ db_find_and_open_repository(0,0);
16341635
verify_all_options();
16351636
if( g.argc!=3 ) usage("FILE");
16361637
blob_zero(&out);
16371638
blob_read_from_file(&in, g.argv[2], ExtFILE);
16381639
markdown_to_html(&in, 0, &out);
16391640
--- src/wiki.c
+++ src/wiki.c
@@ -1629,10 +1629,11 @@
1629 ** Render markdown wiki from FILE to stdout.
1630 **
1631 */
1632 void test_markdown_render(void){
1633 Blob in, out;
 
1634 verify_all_options();
1635 if( g.argc!=3 ) usage("FILE");
1636 blob_zero(&out);
1637 blob_read_from_file(&in, g.argv[2], ExtFILE);
1638 markdown_to_html(&in, 0, &out);
1639
--- src/wiki.c
+++ src/wiki.c
@@ -1629,10 +1629,11 @@
1629 ** Render markdown wiki from FILE to stdout.
1630 **
1631 */
1632 void test_markdown_render(void){
1633 Blob in, out;
1634 db_find_and_open_repository(0,0);
1635 verify_all_options();
1636 if( g.argc!=3 ) usage("FILE");
1637 blob_zero(&out);
1638 blob_read_from_file(&in, g.argv[2], ExtFILE);
1639 markdown_to_html(&in, 0, &out);
1640
+24 -19
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -30,10 +30,11 @@
3030
#define WIKI_NOBLOCK 0x004 /* No block markup of any kind */
3131
#define WIKI_BUTTONS 0x008 /* Allow sub-menu buttons */
3232
#define WIKI_NOBADLINKS 0x010 /* Ignore broken hyperlinks */
3333
#define WIKI_LINKSONLY 0x020 /* No markup. Only decorate links */
3434
#define WIKI_NEWLINE 0x040 /* Honor \n - break lines at each \n */
35
+#define WIKI_MARKDOWNLINKS 0x080 /* Resolve hyperlinks as in markdown */
3536
#endif
3637
3738
3839
/*
3940
** These are the only markup attributes allowed.
@@ -1211,20 +1212,22 @@
12111212
** [http://www.fossil-scm.org/]
12121213
** [https://www.fossil-scm.org/]
12131214
** [ftp://www.fossil-scm.org/]
12141215
** [mailto:[email protected]]
12151216
**
1216
-** [/path]
1217
+** [/path] -> Refers to the root of the Fossil hierarchy, not
1218
+** the root of the URI domain
12171219
**
12181220
** [./relpath]
1221
+** [../relpath]
12191222
**
1220
-** [WikiPageName]
1221
-** [wiki:WikiPageName]
1223
+** [#fragment]
12221224
**
12231225
** [0123456789abcdef]
12241226
**
1225
-** [#fragment]
1227
+** [WikiPageName]
1228
+** [wiki:WikiPageName]
12261229
**
12271230
** [2010-02-27 07:13]
12281231
*/
12291232
void wiki_resolve_hyperlink(
12301233
Blob *pOut, /* Write the HTML output here */
@@ -1296,24 +1299,35 @@
12961299
blob_appendf(pOut, "%z[",xhref(zExtraNS, "%R/info/%s", zTarget));
12971300
zTerm = "]</a>";
12981301
}else{
12991302
zTerm = "";
13001303
}
1301
- }else if( strlen(zTarget)>=10 && fossil_isdigit(zTarget[0]) && zTarget[4]=='-'
1302
- && db_int(0, "SELECT datetime(%Q) NOT NULL", zTarget) ){
1303
- blob_appendf(pOut, "<a href=\"%R/timeline?c=%T\"%s>", zTarget, zExtra);
13041304
}else if( (z = validWikiPageName(mFlags, zTarget))!=0 ){
1305
+ /* The link is to a valid wiki page name */
13051306
const char *zOverride = wiki_is_overridden(zTarget);
13061307
if( zOverride ){
13071308
blob_appendf(pOut, "<a href=\"%R/info/%S\"%s>", zOverride, zExtra);
13081309
}else{
13091310
blob_appendf(pOut, "<a href=\"%R/wiki?name=%T\"%s>", z, zExtra);
13101311
}
1311
- }else if( zOrig && zTarget>=&zOrig[2] && !fossil_isspace(zTarget[-2]) ){
1312
- /* Probably an array subscript in code */
1312
+ }else if( strlen(zTarget)>=10 && fossil_isdigit(zTarget[0]) && zTarget[4]=='-'
1313
+ && db_int(0, "SELECT datetime(%Q) NOT NULL", zTarget) ){
1314
+ /* Dates or date-and-times in ISO8610 resolve to a link to the
1315
+ ** timeline for that date */
1316
+ blob_appendf(pOut, "<a href=\"%R/timeline?c=%T\"%s>", zTarget, zExtra);
1317
+ }else if( mFlags & WIKI_MARKDOWNLINKS ){
1318
+ /* If none of the above, and if rendering links for markdown, then
1319
+ ** create a link to the literal text of the target */
1320
+ blob_appendf(pOut, "<a href=\"%h\"%s>", zTarget, zExtra);
1321
+ }else if( zOrig && zTarget>=&zOrig[2]
1322
+ && zTarget[-1]=='[' && !fossil_isspace(zTarget[-2]) ){
1323
+ /* If the hyperlink markup is not preceded by whitespace, then it
1324
+ ** is probably a C-language subscript or similar, not really a
1325
+ ** hyperlink. Just ignore it. */
13131326
zTerm = "";
13141327
}else if( (mFlags & (WIKI_NOBADLINKS|WIKI_LINKSONLY))!=0 ){
1328
+ /* Also ignore the link if various flags are set */
13151329
zTerm = "";
13161330
}else{
13171331
blob_appendf(pOut, "<span class=\"brokenlink\">[%h]", zTarget);
13181332
zTerm = "</span>";
13191333
}
@@ -1758,20 +1772,10 @@
17581772
}
17591773
blob_append(renderer.pOut, "\n", 1);
17601774
free(renderer.aStack);
17611775
}
17621776
1763
-/*
1764
-** Send a string as wiki to CGI output.
1765
-*/
1766
-void wiki_write(const char *zIn, int flags){
1767
- Blob in;
1768
- blob_init(&in, zIn, -1);
1769
- wiki_convert(&in, 0, flags);
1770
- blob_reset(&in);
1771
-}
1772
-
17731777
/*
17741778
** COMMAND: test-wiki-render
17751779
**
17761780
** Usage: %fossil test-wiki-render FILE [OPTIONS]
17771781
**
@@ -1790,10 +1794,11 @@
17901794
if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
17911795
if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
17921796
if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
17931797
if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
17941798
if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
1799
+ db_find_and_open_repository(0,0);
17951800
verify_all_options();
17961801
if( g.argc!=3 ) usage("FILE");
17971802
blob_zero(&out);
17981803
blob_read_from_file(&in, g.argv[2], ExtFILE);
17991804
wiki_convert(&in, &out, flags);
18001805
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -30,10 +30,11 @@
30 #define WIKI_NOBLOCK 0x004 /* No block markup of any kind */
31 #define WIKI_BUTTONS 0x008 /* Allow sub-menu buttons */
32 #define WIKI_NOBADLINKS 0x010 /* Ignore broken hyperlinks */
33 #define WIKI_LINKSONLY 0x020 /* No markup. Only decorate links */
34 #define WIKI_NEWLINE 0x040 /* Honor \n - break lines at each \n */
 
35 #endif
36
37
38 /*
39 ** These are the only markup attributes allowed.
@@ -1211,20 +1212,22 @@
1211 ** [http://www.fossil-scm.org/]
1212 ** [https://www.fossil-scm.org/]
1213 ** [ftp://www.fossil-scm.org/]
1214 ** [mailto:[email protected]]
1215 **
1216 ** [/path]
 
1217 **
1218 ** [./relpath]
 
1219 **
1220 ** [WikiPageName]
1221 ** [wiki:WikiPageName]
1222 **
1223 ** [0123456789abcdef]
1224 **
1225 ** [#fragment]
 
1226 **
1227 ** [2010-02-27 07:13]
1228 */
1229 void wiki_resolve_hyperlink(
1230 Blob *pOut, /* Write the HTML output here */
@@ -1296,24 +1299,35 @@
1296 blob_appendf(pOut, "%z[",xhref(zExtraNS, "%R/info/%s", zTarget));
1297 zTerm = "]</a>";
1298 }else{
1299 zTerm = "";
1300 }
1301 }else if( strlen(zTarget)>=10 && fossil_isdigit(zTarget[0]) && zTarget[4]=='-'
1302 && db_int(0, "SELECT datetime(%Q) NOT NULL", zTarget) ){
1303 blob_appendf(pOut, "<a href=\"%R/timeline?c=%T\"%s>", zTarget, zExtra);
1304 }else if( (z = validWikiPageName(mFlags, zTarget))!=0 ){
 
1305 const char *zOverride = wiki_is_overridden(zTarget);
1306 if( zOverride ){
1307 blob_appendf(pOut, "<a href=\"%R/info/%S\"%s>", zOverride, zExtra);
1308 }else{
1309 blob_appendf(pOut, "<a href=\"%R/wiki?name=%T\"%s>", z, zExtra);
1310 }
1311 }else if( zOrig && zTarget>=&zOrig[2] && !fossil_isspace(zTarget[-2]) ){
1312 /* Probably an array subscript in code */
 
 
 
 
 
 
 
 
 
 
 
 
1313 zTerm = "";
1314 }else if( (mFlags & (WIKI_NOBADLINKS|WIKI_LINKSONLY))!=0 ){
 
1315 zTerm = "";
1316 }else{
1317 blob_appendf(pOut, "<span class=\"brokenlink\">[%h]", zTarget);
1318 zTerm = "</span>";
1319 }
@@ -1758,20 +1772,10 @@
1758 }
1759 blob_append(renderer.pOut, "\n", 1);
1760 free(renderer.aStack);
1761 }
1762
1763 /*
1764 ** Send a string as wiki to CGI output.
1765 */
1766 void wiki_write(const char *zIn, int flags){
1767 Blob in;
1768 blob_init(&in, zIn, -1);
1769 wiki_convert(&in, 0, flags);
1770 blob_reset(&in);
1771 }
1772
1773 /*
1774 ** COMMAND: test-wiki-render
1775 **
1776 ** Usage: %fossil test-wiki-render FILE [OPTIONS]
1777 **
@@ -1790,10 +1794,11 @@
1790 if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
1791 if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
1792 if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
1793 if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
1794 if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
 
1795 verify_all_options();
1796 if( g.argc!=3 ) usage("FILE");
1797 blob_zero(&out);
1798 blob_read_from_file(&in, g.argv[2], ExtFILE);
1799 wiki_convert(&in, &out, flags);
1800
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -30,10 +30,11 @@
30 #define WIKI_NOBLOCK 0x004 /* No block markup of any kind */
31 #define WIKI_BUTTONS 0x008 /* Allow sub-menu buttons */
32 #define WIKI_NOBADLINKS 0x010 /* Ignore broken hyperlinks */
33 #define WIKI_LINKSONLY 0x020 /* No markup. Only decorate links */
34 #define WIKI_NEWLINE 0x040 /* Honor \n - break lines at each \n */
35 #define WIKI_MARKDOWNLINKS 0x080 /* Resolve hyperlinks as in markdown */
36 #endif
37
38
39 /*
40 ** These are the only markup attributes allowed.
@@ -1211,20 +1212,22 @@
1212 ** [http://www.fossil-scm.org/]
1213 ** [https://www.fossil-scm.org/]
1214 ** [ftp://www.fossil-scm.org/]
1215 ** [mailto:[email protected]]
1216 **
1217 ** [/path] -> Refers to the root of the Fossil hierarchy, not
1218 ** the root of the URI domain
1219 **
1220 ** [./relpath]
1221 ** [../relpath]
1222 **
1223 ** [#fragment]
 
1224 **
1225 ** [0123456789abcdef]
1226 **
1227 ** [WikiPageName]
1228 ** [wiki:WikiPageName]
1229 **
1230 ** [2010-02-27 07:13]
1231 */
1232 void wiki_resolve_hyperlink(
1233 Blob *pOut, /* Write the HTML output here */
@@ -1296,24 +1299,35 @@
1299 blob_appendf(pOut, "%z[",xhref(zExtraNS, "%R/info/%s", zTarget));
1300 zTerm = "]</a>";
1301 }else{
1302 zTerm = "";
1303 }
 
 
 
1304 }else if( (z = validWikiPageName(mFlags, zTarget))!=0 ){
1305 /* The link is to a valid wiki page name */
1306 const char *zOverride = wiki_is_overridden(zTarget);
1307 if( zOverride ){
1308 blob_appendf(pOut, "<a href=\"%R/info/%S\"%s>", zOverride, zExtra);
1309 }else{
1310 blob_appendf(pOut, "<a href=\"%R/wiki?name=%T\"%s>", z, zExtra);
1311 }
1312 }else if( strlen(zTarget)>=10 && fossil_isdigit(zTarget[0]) && zTarget[4]=='-'
1313 && db_int(0, "SELECT datetime(%Q) NOT NULL", zTarget) ){
1314 /* Dates or date-and-times in ISO8610 resolve to a link to the
1315 ** timeline for that date */
1316 blob_appendf(pOut, "<a href=\"%R/timeline?c=%T\"%s>", zTarget, zExtra);
1317 }else if( mFlags & WIKI_MARKDOWNLINKS ){
1318 /* If none of the above, and if rendering links for markdown, then
1319 ** create a link to the literal text of the target */
1320 blob_appendf(pOut, "<a href=\"%h\"%s>", zTarget, zExtra);
1321 }else if( zOrig && zTarget>=&zOrig[2]
1322 && zTarget[-1]=='[' && !fossil_isspace(zTarget[-2]) ){
1323 /* If the hyperlink markup is not preceded by whitespace, then it
1324 ** is probably a C-language subscript or similar, not really a
1325 ** hyperlink. Just ignore it. */
1326 zTerm = "";
1327 }else if( (mFlags & (WIKI_NOBADLINKS|WIKI_LINKSONLY))!=0 ){
1328 /* Also ignore the link if various flags are set */
1329 zTerm = "";
1330 }else{
1331 blob_appendf(pOut, "<span class=\"brokenlink\">[%h]", zTarget);
1332 zTerm = "</span>";
1333 }
@@ -1758,20 +1772,10 @@
1772 }
1773 blob_append(renderer.pOut, "\n", 1);
1774 free(renderer.aStack);
1775 }
1776
 
 
 
 
 
 
 
 
 
 
1777 /*
1778 ** COMMAND: test-wiki-render
1779 **
1780 ** Usage: %fossil test-wiki-render FILE [OPTIONS]
1781 **
@@ -1790,10 +1794,11 @@
1794 if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
1795 if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
1796 if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
1797 if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
1798 if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
1799 db_find_and_open_repository(0,0);
1800 verify_all_options();
1801 if( g.argc!=3 ) usage("FILE");
1802 blob_zero(&out);
1803 blob_read_from_file(&in, g.argv[2], ExtFILE);
1804 wiki_convert(&in, &out, flags);
1805

Keyboard Shortcuts

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