Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | 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. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | comment-markdown-links |
| Files: | files | file ages | folders |
| SHA3-256: |
f80b89217883956d76b1cb22d7c26a2d |
| User & Date: | drh 2025-03-04 11:48:16.995 |
Context
|
2025-03-04
| ||
| 12:21 | Add the timeline-markdown-span setting that controls whether or not markdown span markup will be interpreted in check-in comments. Add auto-links. Support for emphasis and code marks is pending. check-in: 8f55b909c4 user: drh tags: comment-markdown-links | |
| 11:48 | 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. check-in: f80b892178 user: drh tags: comment-markdown-links | |
| 00:39 | Proof-of-concept code that allows markdown-style hyperlinks to appear in check-in comments. Markdown-style hyperlinks are not allowed in ordinary text/x-fossil-wiki for backwards compatibility. This simply change reduces the need to provide full markdown support for check-in comments. check-in: e7bc33f080 user: drh tags: comment-markdown-links | |
Changes
Changes to src/backlink.c.
| ︙ | ︙ | |||
370 371 372 373 374 375 376 |
assert( ValidBklnk(srctype) );
assert( ValidMTC(mimetype) );
bklnk.srctype = srctype;
bklnk.mtime = mtime;
if( mimetype==MT_NONE || mimetype==MT_WIKI ){
int flags;
if( srctype==BKLNK_COMMENT ){
| | | 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 |
assert( ValidBklnk(srctype) );
assert( ValidMTC(mimetype) );
bklnk.srctype = srctype;
bklnk.mtime = mtime;
if( mimetype==MT_NONE || mimetype==MT_WIKI ){
int flags;
if( srctype==BKLNK_COMMENT ){
flags = WIKI_INLINE | WIKI_MARKDOWN_SPAN;
}else{
flags = 0;
}
wiki_extract_links(zSrc, &bklnk, flags);
}else if( mimetype==MT_MARKDOWN ){
markdown_extract_links(zSrc, &bklnk);
}
|
| ︙ | ︙ |
Changes to src/printf.c.
| ︙ | ︙ | |||
262 263 264 265 266 267 268 |
}
if( db_get_boolean("timeline-plaintext", 0) ){
wikiFlags |= WIKI_LINKSONLY;
}
if( db_get_boolean("timeline-hard-newlines", 0) ){
wikiFlags |= WIKI_NEWLINE;
}
| > | > | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
}
if( db_get_boolean("timeline-plaintext", 0) ){
wikiFlags |= WIKI_LINKSONLY;
}
if( db_get_boolean("timeline-hard-newlines", 0) ){
wikiFlags |= WIKI_NEWLINE;
}
if( db_get_boolean("timeline-markdown-span", 1) ){
wikiFlags |= WIKI_MARKDOWN_SPAN;
}
}
if( altForm2 ){
/* block markup (ex: <p>, <table>) allowed */
return wikiFlags & ~WIKI_NOBLOCK;
}else{
/* Do not allow any block format. Everything in a <span> */
return wikiFlags;
|
| ︙ | ︙ |
Changes to src/wikiformat.c.
| ︙ | ︙ | |||
32 33 34 35 36 37 38 | #define WIKI_NOBADLINKS 0x010 /* Ignore broken hyperlinks */ #define WIKI_LINKSONLY 0x020 /* No markup. Only decorate links */ #define WIKI_NEWLINE 0x040 /* Honor \n - break lines at each \n */ #define WIKI_MARKDOWN_URL 0x080 /* Hyperlink targets as in markdown */ #define WIKI_SAFE 0x100 /* Make the result safe for embedding */ #define WIKI_TARGET_BLANK 0x200 /* Hyperlinks go to a new window */ #define WIKI_NOBRACKET 0x400 /* Omit extra [..] around hyperlinks */ | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#define WIKI_NOBADLINKS 0x010 /* Ignore broken hyperlinks */
#define WIKI_LINKSONLY 0x020 /* No markup. Only decorate links */
#define WIKI_NEWLINE 0x040 /* Honor \n - break lines at each \n */
#define WIKI_MARKDOWN_URL 0x080 /* Hyperlink targets as in markdown */
#define WIKI_SAFE 0x100 /* Make the result safe for embedding */
#define WIKI_TARGET_BLANK 0x200 /* Hyperlinks go to a new window */
#define WIKI_NOBRACKET 0x400 /* Omit extra [..] around hyperlinks */
#define WIKI_MARKDOWN_SPAN 0x800 /* Interpret span elements of markdown */
#endif
/*
** These are the only markup attributes allowed.
*/
enum allowed_attr_t {
|
| ︙ | ︙ | |||
433 434 435 436 437 438 439 | #define TOKEN_PARAGRAPH 4 /* blank lines */ #define TOKEN_NEWLINE 5 /* A single "\n" */ #define TOKEN_BUL_LI 6 /* " * " */ #define TOKEN_NUM_LI 7 /* " # " */ #define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */ #define TOKEN_INDENT 9 /* " " */ #define TOKEN_RAW 10 /* Output exactly (used when wiki-use-html==1) */ | > | | 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | #define TOKEN_PARAGRAPH 4 /* blank lines */ #define TOKEN_NEWLINE 5 /* A single "\n" */ #define TOKEN_BUL_LI 6 /* " * " */ #define TOKEN_NUM_LI 7 /* " # " */ #define TOKEN_ENUM 8 /* " \(?\d+[.)]? " */ #define TOKEN_INDENT 9 /* " " */ #define TOKEN_RAW 10 /* Output exactly (used when wiki-use-html==1) */ #define TOKEN_AUTOLINK 11 /* <URL> */ #define TOKEN_TEXT 12 /* None of the above */ /* ** State flags. Save the lower 16 bits for the WIKI_* flags. */ #define AT_NEWLINE 0x0010000 /* At start of a line */ #define AT_PARAGRAPH 0x0020000 /* At start of a paragraph */ #define ALLOW_WIKI 0x0040000 /* Allow wiki markup */ |
| ︙ | ︙ | |||
680 681 682 683 684 685 686 |
static int nextWikiToken(const char *z, Renderer *p, int *pTokenType){
int n;
if( z[0]=='<' ){
n = html_tag_length(z);
if( n>0 ){
*pTokenType = TOKEN_MARKUP;
return n;
| < > > > > > > | | | > > > | 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
static int nextWikiToken(const char *z, Renderer *p, int *pTokenType){
int n;
if( z[0]=='<' ){
n = html_tag_length(z);
if( n>0 ){
*pTokenType = TOKEN_MARKUP;
return n;
}
if( z[1]=='h'
&& (strncmp(z,"<https://",9)==0 || strncmp(z,"<http://",8)==0)
){
for(n=8; z[n] && z[n]!='>'; n++){}
if( z[n]=='>' ){
*pTokenType = TOKEN_AUTOLINK;
return n+1;
}
}
*pTokenType = TOKEN_CHARACTER;
return 1;
}
if( z[0]=='&' && (p->inVerbatim || !isElement(z)) ){
*pTokenType = TOKEN_CHARACTER;
return 1;
}
if( (p->state & ALLOW_WIKI)!=0 ){
if( z[0]=='\n' ){
|
| ︙ | ︙ | |||
1582 1583 1584 1585 1586 1587 1588 |
int savedState;
char zClose[20];
char cS1 = 0;
int iS1 = 0;
startAutoParagraph(p);
if( z[n]=='('
| | | 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 |
int savedState;
char zClose[20];
char cS1 = 0;
int iS1 = 0;
startAutoParagraph(p);
if( z[n]=='('
&& (p->state & WIKI_MARKDOWN_SPAN)!=0
&& (zEnd = strchr(z+n+1,')'))!=0
){
/* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
if( n>2 ){
zDisplay = &z[1];
z[n] = 0;
}else{
|
| ︙ | ︙ | |||
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 |
case TOKEN_RAW: {
if( linksOnly ){
htmlize_to_blob(p->pOut, z, n);
}else{
blob_append(p->pOut, z, n);
}
break;
}
case TOKEN_MARKUP: {
const char *zId;
int iDiv;
int mAttr = parseMarkup(&markup, z);
/* Convert <title> to <h1 align='center'> */
| > > > > > > > > > > > > | 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 |
case TOKEN_RAW: {
if( linksOnly ){
htmlize_to_blob(p->pOut, z, n);
}else{
blob_append(p->pOut, z, n);
}
break;
}
case TOKEN_AUTOLINK: {
/* URL enclosed in <...> */
if( (p->state & WIKI_MARKDOWN_SPAN)==0 ){
blob_append(p->pOut, "<", 4);
n = 1;
}else{
z[n-1] = 0;
blob_appendf(p->pOut, "<a href=\"%h\">%h</a>", z+1, z+1);
z[n-1] = '>';
}
break;
}
case TOKEN_MARKUP: {
const char *zId;
int iDiv;
int mAttr = parseMarkup(&markup, z);
/* Convert <title> to <h1 align='center'> */
|
| ︙ | ︙ | |||
1891 1892 1893 1894 1895 1896 1897 | ** ** Options: ** --buttons Set the WIKI_BUTTONS flag ** --dark-pikchr Render pikchrs in dark mode ** --htmlonly Set the WIKI_HTMLONLY flag ** --inline Set the WIKI_INLINE flag ** --linksonly Set the WIKI_LINKSONLY flag | | | | 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 |
**
** Options:
** --buttons Set the WIKI_BUTTONS flag
** --dark-pikchr Render pikchrs in dark mode
** --htmlonly Set the WIKI_HTMLONLY flag
** --inline Set the WIKI_INLINE flag
** --linksonly Set the WIKI_LINKSONLY flag
** --md-span Allow markdown span syntax: links and emphasis marks
** --nobadlinks Set the WIKI_NOBADLINKS flag
** --noblock Set the WIKI_NOBLOCK flag
** --text Run the output through html_to_plaintext().
*/
void test_wiki_render(void){
Blob in, out;
int flags = 0;
int bText;
if( find_option("buttons",0,0)!=0 ) flags |= WIKI_BUTTONS;
if( find_option("htmlonly",0,0)!=0 ) flags |= WIKI_HTMLONLY;
if( find_option("linksonly",0,0)!=0 ) flags |= WIKI_LINKSONLY;
if( find_option("nobadlinks",0,0)!=0 ) flags |= WIKI_NOBADLINKS;
if( find_option("inline",0,0)!=0 ) flags |= WIKI_INLINE;
if( find_option("noblock",0,0)!=0 ) flags |= WIKI_NOBLOCK;
if( find_option("md-span",0,0)!=0 ) flags |= WIKI_MARKDOWN_SPAN;
if( find_option("dark-pikchr",0,0)!=0 ){
pikchr_to_html_add_flags( PIKCHR_PROCESS_DARK_MODE );
}
bText = find_option("text",0,0)!=0;
db_find_and_open_repository(OPEN_OK_NOT_FOUND|OPEN_SUBSTITUTE,0);
verify_all_options();
if( g.argc!=3 ) usage("FILE");
|
| ︙ | ︙ | |||
2064 2065 2066 2067 2068 2069 2070 |
}
switch( tokenType ){
case TOKEN_LINK: {
char *zTarget, *zEnd;
int i;
if( z[n]=='('
| | | 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 |
}
switch( tokenType ){
case TOKEN_LINK: {
char *zTarget, *zEnd;
int i;
if( z[n]=='('
&& (flags & WIKI_MARKDOWN_SPAN)!=0
&& (zEnd = strchr(z+n+1,')'))!=0
){
/* Markdown-style hyperlinks: [display-text](URL) or [](URL) */
z += n+1;
zTarget = z;
for(i=1; z[i] && z[i]!=')' && z[i]!=' '; i++){}
n = (int)(zEnd - z) + 1;
|
| ︙ | ︙ |