Fossil SCM
Be smarter about distinguishing between hyperlinks and array subscripts in code when rendering wiki.
Commit
b7abba6707167f7200ca071a9ecf6ff944533a35
Parent
8b1f5e0eab08e96…
1 file changed
+8
-2
+8
-2
| --- src/wikiformat.c | ||
| +++ src/wikiformat.c | ||
| @@ -1049,11 +1049,12 @@ | ||
| 1049 | 1049 | */ |
| 1050 | 1050 | static void openHyperlink( |
| 1051 | 1051 | Renderer *p, /* Rendering context */ |
| 1052 | 1052 | const char *zTarget, /* Hyperlink traget; text within [...] */ |
| 1053 | 1053 | char *zClose, /* Write hyperlink closing text here */ |
| 1054 | - int nClose /* Bytes available in zClose[] */ | |
| 1054 | + int nClose, /* Bytes available in zClose[] */ | |
| 1055 | + const char *zOrig /* Complete document text */ | |
| 1055 | 1056 | ){ |
| 1056 | 1057 | const char *zTerm = "</a>"; |
| 1057 | 1058 | assert( nClose>=20 ); |
| 1058 | 1059 | |
| 1059 | 1060 | if( strncmp(zTarget, "http:", 5)==0 |
| @@ -1111,10 +1112,14 @@ | ||
| 1111 | 1112 | && wiki_name_is_wellformed((const unsigned char*)zTarget) ){ |
| 1112 | 1113 | zTarget += 5; |
| 1113 | 1114 | blob_appendf(p->pOut, "<a href=\"%R/wiki?name=%T\">", zTarget); |
| 1114 | 1115 | }else if( wiki_name_is_wellformed((const unsigned char *)zTarget) ){ |
| 1115 | 1116 | blob_appendf(p->pOut, "<a href=\"%R/wiki?name=%T\">", zTarget); |
| 1117 | + }else if( zTarget>=&zOrig[2] && !fossil_isspace(zTarget[-2]) ){ | |
| 1118 | + /* Probably an array subscript in code */ | |
| 1119 | + blob_appendf(p->pOut, "["); | |
| 1120 | + zTerm = "]"; | |
| 1116 | 1121 | }else{ |
| 1117 | 1122 | blob_appendf(p->pOut, "<span class=\"brokenlink\">[%h]</span>", zTarget); |
| 1118 | 1123 | zTerm = ""; |
| 1119 | 1124 | } |
| 1120 | 1125 | assert( strlen(zTerm)<nClose ); |
| @@ -1154,10 +1159,11 @@ | ||
| 1154 | 1159 | int tokenType; |
| 1155 | 1160 | ParsedMarkup markup; |
| 1156 | 1161 | int n; |
| 1157 | 1162 | int inlineOnly = (p->state & INLINE_MARKUP_ONLY)!=0; |
| 1158 | 1163 | int wikiUseHtml = (p->state & WIKI_USE_HTML)!=0; |
| 1164 | + char *zOrig = z; | |
| 1159 | 1165 | |
| 1160 | 1166 | /* Make sure the attribute constants and names still align |
| 1161 | 1167 | ** following changes in the attribute list. */ |
| 1162 | 1168 | assert( fossil_strcmp(aAttribute[ATTR_WIDTH].zName, "width")==0 ); |
| 1163 | 1169 | |
| @@ -1289,11 +1295,11 @@ | ||
| 1289 | 1295 | if( zDisplay==0 ){ |
| 1290 | 1296 | zDisplay = zTarget; |
| 1291 | 1297 | }else{ |
| 1292 | 1298 | while( fossil_isspace(*zDisplay) ) zDisplay++; |
| 1293 | 1299 | } |
| 1294 | - openHyperlink(p, zTarget, zClose, sizeof(zClose)); | |
| 1300 | + openHyperlink(p, zTarget, zClose, sizeof(zClose), zOrig); | |
| 1295 | 1301 | savedState = p->state; |
| 1296 | 1302 | p->state &= ~ALLOW_WIKI; |
| 1297 | 1303 | p->state |= FONT_MARKUP_ONLY; |
| 1298 | 1304 | wiki_render(p, zDisplay); |
| 1299 | 1305 | p->state = savedState; |
| 1300 | 1306 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -1049,11 +1049,12 @@ | |
| 1049 | */ |
| 1050 | static void openHyperlink( |
| 1051 | Renderer *p, /* Rendering context */ |
| 1052 | const char *zTarget, /* Hyperlink traget; text within [...] */ |
| 1053 | char *zClose, /* Write hyperlink closing text here */ |
| 1054 | int nClose /* Bytes available in zClose[] */ |
| 1055 | ){ |
| 1056 | const char *zTerm = "</a>"; |
| 1057 | assert( nClose>=20 ); |
| 1058 | |
| 1059 | if( strncmp(zTarget, "http:", 5)==0 |
| @@ -1111,10 +1112,14 @@ | |
| 1111 | && wiki_name_is_wellformed((const unsigned char*)zTarget) ){ |
| 1112 | zTarget += 5; |
| 1113 | blob_appendf(p->pOut, "<a href=\"%R/wiki?name=%T\">", zTarget); |
| 1114 | }else if( wiki_name_is_wellformed((const unsigned char *)zTarget) ){ |
| 1115 | blob_appendf(p->pOut, "<a href=\"%R/wiki?name=%T\">", zTarget); |
| 1116 | }else{ |
| 1117 | blob_appendf(p->pOut, "<span class=\"brokenlink\">[%h]</span>", zTarget); |
| 1118 | zTerm = ""; |
| 1119 | } |
| 1120 | assert( strlen(zTerm)<nClose ); |
| @@ -1154,10 +1159,11 @@ | |
| 1154 | int tokenType; |
| 1155 | ParsedMarkup markup; |
| 1156 | int n; |
| 1157 | int inlineOnly = (p->state & INLINE_MARKUP_ONLY)!=0; |
| 1158 | int wikiUseHtml = (p->state & WIKI_USE_HTML)!=0; |
| 1159 | |
| 1160 | /* Make sure the attribute constants and names still align |
| 1161 | ** following changes in the attribute list. */ |
| 1162 | assert( fossil_strcmp(aAttribute[ATTR_WIDTH].zName, "width")==0 ); |
| 1163 | |
| @@ -1289,11 +1295,11 @@ | |
| 1289 | if( zDisplay==0 ){ |
| 1290 | zDisplay = zTarget; |
| 1291 | }else{ |
| 1292 | while( fossil_isspace(*zDisplay) ) zDisplay++; |
| 1293 | } |
| 1294 | openHyperlink(p, zTarget, zClose, sizeof(zClose)); |
| 1295 | savedState = p->state; |
| 1296 | p->state &= ~ALLOW_WIKI; |
| 1297 | p->state |= FONT_MARKUP_ONLY; |
| 1298 | wiki_render(p, zDisplay); |
| 1299 | p->state = savedState; |
| 1300 |
| --- src/wikiformat.c | |
| +++ src/wikiformat.c | |
| @@ -1049,11 +1049,12 @@ | |
| 1049 | */ |
| 1050 | static void openHyperlink( |
| 1051 | Renderer *p, /* Rendering context */ |
| 1052 | const char *zTarget, /* Hyperlink traget; text within [...] */ |
| 1053 | char *zClose, /* Write hyperlink closing text here */ |
| 1054 | int nClose, /* Bytes available in zClose[] */ |
| 1055 | const char *zOrig /* Complete document text */ |
| 1056 | ){ |
| 1057 | const char *zTerm = "</a>"; |
| 1058 | assert( nClose>=20 ); |
| 1059 | |
| 1060 | if( strncmp(zTarget, "http:", 5)==0 |
| @@ -1111,10 +1112,14 @@ | |
| 1112 | && wiki_name_is_wellformed((const unsigned char*)zTarget) ){ |
| 1113 | zTarget += 5; |
| 1114 | blob_appendf(p->pOut, "<a href=\"%R/wiki?name=%T\">", zTarget); |
| 1115 | }else if( wiki_name_is_wellformed((const unsigned char *)zTarget) ){ |
| 1116 | blob_appendf(p->pOut, "<a href=\"%R/wiki?name=%T\">", zTarget); |
| 1117 | }else if( zTarget>=&zOrig[2] && !fossil_isspace(zTarget[-2]) ){ |
| 1118 | /* Probably an array subscript in code */ |
| 1119 | blob_appendf(p->pOut, "["); |
| 1120 | zTerm = "]"; |
| 1121 | }else{ |
| 1122 | blob_appendf(p->pOut, "<span class=\"brokenlink\">[%h]</span>", zTarget); |
| 1123 | zTerm = ""; |
| 1124 | } |
| 1125 | assert( strlen(zTerm)<nClose ); |
| @@ -1154,10 +1159,11 @@ | |
| 1159 | int tokenType; |
| 1160 | ParsedMarkup markup; |
| 1161 | int n; |
| 1162 | int inlineOnly = (p->state & INLINE_MARKUP_ONLY)!=0; |
| 1163 | int wikiUseHtml = (p->state & WIKI_USE_HTML)!=0; |
| 1164 | char *zOrig = z; |
| 1165 | |
| 1166 | /* Make sure the attribute constants and names still align |
| 1167 | ** following changes in the attribute list. */ |
| 1168 | assert( fossil_strcmp(aAttribute[ATTR_WIDTH].zName, "width")==0 ); |
| 1169 | |
| @@ -1289,11 +1295,11 @@ | |
| 1295 | if( zDisplay==0 ){ |
| 1296 | zDisplay = zTarget; |
| 1297 | }else{ |
| 1298 | while( fossil_isspace(*zDisplay) ) zDisplay++; |
| 1299 | } |
| 1300 | openHyperlink(p, zTarget, zClose, sizeof(zClose), zOrig); |
| 1301 | savedState = p->state; |
| 1302 | p->state &= ~ALLOW_WIKI; |
| 1303 | p->state |= FONT_MARKUP_ONLY; |
| 1304 | wiki_render(p, zDisplay); |
| 1305 | p->state = savedState; |
| 1306 |