Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Add support for magic conversion of /doc/$SELF/ URIs by expanding the $SELF to the version of the currently displayed document. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
703e62a68e87aea76d753ffb0410ea29 |
| User & Date: | drh 2019-12-18 15:11:59.016 |
Context
|
2019-12-18
| ||
| 15:19 | Comment updates that should have been in the previous check-in, but I didn't press the "Save" button on my editor, and I failed to adequately review the changes before committed - I should follow my own checklists... ... (check-in: c865e1a0fc user: drh tags: trunk) | |
| 15:11 | Add support for magic conversion of /doc/$SELF/ URIs by expanding the $SELF to the version of the currently displayed document. ... (check-in: 703e62a68e user: drh tags: trunk) | |
| 14:02 | Add a test document to verify that relative path hyperlinks work in the Markdown formatter. ... (check-in: 367f9b32d6 user: drh tags: trunk) | |
Changes
Changes to src/doc.c.
| ︙ | ︙ | |||
505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
rid = db_int(0, "SELECT rid FROM vcache"
" WHERE vid=%d AND fname=%Q", vid, zName);
if( rid && content_get(rid, pContent)==0 ){
rid = 0;
}
return rid;
}
/*
** Transfer content to the output. During the transfer, when text of
** the following form is seen:
**
** href="$ROOT/
** action="$ROOT/
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 |
rid = db_int(0, "SELECT rid FROM vcache"
" WHERE vid=%d AND fname=%Q", vid, zName);
if( rid && content_get(rid, pContent)==0 ){
rid = 0;
}
return rid;
}
/*
** Check to verify that z[i] is contained within HTML markup.
**
** This works by looking backwards in the string for the most recent
** '<' or '>' character. If a '<' is found first, then we assume that
** z[i] is within markup. If a '>' is seen or neither character is seen,
** then z[i] is not within markup.
*/
static int isWithinHtmlMarkup(const char *z, int i){
while( i>=0 && z[i]!='>' && z[i]!='<' ){ i--; }
return z[i]=='<';
}
/*
** Check to see if z[i] is contained within an href='...' of markup.
*/
static int isWithinHref(const char *z, int i){
while( i>5
&& !fossil_isspace(z[i])
&& z[i]!='\'' && z[i]!='"'
&& z[i]!='>'
){ i--; }
if( i<=6 ) return 0;
if( z[i]!='\'' && z[i]!='\"' ) return 0;
if( strncmp(&z[i-5],"href=",5)!=0 ) return 0;
if( !fossil_isspace(z[i-6]) ) return 0;
return 1;
}
/*
** Transfer content to the output. During the transfer, when text of
** the following form is seen:
**
** href="$ROOT/
** action="$ROOT/
|
| ︙ | ︙ | |||
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
for(base=0, i=7; i<n; i++){
if( z[i]=='$'
&& strncmp(&z[i],"$ROOT/", 6)==0
&& (z[i-1]=='\'' || z[i-1]=='"')
&& i-base>=9
&& ((fossil_strnicmp(&z[i-6],"href=",5)==0 && fossil_isspace(z[i-7])) ||
(fossil_strnicmp(&z[i-8],"action=",7)==0 && fossil_isspace(z[i-9])) )
){
blob_append(cgi_output_blob(), &z[base], i-base);
blob_appendf(cgi_output_blob(), "%R");
base = i+5;
}
}
blob_append(cgi_output_blob(), &z[base], i-base);
}
/*
** Render a document as the reply to the HTTP request. The body
| > > > > > > > > > > > > > | 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
for(base=0, i=7; i<n; i++){
if( z[i]=='$'
&& strncmp(&z[i],"$ROOT/", 6)==0
&& (z[i-1]=='\'' || z[i-1]=='"')
&& i-base>=9
&& ((fossil_strnicmp(&z[i-6],"href=",5)==0 && fossil_isspace(z[i-7])) ||
(fossil_strnicmp(&z[i-8],"action=",7)==0 && fossil_isspace(z[i-9])) )
&& isWithinHtmlMarkup(z, i-6)
){
blob_append(cgi_output_blob(), &z[base], i-base);
blob_appendf(cgi_output_blob(), "%R");
base = i+5;
}else
if( z[i]=='$'
&& strncmp(&z[i-5],"/doc/$SELF/", 11)==0
&& isWithinHref(z,i-5)
&& isWithinHtmlMarkup(z, i-5)
&& strncmp(g.zPath, "doc/",4)==0
){
int j;
for(j=4; g.zPath[j] && g.zPath[j]!='/'; j++){}
blob_append(cgi_output_blob(), &z[base], i-base);
blob_appendf(cgi_output_blob(), "%.*s", j-4, g.zPath+4);
base = i+5;
}
}
blob_append(cgi_output_blob(), &z[base], i-base);
}
/*
** Render a document as the reply to the HTTP request. The body
|
| ︙ | ︙ |
Changes to www/mdtest/test1.md.
1 2 | # Markdown Link-test | | > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # Markdown Link-test This document exist solely as a test for some of the hyperlinking capabilities of Markdown as implemented by Fossil. ## Relative-Path Links * The index: [](../index.wiki) * Load management: [](../loadmgmt.md) * Site-map: [](../../../../sitemap) * Windows CGI: [](../server/windows/cgi.md) ## The Magic $ROOT Path Prefix In text of the form `href="$ROOT/..."` in the HTML that markdown generates, the $ROOT is replaced by the complete URI for the root of the document tree. Note that the $ROOT translation only occurs within the `<a href="...">` element, not within the text of the hyperlink. So you should see the $ROOT text on this page, but if you mouse-over the hyperlink the $ROOT value should have been expanded to the actual document root. * Timeline: []($ROOT/timeline) * Site-map: []($ROOT/sitemap) The $ROOT prefix on markdown links is superfluous. The same link works without the $ROOT prefix. (Though: the $ROOT prefix is required for HTML documents.) * Timeline: [](/timeline) * Help: [](/help?cmd=help) * Site-map: [](/sitemap) ## The Magic $SELF Document Version Translation In URI text of the form `.../doc/$SELF/...` the $SELF value is converted to the version number of the document currently being displayed. This conversion happens after translation into HTML and only occurs on href='...' attributes so it does not occur for plain text. * Document index: [](/doc/$SELF/www/index.wiki) Both the $ROOT and the $SELF conversions can occur on the same link. * Document index: []($ROOT/doc/$SELF/www/index.wiki) The translations must be contained within HTML markup in order to work. They do not work for ordinary text that appears to be an href= attribute. * `x href='$ROOT/timeline'` * `x action="$ROOT/whatever"` * `x href="https://some-other-site.com/doc/$SELF/tail"` |