Fossil SCM

Be smarter about distinguishing between hyperlinks and array subscripts in code when rendering wiki.

drh 2012-09-04 23:13 trunk
Commit b7abba6707167f7200ca071a9ecf6ff944533a35
1 file changed +8 -2
--- src/wikiformat.c
+++ src/wikiformat.c
@@ -1049,11 +1049,12 @@
10491049
*/
10501050
static void openHyperlink(
10511051
Renderer *p, /* Rendering context */
10521052
const char *zTarget, /* Hyperlink traget; text within [...] */
10531053
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 */
10551056
){
10561057
const char *zTerm = "</a>";
10571058
assert( nClose>=20 );
10581059
10591060
if( strncmp(zTarget, "http:", 5)==0
@@ -1111,10 +1112,14 @@
11111112
&& wiki_name_is_wellformed((const unsigned char*)zTarget) ){
11121113
zTarget += 5;
11131114
blob_appendf(p->pOut, "<a href=\"%R/wiki?name=%T\">", zTarget);
11141115
}else if( wiki_name_is_wellformed((const unsigned char *)zTarget) ){
11151116
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 = "]";
11161121
}else{
11171122
blob_appendf(p->pOut, "<span class=\"brokenlink\">[%h]</span>", zTarget);
11181123
zTerm = "";
11191124
}
11201125
assert( strlen(zTerm)<nClose );
@@ -1154,10 +1159,11 @@
11541159
int tokenType;
11551160
ParsedMarkup markup;
11561161
int n;
11571162
int inlineOnly = (p->state & INLINE_MARKUP_ONLY)!=0;
11581163
int wikiUseHtml = (p->state & WIKI_USE_HTML)!=0;
1164
+ char *zOrig = z;
11591165
11601166
/* Make sure the attribute constants and names still align
11611167
** following changes in the attribute list. */
11621168
assert( fossil_strcmp(aAttribute[ATTR_WIDTH].zName, "width")==0 );
11631169
@@ -1289,11 +1295,11 @@
12891295
if( zDisplay==0 ){
12901296
zDisplay = zTarget;
12911297
}else{
12921298
while( fossil_isspace(*zDisplay) ) zDisplay++;
12931299
}
1294
- openHyperlink(p, zTarget, zClose, sizeof(zClose));
1300
+ openHyperlink(p, zTarget, zClose, sizeof(zClose), zOrig);
12951301
savedState = p->state;
12961302
p->state &= ~ALLOW_WIKI;
12971303
p->state |= FONT_MARKUP_ONLY;
12981304
wiki_render(p, zDisplay);
12991305
p->state = savedState;
13001306
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button