Fossil SCM
Add support for expanding $ROOT in href= and action= of HTML output into the top-level directory of the repository.
Commit
e57ab295843aa335d3458ae2905279d03d92d7f2
Parent
f7afea949dd59c4…
1 file changed
+46
-2
+46
-2
| --- src/doc.c | ||
| +++ src/doc.c | ||
| @@ -486,10 +486,40 @@ | ||
| 486 | 486 | if( rid && content_get(rid, pContent)==0 ){ |
| 487 | 487 | rid = 0; |
| 488 | 488 | } |
| 489 | 489 | return rid; |
| 490 | 490 | } |
| 491 | + | |
| 492 | +/* | |
| 493 | +** Transfer content to the output. During the transfer, when text of | |
| 494 | +** the followign form is seen: | |
| 495 | +** | |
| 496 | +** href="$ROOT/ | |
| 497 | +** action="$ROOT/ | |
| 498 | +** | |
| 499 | +** Convert $ROOT to the root URI of the repository. Allow ' in place of " | |
| 500 | +** and any case for href. | |
| 501 | +*/ | |
| 502 | +static void convert_href_and_output(Blob *pIn){ | |
| 503 | + int i, base; | |
| 504 | + int n = blob_size(pIn); | |
| 505 | + char *z = blob_buffer(pIn); | |
| 506 | + for(base=0, i=7; i<n; i++){ | |
| 507 | + if( z[i]=='$' | |
| 508 | + && strncmp(&z[i],"$ROOT/", 6)==0 | |
| 509 | + && (z[i-1]=='\'' || z[i-1]=='"') | |
| 510 | + && i-base>=9 | |
| 511 | + && (fossil_strnicmp(&z[i-7]," href=", 6)==0 || | |
| 512 | + fossil_strnicmp(&z[i-9]," action=", 8)==0) | |
| 513 | + ){ | |
| 514 | + blob_append(cgi_output_blob(), &z[base], i-base); | |
| 515 | + blob_appendf(cgi_output_blob(), "%R"); | |
| 516 | + base = i+5; | |
| 517 | + } | |
| 518 | + } | |
| 519 | + blob_append(cgi_output_blob(), &z[base], i-base); | |
| 520 | +} | |
| 491 | 521 | |
| 492 | 522 | /* |
| 493 | 523 | ** WEBPAGE: doc |
| 494 | 524 | ** URL: /doc?name=CHECKIN/FILE |
| 495 | 525 | ** URL: /doc/CHECKIN/FILE |
| @@ -518,10 +548,24 @@ | ||
| 518 | 548 | ** and "FILE/index.md" are tried in that order. If the binary was compiled |
| 519 | 549 | ** with TH1 embedded documentation support and the "th1-docs" setting is |
| 520 | 550 | ** enabled, the name "FILE/index.th1" is also tried. If none of those are |
| 521 | 551 | ** found, then FILE is completely replaced by "404.md" and tried. If that |
| 522 | 552 | ** is not found, then a default 404 screen is generated. |
| 553 | +** | |
| 554 | +** Headers and footers are added for text/x-fossil-wiki and text/md | |
| 555 | +** If the document has mimetype text/html then headers and footers are | |
| 556 | +** usually not added. However, a text/html document begins with the | |
| 557 | +** following div: | |
| 558 | +** | |
| 559 | +** <div class='fossil-doc' data-title='TEXT'> | |
| 560 | +** | |
| 561 | +** then headers and footers are supplied. The optional data-title field | |
| 562 | +** specifies the title of the document in that case. | |
| 563 | +** | |
| 564 | +** For fossil-doc documents and for markdown documents, text of the | |
| 565 | +** form: "href='$ROOT/" or "action='$ROOT" has the $ROOT name expanded | |
| 566 | +** to the top-level of the repository. | |
| 523 | 567 | */ |
| 524 | 568 | void doc_page(void){ |
| 525 | 569 | const char *zName; /* Argument to the /doc page */ |
| 526 | 570 | const char *zOrigName = "?"; /* Original document name */ |
| 527 | 571 | const char *zMime; /* Document MIME type */ |
| @@ -621,11 +665,11 @@ | ||
| 621 | 665 | style_header("%s", blob_str(&title)); |
| 622 | 666 | }else{ |
| 623 | 667 | style_header("%s", nMiss>=ArraySize(azSuffix)? |
| 624 | 668 | "Not Found" : "Documentation"); |
| 625 | 669 | } |
| 626 | - blob_append(cgi_output_blob(), blob_buffer(&tail), blob_size(&tail)); | |
| 670 | + convert_href_and_output(&tail); | |
| 627 | 671 | style_footer(); |
| 628 | 672 | }else if( fossil_strcmp(zMime, "text/plain")==0 ){ |
| 629 | 673 | style_header("Documentation"); |
| 630 | 674 | @ <blockquote><pre> |
| 631 | 675 | @ %h(blob_str(&filebody)) |
| @@ -633,11 +677,11 @@ | ||
| 633 | 677 | style_footer(); |
| 634 | 678 | }else if( fossil_strcmp(zMime, "text/html")==0 |
| 635 | 679 | && doc_is_embedded_html(&filebody, &title) ){ |
| 636 | 680 | if( blob_size(&title)==0 ) blob_append(&title,zName,-1); |
| 637 | 681 | style_header("%s", blob_str(&title)); |
| 638 | - blob_append(cgi_output_blob(), blob_buffer(&filebody),blob_size(&filebody)); | |
| 682 | + convert_href_and_output(&filebody); | |
| 639 | 683 | style_footer(); |
| 640 | 684 | #ifdef FOSSIL_ENABLE_TH1_DOCS |
| 641 | 685 | }else if( Th_AreDocsEnabled() && |
| 642 | 686 | fossil_strcmp(zMime, "application/x-th1")==0 ){ |
| 643 | 687 | style_header("%h", zName); |
| 644 | 688 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -486,10 +486,40 @@ | |
| 486 | if( rid && content_get(rid, pContent)==0 ){ |
| 487 | rid = 0; |
| 488 | } |
| 489 | return rid; |
| 490 | } |
| 491 | |
| 492 | /* |
| 493 | ** WEBPAGE: doc |
| 494 | ** URL: /doc?name=CHECKIN/FILE |
| 495 | ** URL: /doc/CHECKIN/FILE |
| @@ -518,10 +548,24 @@ | |
| 518 | ** and "FILE/index.md" are tried in that order. If the binary was compiled |
| 519 | ** with TH1 embedded documentation support and the "th1-docs" setting is |
| 520 | ** enabled, the name "FILE/index.th1" is also tried. If none of those are |
| 521 | ** found, then FILE is completely replaced by "404.md" and tried. If that |
| 522 | ** is not found, then a default 404 screen is generated. |
| 523 | */ |
| 524 | void doc_page(void){ |
| 525 | const char *zName; /* Argument to the /doc page */ |
| 526 | const char *zOrigName = "?"; /* Original document name */ |
| 527 | const char *zMime; /* Document MIME type */ |
| @@ -621,11 +665,11 @@ | |
| 621 | style_header("%s", blob_str(&title)); |
| 622 | }else{ |
| 623 | style_header("%s", nMiss>=ArraySize(azSuffix)? |
| 624 | "Not Found" : "Documentation"); |
| 625 | } |
| 626 | blob_append(cgi_output_blob(), blob_buffer(&tail), blob_size(&tail)); |
| 627 | style_footer(); |
| 628 | }else if( fossil_strcmp(zMime, "text/plain")==0 ){ |
| 629 | style_header("Documentation"); |
| 630 | @ <blockquote><pre> |
| 631 | @ %h(blob_str(&filebody)) |
| @@ -633,11 +677,11 @@ | |
| 633 | style_footer(); |
| 634 | }else if( fossil_strcmp(zMime, "text/html")==0 |
| 635 | && doc_is_embedded_html(&filebody, &title) ){ |
| 636 | if( blob_size(&title)==0 ) blob_append(&title,zName,-1); |
| 637 | style_header("%s", blob_str(&title)); |
| 638 | blob_append(cgi_output_blob(), blob_buffer(&filebody),blob_size(&filebody)); |
| 639 | style_footer(); |
| 640 | #ifdef FOSSIL_ENABLE_TH1_DOCS |
| 641 | }else if( Th_AreDocsEnabled() && |
| 642 | fossil_strcmp(zMime, "application/x-th1")==0 ){ |
| 643 | style_header("%h", zName); |
| 644 |
| --- src/doc.c | |
| +++ src/doc.c | |
| @@ -486,10 +486,40 @@ | |
| 486 | if( rid && content_get(rid, pContent)==0 ){ |
| 487 | rid = 0; |
| 488 | } |
| 489 | return rid; |
| 490 | } |
| 491 | |
| 492 | /* |
| 493 | ** Transfer content to the output. During the transfer, when text of |
| 494 | ** the followign form is seen: |
| 495 | ** |
| 496 | ** href="$ROOT/ |
| 497 | ** action="$ROOT/ |
| 498 | ** |
| 499 | ** Convert $ROOT to the root URI of the repository. Allow ' in place of " |
| 500 | ** and any case for href. |
| 501 | */ |
| 502 | static void convert_href_and_output(Blob *pIn){ |
| 503 | int i, base; |
| 504 | int n = blob_size(pIn); |
| 505 | char *z = blob_buffer(pIn); |
| 506 | for(base=0, i=7; i<n; i++){ |
| 507 | if( z[i]=='$' |
| 508 | && strncmp(&z[i],"$ROOT/", 6)==0 |
| 509 | && (z[i-1]=='\'' || z[i-1]=='"') |
| 510 | && i-base>=9 |
| 511 | && (fossil_strnicmp(&z[i-7]," href=", 6)==0 || |
| 512 | fossil_strnicmp(&z[i-9]," action=", 8)==0) |
| 513 | ){ |
| 514 | blob_append(cgi_output_blob(), &z[base], i-base); |
| 515 | blob_appendf(cgi_output_blob(), "%R"); |
| 516 | base = i+5; |
| 517 | } |
| 518 | } |
| 519 | blob_append(cgi_output_blob(), &z[base], i-base); |
| 520 | } |
| 521 | |
| 522 | /* |
| 523 | ** WEBPAGE: doc |
| 524 | ** URL: /doc?name=CHECKIN/FILE |
| 525 | ** URL: /doc/CHECKIN/FILE |
| @@ -518,10 +548,24 @@ | |
| 548 | ** and "FILE/index.md" are tried in that order. If the binary was compiled |
| 549 | ** with TH1 embedded documentation support and the "th1-docs" setting is |
| 550 | ** enabled, the name "FILE/index.th1" is also tried. If none of those are |
| 551 | ** found, then FILE is completely replaced by "404.md" and tried. If that |
| 552 | ** is not found, then a default 404 screen is generated. |
| 553 | ** |
| 554 | ** Headers and footers are added for text/x-fossil-wiki and text/md |
| 555 | ** If the document has mimetype text/html then headers and footers are |
| 556 | ** usually not added. However, a text/html document begins with the |
| 557 | ** following div: |
| 558 | ** |
| 559 | ** <div class='fossil-doc' data-title='TEXT'> |
| 560 | ** |
| 561 | ** then headers and footers are supplied. The optional data-title field |
| 562 | ** specifies the title of the document in that case. |
| 563 | ** |
| 564 | ** For fossil-doc documents and for markdown documents, text of the |
| 565 | ** form: "href='$ROOT/" or "action='$ROOT" has the $ROOT name expanded |
| 566 | ** to the top-level of the repository. |
| 567 | */ |
| 568 | void doc_page(void){ |
| 569 | const char *zName; /* Argument to the /doc page */ |
| 570 | const char *zOrigName = "?"; /* Original document name */ |
| 571 | const char *zMime; /* Document MIME type */ |
| @@ -621,11 +665,11 @@ | |
| 665 | style_header("%s", blob_str(&title)); |
| 666 | }else{ |
| 667 | style_header("%s", nMiss>=ArraySize(azSuffix)? |
| 668 | "Not Found" : "Documentation"); |
| 669 | } |
| 670 | convert_href_and_output(&tail); |
| 671 | style_footer(); |
| 672 | }else if( fossil_strcmp(zMime, "text/plain")==0 ){ |
| 673 | style_header("Documentation"); |
| 674 | @ <blockquote><pre> |
| 675 | @ %h(blob_str(&filebody)) |
| @@ -633,11 +677,11 @@ | |
| 677 | style_footer(); |
| 678 | }else if( fossil_strcmp(zMime, "text/html")==0 |
| 679 | && doc_is_embedded_html(&filebody, &title) ){ |
| 680 | if( blob_size(&title)==0 ) blob_append(&title,zName,-1); |
| 681 | style_header("%s", blob_str(&title)); |
| 682 | convert_href_and_output(&filebody); |
| 683 | style_footer(); |
| 684 | #ifdef FOSSIL_ENABLE_TH1_DOCS |
| 685 | }else if( Th_AreDocsEnabled() && |
| 686 | fossil_strcmp(zMime, "application/x-th1")==0 ){ |
| 687 | style_header("%h", zName); |
| 688 |