Fossil SCM

Change the rendering option to WIKI_MARKDOWN_SPAN with the idea of eventually supporting all kinds of span-markdown, just not block-markdown. Add support for auto-links.

drh 2025-03-04 11:48 comment-markdown-links
Commit f80b89217883956d76b1cb22d7c26a2df15c0a8bf9521b6ea2b4aa42c6c72d91
+1 -1
--- src/backlink.c
+++ src/backlink.c
@@ -372,11 +372,11 @@
372372
bklnk.srctype = srctype;
373373
bklnk.mtime = mtime;
374374
if( mimetype==MT_NONE || mimetype==MT_WIKI ){
375375
int flags;
376376
if( srctype==BKLNK_COMMENT ){
377
- flags = WIKI_INLINE | WIKI_MARKDOWN_LINK;
377
+ flags = WIKI_INLINE | WIKI_MARKDOWN_SPAN;
378378
}else{
379379
flags = 0;
380380
}
381381
wiki_extract_links(zSrc, &bklnk, flags);
382382
}else if( mimetype==MT_MARKDOWN ){
383383
--- src/backlink.c
+++ src/backlink.c
@@ -372,11 +372,11 @@
372 bklnk.srctype = srctype;
373 bklnk.mtime = mtime;
374 if( mimetype==MT_NONE || mimetype==MT_WIKI ){
375 int flags;
376 if( srctype==BKLNK_COMMENT ){
377 flags = WIKI_INLINE | WIKI_MARKDOWN_LINK;
378 }else{
379 flags = 0;
380 }
381 wiki_extract_links(zSrc, &bklnk, flags);
382 }else if( mimetype==MT_MARKDOWN ){
383
--- src/backlink.c
+++ src/backlink.c
@@ -372,11 +372,11 @@
372 bklnk.srctype = srctype;
373 bklnk.mtime = mtime;
374 if( mimetype==MT_NONE || mimetype==MT_WIKI ){
375 int flags;
376 if( srctype==BKLNK_COMMENT ){
377 flags = WIKI_INLINE | WIKI_MARKDOWN_SPAN;
378 }else{
379 flags = 0;
380 }
381 wiki_extract_links(zSrc, &bklnk, flags);
382 }else if( mimetype==MT_MARKDOWN ){
383
+3 -1
--- src/printf.c
+++ src/printf.c
@@ -264,11 +264,13 @@
264264
wikiFlags |= WIKI_LINKSONLY;
265265
}
266266
if( db_get_boolean("timeline-hard-newlines", 0) ){
267267
wikiFlags |= WIKI_NEWLINE;
268268
}
269
- wikiFlags |= WIKI_MARKDOWN_LINK;
269
+ if( db_get_boolean("timeline-markdown-span", 1) ){
270
+ wikiFlags |= WIKI_MARKDOWN_SPAN;
271
+ }
270272
}
271273
if( altForm2 ){
272274
/* block markup (ex: <p>, <table>) allowed */
273275
return wikiFlags & ~WIKI_NOBLOCK;
274276
}else{
275277
--- src/printf.c
+++ src/printf.c
@@ -264,11 +264,13 @@
264 wikiFlags |= WIKI_LINKSONLY;
265 }
266 if( db_get_boolean("timeline-hard-newlines", 0) ){
267 wikiFlags |= WIKI_NEWLINE;
268 }
269 wikiFlags |= WIKI_MARKDOWN_LINK;
 
 
270 }
271 if( altForm2 ){
272 /* block markup (ex: <p>, <table>) allowed */
273 return wikiFlags & ~WIKI_NOBLOCK;
274 }else{
275
--- src/printf.c
+++ src/printf.c
@@ -264,11 +264,13 @@
264 wikiFlags |= WIKI_LINKSONLY;
265 }
266 if( db_get_boolean("timeline-hard-newlines", 0) ){
267 wikiFlags |= WIKI_NEWLINE;
268 }
269 if( db_get_boolean("timeline-markdown-span", 1) ){
270 wikiFlags |= WIKI_MARKDOWN_SPAN;
271 }
272 }
273 if( altForm2 ){
274 /* block markup (ex: <p>, <table>) allowed */
275 return wikiFlags & ~WIKI_NOBLOCK;
276 }else{
277
+30 -9
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -34,11 +34,11 @@
3434
#define WIKI_NEWLINE 0x040 /* Honor \n - break lines at each \n */
3535
#define WIKI_MARKDOWN_URL 0x080 /* Hyperlink targets as in markdown */
3636
#define WIKI_SAFE 0x100 /* Make the result safe for embedding */
3737
#define WIKI_TARGET_BLANK 0x200 /* Hyperlinks go to a new window */
3838
#define WIKI_NOBRACKET 0x400 /* Omit extra [..] around hyperlinks */
39
-#define WIKI_MARKDOWN_LINK 0x800 /* Markdown link syntax: [display](URL) */
39
+#define WIKI_MARKDOWN_SPAN 0x800 /* Interpret span elements of markdown */
4040
#endif
4141
4242
4343
/*
4444
** These are the only markup attributes allowed.
@@ -435,11 +435,12 @@
435435
#define TOKEN_BUL_LI 6 /* " * " */
436436
#define TOKEN_NUM_LI 7 /* " # " */
437437
#define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */
438438
#define TOKEN_INDENT 9 /* " " */
439439
#define TOKEN_RAW 10 /* Output exactly (used when wiki-use-html==1) */
440
-#define TOKEN_TEXT 11 /* None of the above */
440
+#define TOKEN_AUTOLINK 11 /* <URL> */
441
+#define TOKEN_TEXT 12 /* None of the above */
441442
442443
/*
443444
** State flags. Save the lower 16 bits for the WIKI_* flags.
444445
*/
445446
#define AT_NEWLINE 0x0010000 /* At start of a line */
@@ -682,14 +683,22 @@
682683
if( z[0]=='<' ){
683684
n = html_tag_length(z);
684685
if( n>0 ){
685686
*pTokenType = TOKEN_MARKUP;
686687
return n;
687
- }else{
688
- *pTokenType = TOKEN_CHARACTER;
689
- return 1;
688
+ }
689
+ if( z[1]=='h'
690
+ && (strncmp(z,"<https://",9)==0 || strncmp(z,"<http://",8)==0)
691
+ ){
692
+ for(n=8; z[n] && z[n]!='>'; n++){}
693
+ if( z[n]=='>' ){
694
+ *pTokenType = TOKEN_AUTOLINK;
695
+ return n+1;
696
+ }
690697
}
698
+ *pTokenType = TOKEN_CHARACTER;
699
+ return 1;
691700
}
692701
if( z[0]=='&' && (p->inVerbatim || !isElement(z)) ){
693702
*pTokenType = TOKEN_CHARACTER;
694703
return 1;
695704
}
@@ -1584,11 +1593,11 @@
15841593
char cS1 = 0;
15851594
int iS1 = 0;
15861595
15871596
startAutoParagraph(p);
15881597
if( z[n]=='('
1589
- && (p->state & WIKI_MARKDOWN_LINK)!=0
1598
+ && (p->state & WIKI_MARKDOWN_SPAN)!=0
15901599
&& (zEnd = strchr(z+n+1,')'))!=0
15911600
){
15921601
/* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
15931602
if( n>2 ){
15941603
zDisplay = &z[1];
@@ -1649,10 +1658,22 @@
16491658
htmlize_to_blob(p->pOut, z, n);
16501659
}else{
16511660
blob_append(p->pOut, z, n);
16521661
}
16531662
break;
1663
+ }
1664
+ case TOKEN_AUTOLINK: {
1665
+ /* URL enclosed in <...> */
1666
+ if( (p->state & WIKI_MARKDOWN_SPAN)==0 ){
1667
+ blob_append(p->pOut, "&lt;", 4);
1668
+ n = 1;
1669
+ }else{
1670
+ z[n-1] = 0;
1671
+ blob_appendf(p->pOut, "<a href=\"%h\">%h</a>", z+1, z+1);
1672
+ z[n-1] = '>';
1673
+ }
1674
+ break;
16541675
}
16551676
case TOKEN_MARKUP: {
16561677
const char *zId;
16571678
int iDiv;
16581679
int mAttr = parseMarkup(&markup, z);
@@ -1893,11 +1914,11 @@
18931914
** --buttons Set the WIKI_BUTTONS flag
18941915
** --dark-pikchr Render pikchrs in dark mode
18951916
** --htmlonly Set the WIKI_HTMLONLY flag
18961917
** --inline Set the WIKI_INLINE flag
18971918
** --linksonly Set the WIKI_LINKSONLY flag
1898
-** --md-links Allow markdown link syntax
1919
+** --md-span Allow markdown span syntax: links and emphasis marks
18991920
** --nobadlinks Set the WIKI_NOBADLINKS flag
19001921
** --noblock Set the WIKI_NOBLOCK flag
19011922
** --text Run the output through html_to_plaintext().
19021923
*/
19031924
void test_wiki_render(void){
@@ -1908,11 +1929,11 @@
19081929
if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
19091930
if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
19101931
if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
19111932
if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
19121933
if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
1913
- if( find_option("md-links",0,0)!=0 ) flags |= WIKI_MARKDOWN_LINK;
1934
+ if( find_option("md-span",0,0)!=0 ) flags |= WIKI_MARKDOWN_SPAN;
19141935
if( find_option("dark-pikchr",0,0)!=0 ){
19151936
pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
19161937
}
19171938
bText = find_option("text",0,0)!=0;
19181939
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
@@ -2066,11 +2087,11 @@
20662087
case TOKEN_LINK: {
20672088
char *zTarget, *zEnd;
20682089
int i;
20692090
20702091
if( z[n]=='('
2071
- && (flags & WIKI_MARKDOWN_LINK)!=0
2092
+ && (flags & WIKI_MARKDOWN_SPAN)!=0
20722093
&& (zEnd = strchr(z+n+1,')'))!=0
20732094
){
20742095
/* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
20752096
z += n+1;
20762097
zTarget = z;
20772098
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -34,11 +34,11 @@
34 #define WIKI_NEWLINE 0x040 /* Honor \n - break lines at each \n */
35 #define WIKI_MARKDOWN_URL 0x080 /* Hyperlink targets as in markdown */
36 #define WIKI_SAFE 0x100 /* Make the result safe for embedding */
37 #define WIKI_TARGET_BLANK 0x200 /* Hyperlinks go to a new window */
38 #define WIKI_NOBRACKET 0x400 /* Omit extra [..] around hyperlinks */
39 #define WIKI_MARKDOWN_LINK 0x800 /* Markdown link syntax: [display](URL) */
40 #endif
41
42
43 /*
44 ** These are the only markup attributes allowed.
@@ -435,11 +435,12 @@
435 #define TOKEN_BUL_LI 6 /* " * " */
436 #define TOKEN_NUM_LI 7 /* " # " */
437 #define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */
438 #define TOKEN_INDENT 9 /* " " */
439 #define TOKEN_RAW 10 /* Output exactly (used when wiki-use-html==1) */
440 #define TOKEN_TEXT 11 /* None of the above */
 
441
442 /*
443 ** State flags. Save the lower 16 bits for the WIKI_* flags.
444 */
445 #define AT_NEWLINE 0x0010000 /* At start of a line */
@@ -682,14 +683,22 @@
682 if( z[0]=='<' ){
683 n = html_tag_length(z);
684 if( n>0 ){
685 *pTokenType = TOKEN_MARKUP;
686 return n;
687 }else{
688 *pTokenType = TOKEN_CHARACTER;
689 return 1;
 
 
 
 
 
 
690 }
 
 
691 }
692 if( z[0]=='&' && (p->inVerbatim || !isElement(z)) ){
693 *pTokenType = TOKEN_CHARACTER;
694 return 1;
695 }
@@ -1584,11 +1593,11 @@
1584 char cS1 = 0;
1585 int iS1 = 0;
1586
1587 startAutoParagraph(p);
1588 if( z[n]=='('
1589 && (p->state & WIKI_MARKDOWN_LINK)!=0
1590 && (zEnd = strchr(z+n+1,')'))!=0
1591 ){
1592 /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
1593 if( n>2 ){
1594 zDisplay = &z[1];
@@ -1649,10 +1658,22 @@
1649 htmlize_to_blob(p->pOut, z, n);
1650 }else{
1651 blob_append(p->pOut, z, n);
1652 }
1653 break;
 
 
 
 
 
 
 
 
 
 
 
 
1654 }
1655 case TOKEN_MARKUP: {
1656 const char *zId;
1657 int iDiv;
1658 int mAttr = parseMarkup(&markup, z);
@@ -1893,11 +1914,11 @@
1893 ** --buttons Set the WIKI_BUTTONS flag
1894 ** --dark-pikchr Render pikchrs in dark mode
1895 ** --htmlonly Set the WIKI_HTMLONLY flag
1896 ** --inline Set the WIKI_INLINE flag
1897 ** --linksonly Set the WIKI_LINKSONLY flag
1898 ** --md-links Allow markdown link syntax
1899 ** --nobadlinks Set the WIKI_NOBADLINKS flag
1900 ** --noblock Set the WIKI_NOBLOCK flag
1901 ** --text Run the output through html_to_plaintext().
1902 */
1903 void test_wiki_render(void){
@@ -1908,11 +1929,11 @@
1908 if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
1909 if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
1910 if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
1911 if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
1912 if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
1913 if( find_option("md-links",0,0)!=0 ) flags |= WIKI_MARKDOWN_LINK;
1914 if( find_option("dark-pikchr",0,0)!=0 ){
1915 pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
1916 }
1917 bText = find_option("text",0,0)!=0;
1918 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
@@ -2066,11 +2087,11 @@
2066 case TOKEN_LINK: {
2067 char *zTarget, *zEnd;
2068 int i;
2069
2070 if( z[n]=='('
2071 && (flags & WIKI_MARKDOWN_LINK)!=0
2072 && (zEnd = strchr(z+n+1,')'))!=0
2073 ){
2074 /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
2075 z += n+1;
2076 zTarget = z;
2077
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -34,11 +34,11 @@
34 #define WIKI_NEWLINE 0x040 /* Honor \n - break lines at each \n */
35 #define WIKI_MARKDOWN_URL 0x080 /* Hyperlink targets as in markdown */
36 #define WIKI_SAFE 0x100 /* Make the result safe for embedding */
37 #define WIKI_TARGET_BLANK 0x200 /* Hyperlinks go to a new window */
38 #define WIKI_NOBRACKET 0x400 /* Omit extra [..] around hyperlinks */
39 #define WIKI_MARKDOWN_SPAN 0x800 /* Interpret span elements of markdown */
40 #endif
41
42
43 /*
44 ** These are the only markup attributes allowed.
@@ -435,11 +435,12 @@
435 #define TOKEN_BUL_LI 6 /* " * " */
436 #define TOKEN_NUM_LI 7 /* " # " */
437 #define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */
438 #define TOKEN_INDENT 9 /* " " */
439 #define TOKEN_RAW 10 /* Output exactly (used when wiki-use-html==1) */
440 #define TOKEN_AUTOLINK 11 /* <URL> */
441 #define TOKEN_TEXT 12 /* None of the above */
442
443 /*
444 ** State flags. Save the lower 16 bits for the WIKI_* flags.
445 */
446 #define AT_NEWLINE 0x0010000 /* At start of a line */
@@ -682,14 +683,22 @@
683 if( z[0]=='<' ){
684 n = html_tag_length(z);
685 if( n>0 ){
686 *pTokenType = TOKEN_MARKUP;
687 return n;
688 }
689 if( z[1]=='h'
690 && (strncmp(z,"<https://",9)==0 || strncmp(z,"<http://",8)==0)
691 ){
692 for(n=8; z[n] && z[n]!='>'; n++){}
693 if( z[n]=='>' ){
694 *pTokenType = TOKEN_AUTOLINK;
695 return n+1;
696 }
697 }
698 *pTokenType = TOKEN_CHARACTER;
699 return 1;
700 }
701 if( z[0]=='&' && (p->inVerbatim || !isElement(z)) ){
702 *pTokenType = TOKEN_CHARACTER;
703 return 1;
704 }
@@ -1584,11 +1593,11 @@
1593 char cS1 = 0;
1594 int iS1 = 0;
1595
1596 startAutoParagraph(p);
1597 if( z[n]=='('
1598 && (p->state & WIKI_MARKDOWN_SPAN)!=0
1599 && (zEnd = strchr(z+n+1,')'))!=0
1600 ){
1601 /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
1602 if( n>2 ){
1603 zDisplay = &z[1];
@@ -1649,10 +1658,22 @@
1658 htmlize_to_blob(p->pOut, z, n);
1659 }else{
1660 blob_append(p->pOut, z, n);
1661 }
1662 break;
1663 }
1664 case TOKEN_AUTOLINK: {
1665 /* URL enclosed in <...> */
1666 if( (p->state & WIKI_MARKDOWN_SPAN)==0 ){
1667 blob_append(p->pOut, "&lt;", 4);
1668 n = 1;
1669 }else{
1670 z[n-1] = 0;
1671 blob_appendf(p->pOut, "<a href=\"%h\">%h</a>", z+1, z+1);
1672 z[n-1] = '>';
1673 }
1674 break;
1675 }
1676 case TOKEN_MARKUP: {
1677 const char *zId;
1678 int iDiv;
1679 int mAttr = parseMarkup(&markup, z);
@@ -1893,11 +1914,11 @@
1914 ** --buttons Set the WIKI_BUTTONS flag
1915 ** --dark-pikchr Render pikchrs in dark mode
1916 ** --htmlonly Set the WIKI_HTMLONLY flag
1917 ** --inline Set the WIKI_INLINE flag
1918 ** --linksonly Set the WIKI_LINKSONLY flag
1919 ** --md-span Allow markdown span syntax: links and emphasis marks
1920 ** --nobadlinks Set the WIKI_NOBADLINKS flag
1921 ** --noblock Set the WIKI_NOBLOCK flag
1922 ** --text Run the output through html_to_plaintext().
1923 */
1924 void test_wiki_render(void){
@@ -1908,11 +1929,11 @@
1929 if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
1930 if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
1931 if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
1932 if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
1933 if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
1934 if( find_option("md-span",0,0)!=0 ) flags |= WIKI_MARKDOWN_SPAN;
1935 if( find_option("dark-pikchr",0,0)!=0 ){
1936 pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
1937 }
1938 bText = find_option("text",0,0)!=0;
1939 db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
@@ -2066,11 +2087,11 @@
2087 case TOKEN_LINK: {
2088 char *zTarget, *zEnd;
2089 int i;
2090
2091 if( z[n]=='('
2092 && (flags & WIKI_MARKDOWN_SPAN)!=0
2093 && (zEnd = strchr(z+n+1,')'))!=0
2094 ){
2095 /* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
2096 z += n+1;
2097 zTarget = z;
2098

Keyboard Shortcuts

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