Fossil SCM
For Hash or Wiki interwiki hyperlinks in Fossil Wiki without an alternative display, elide the initial interwiki tag from the display.
Commit
2d1a493d9c0c7becb68af7e13b48e9da7b6c91b168c769b1659fd0f3e952fd96
Parent
5a568d8b1f38e45…
2 files changed
+25
+1
-1
+25
| --- src/interwiki.c | ||
| +++ src/interwiki.c | ||
| @@ -111,10 +111,35 @@ | ||
| 111 | 111 | break; |
| 112 | 112 | } |
| 113 | 113 | db_finalize(&q); |
| 114 | 114 | return zUrl; |
| 115 | 115 | } |
| 116 | + | |
| 117 | +/* | |
| 118 | +** If hyperlink target zTarget begins with an interwiki tag that ought | |
| 119 | +** to be excluded from display, then return the number of characters in | |
| 120 | +** that tag. | |
| 121 | +** | |
| 122 | +** Path interwiki targets always return zero. In other words, links | |
| 123 | +** of the form: | |
| 124 | +** | |
| 125 | +** remote:/path/to/file.txt | |
| 126 | +** | |
| 127 | +** Do not have the interwiki tag removed. But Hash and Wiki links are | |
| 128 | +** transformed: | |
| 129 | +** | |
| 130 | +** src:39cb0a323f2f3fb6 -> 39cb0a323f2f3fb6 | |
| 131 | +** fossil:To Do List -> To Do List | |
| 132 | +*/ | |
| 133 | +int interwiki_removable_prefix(const char *zTarget){ | |
| 134 | + int i; | |
| 135 | + for(i=0; fossil_isalnum(zTarget[i]); i++){} | |
| 136 | + if( zTarget[i]!=':' ) return 0; | |
| 137 | + i++; | |
| 138 | + if( zTarget[i]==0 || zTarget[i]=='/' ) return 0; | |
| 139 | + return i; | |
| 140 | +} | |
| 116 | 141 | |
| 117 | 142 | /* |
| 118 | 143 | ** Verify that a name is a valid interwiki "Code". Rules: |
| 119 | 144 | ** |
| 120 | 145 | ** * ascii |
| 121 | 146 |
| --- src/interwiki.c | |
| +++ src/interwiki.c | |
| @@ -111,10 +111,35 @@ | |
| 111 | break; |
| 112 | } |
| 113 | db_finalize(&q); |
| 114 | return zUrl; |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | ** Verify that a name is a valid interwiki "Code". Rules: |
| 119 | ** |
| 120 | ** * ascii |
| 121 |
| --- src/interwiki.c | |
| +++ src/interwiki.c | |
| @@ -111,10 +111,35 @@ | |
| 111 | break; |
| 112 | } |
| 113 | db_finalize(&q); |
| 114 | return zUrl; |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | ** If hyperlink target zTarget begins with an interwiki tag that ought |
| 119 | ** to be excluded from display, then return the number of characters in |
| 120 | ** that tag. |
| 121 | ** |
| 122 | ** Path interwiki targets always return zero. In other words, links |
| 123 | ** of the form: |
| 124 | ** |
| 125 | ** remote:/path/to/file.txt |
| 126 | ** |
| 127 | ** Do not have the interwiki tag removed. But Hash and Wiki links are |
| 128 | ** transformed: |
| 129 | ** |
| 130 | ** src:39cb0a323f2f3fb6 -> 39cb0a323f2f3fb6 |
| 131 | ** fossil:To Do List -> To Do List |
| 132 | */ |
| 133 | int interwiki_removable_prefix(const char *zTarget){ |
| 134 | int i; |
| 135 | for(i=0; fossil_isalnum(zTarget[i]); i++){} |
| 136 | if( zTarget[i]!=':' ) return 0; |
| 137 | i++; |
| 138 | if( zTarget[i]==0 || zTarget[i]=='/' ) return 0; |
| 139 | return i; |
| 140 | } |
| 141 | |
| 142 | /* |
| 143 | ** Verify that a name is a valid interwiki "Code". Rules: |
| 144 | ** |
| 145 | ** * ascii |
| 146 |
+1
-1
| --- src/wikiformat.c | ||
| +++ src/wikiformat.c | ||
| @@ -1520,11 +1520,11 @@ | ||
| 1520 | 1520 | z[j] = 0; |
| 1521 | 1521 | } |
| 1522 | 1522 | } |
| 1523 | 1523 | z[i] = 0; |
| 1524 | 1524 | if( zDisplay==0 ){ |
| 1525 | - zDisplay = zTarget; | |
| 1525 | + zDisplay = zTarget + interwiki_removable_prefix(zTarget); | |
| 1526 | 1526 | }else{ |
| 1527 | 1527 | while( fossil_isspace(*zDisplay) ) zDisplay++; |
| 1528 | 1528 | } |
| 1529 | 1529 | wiki_resolve_hyperlink(p->pOut, p->state, |
| 1530 | 1530 | zTarget, zClose, sizeof(zClose), zOrig, 0); |
| 1531 | 1531 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -1520,11 +1520,11 @@ | |
| 1520 | z[j] = 0; |
| 1521 | } |
| 1522 | } |
| 1523 | z[i] = 0; |
| 1524 | if( zDisplay==0 ){ |
| 1525 | zDisplay = zTarget; |
| 1526 | }else{ |
| 1527 | while( fossil_isspace(*zDisplay) ) zDisplay++; |
| 1528 | } |
| 1529 | wiki_resolve_hyperlink(p->pOut, p->state, |
| 1530 | zTarget, zClose, sizeof(zClose), zOrig, 0); |
| 1531 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -1520,11 +1520,11 @@ | |
| 1520 | z[j] = 0; |
| 1521 | } |
| 1522 | } |
| 1523 | z[i] = 0; |
| 1524 | if( zDisplay==0 ){ |
| 1525 | zDisplay = zTarget + interwiki_removable_prefix(zTarget); |
| 1526 | }else{ |
| 1527 | while( fossil_isspace(*zDisplay) ) zDisplay++; |
| 1528 | } |
| 1529 | wiki_resolve_hyperlink(p->pOut, p->state, |
| 1530 | zTarget, zClose, sizeof(zClose), zOrig, 0); |
| 1531 |