Fossil SCM
If markup is ambigous between a "span-bounded" footnote and a "free-standing" footnote followed by another footnote then interpret as the later case.
Commit
b363a4dbe7d62fef6dff08a4691055da5a99aeb611d81a18595095e1c1f8fe0d
Parent
ea66d15cf39d361…
2 files changed
+16
-17
+11
-1
+16
-17
| --- src/markdown.c | ||
| +++ src/markdown.c | ||
| @@ -1208,21 +1208,30 @@ | ||
| 1208 | 1208 | title = new_work_buffer(rndr); |
| 1209 | 1209 | content = new_work_buffer(rndr); |
| 1210 | 1210 | link = new_work_buffer(rndr); |
| 1211 | 1211 | ret = 0; /* error if we don't get to the callback */ |
| 1212 | 1212 | |
| 1213 | - /* inline style link or span-bounded inline footnote */ | |
| 1214 | - if( i<size && data[i]=='(' ){ | |
| 1213 | + /* free-standing footnote refernece */ | |
| 1214 | + if(!is_img && size>3 && data[1]=='^'){ | |
| 1215 | + /* free-standing footnote reference */ | |
| 1216 | + fn = get_footnote(rndr, data+2, txt_e-2); | |
| 1217 | + if( !fn ) { | |
| 1218 | + rndr->notes.misref.nUsed++; | |
| 1219 | + fn = &rndr->notes.misref; | |
| 1220 | + } | |
| 1221 | + release_work_buffer(rndr, content); | |
| 1222 | + content = 0; | |
| 1215 | 1223 | |
| 1216 | - /* inline footnote */ | |
| 1217 | - if( i+2<size && data[i+1]=='^' ){ | |
| 1224 | + }else if( i<size && data[i]=='(' ){ | |
| 1225 | + | |
| 1226 | + if( i+2<size && data[i+1]=='^' ){ /* span-bounded inline footnote */ | |
| 1218 | 1227 | |
| 1219 | 1228 | const size_t k = matching_bracket_offset(data+i, data+size); |
| 1220 | 1229 | if( !k ) goto char_link_cleanup; |
| 1221 | 1230 | fn = add_inline_footnote(rndr, data+(i+2), k-2); |
| 1222 | 1231 | i += k+1; |
| 1223 | - }else{ | |
| 1232 | + }else{ /* inline style link */ | |
| 1224 | 1233 | size_t span_end = i; |
| 1225 | 1234 | while( span_end<size |
| 1226 | 1235 | && !(data[span_end]==')' && (span_end==i || data[span_end-1]!='\\')) |
| 1227 | 1236 | ){ |
| 1228 | 1237 | span_end++; |
| @@ -1272,25 +1281,15 @@ | ||
| 1272 | 1281 | goto char_link_cleanup; |
| 1273 | 1282 | } |
| 1274 | 1283 | |
| 1275 | 1284 | i = id_end+1; |
| 1276 | 1285 | |
| 1277 | - /* shortcut reference style link or free-standing footnote refernece */ | |
| 1286 | + /* shortcut reference style link */ | |
| 1278 | 1287 | }else{ |
| 1279 | - if(!is_img && size>3 && data[1]=='^'){ | |
| 1280 | - /* free-standing footnote reference */ | |
| 1281 | - fn = get_footnote(rndr, data+2, txt_e-2); | |
| 1282 | - if( !fn ) { | |
| 1283 | - rndr->notes.misref.nUsed++; | |
| 1284 | - fn = &rndr->notes.misref; | |
| 1285 | - } | |
| 1286 | - release_work_buffer(rndr, content); | |
| 1287 | - content = 0; | |
| 1288 | - }else if( get_link_ref(rndr, link, title, data+1, txt_e-1)<0 ){ | |
| 1288 | + if( get_link_ref(rndr, link, title, data+1, txt_e-1)<0 ){ | |
| 1289 | 1289 | goto char_link_cleanup; |
| 1290 | 1290 | } |
| 1291 | - | |
| 1292 | 1291 | /* rewinding a closing square bracket */ |
| 1293 | 1292 | i = txt_e+1; |
| 1294 | 1293 | } |
| 1295 | 1294 | |
| 1296 | 1295 | /* building content: img alt is escaped, link content is parsed */ |
| 1297 | 1296 |
| --- src/markdown.c | |
| +++ src/markdown.c | |
| @@ -1208,21 +1208,30 @@ | |
| 1208 | title = new_work_buffer(rndr); |
| 1209 | content = new_work_buffer(rndr); |
| 1210 | link = new_work_buffer(rndr); |
| 1211 | ret = 0; /* error if we don't get to the callback */ |
| 1212 | |
| 1213 | /* inline style link or span-bounded inline footnote */ |
| 1214 | if( i<size && data[i]=='(' ){ |
| 1215 | |
| 1216 | /* inline footnote */ |
| 1217 | if( i+2<size && data[i+1]=='^' ){ |
| 1218 | |
| 1219 | const size_t k = matching_bracket_offset(data+i, data+size); |
| 1220 | if( !k ) goto char_link_cleanup; |
| 1221 | fn = add_inline_footnote(rndr, data+(i+2), k-2); |
| 1222 | i += k+1; |
| 1223 | }else{ |
| 1224 | size_t span_end = i; |
| 1225 | while( span_end<size |
| 1226 | && !(data[span_end]==')' && (span_end==i || data[span_end-1]!='\\')) |
| 1227 | ){ |
| 1228 | span_end++; |
| @@ -1272,25 +1281,15 @@ | |
| 1272 | goto char_link_cleanup; |
| 1273 | } |
| 1274 | |
| 1275 | i = id_end+1; |
| 1276 | |
| 1277 | /* shortcut reference style link or free-standing footnote refernece */ |
| 1278 | }else{ |
| 1279 | if(!is_img && size>3 && data[1]=='^'){ |
| 1280 | /* free-standing footnote reference */ |
| 1281 | fn = get_footnote(rndr, data+2, txt_e-2); |
| 1282 | if( !fn ) { |
| 1283 | rndr->notes.misref.nUsed++; |
| 1284 | fn = &rndr->notes.misref; |
| 1285 | } |
| 1286 | release_work_buffer(rndr, content); |
| 1287 | content = 0; |
| 1288 | }else if( get_link_ref(rndr, link, title, data+1, txt_e-1)<0 ){ |
| 1289 | goto char_link_cleanup; |
| 1290 | } |
| 1291 | |
| 1292 | /* rewinding a closing square bracket */ |
| 1293 | i = txt_e+1; |
| 1294 | } |
| 1295 | |
| 1296 | /* building content: img alt is escaped, link content is parsed */ |
| 1297 |
| --- src/markdown.c | |
| +++ src/markdown.c | |
| @@ -1208,21 +1208,30 @@ | |
| 1208 | title = new_work_buffer(rndr); |
| 1209 | content = new_work_buffer(rndr); |
| 1210 | link = new_work_buffer(rndr); |
| 1211 | ret = 0; /* error if we don't get to the callback */ |
| 1212 | |
| 1213 | /* free-standing footnote refernece */ |
| 1214 | if(!is_img && size>3 && data[1]=='^'){ |
| 1215 | /* free-standing footnote reference */ |
| 1216 | fn = get_footnote(rndr, data+2, txt_e-2); |
| 1217 | if( !fn ) { |
| 1218 | rndr->notes.misref.nUsed++; |
| 1219 | fn = &rndr->notes.misref; |
| 1220 | } |
| 1221 | release_work_buffer(rndr, content); |
| 1222 | content = 0; |
| 1223 | |
| 1224 | }else if( i<size && data[i]=='(' ){ |
| 1225 | |
| 1226 | if( i+2<size && data[i+1]=='^' ){ /* span-bounded inline footnote */ |
| 1227 | |
| 1228 | const size_t k = matching_bracket_offset(data+i, data+size); |
| 1229 | if( !k ) goto char_link_cleanup; |
| 1230 | fn = add_inline_footnote(rndr, data+(i+2), k-2); |
| 1231 | i += k+1; |
| 1232 | }else{ /* inline style link */ |
| 1233 | size_t span_end = i; |
| 1234 | while( span_end<size |
| 1235 | && !(data[span_end]==')' && (span_end==i || data[span_end-1]!='\\')) |
| 1236 | ){ |
| 1237 | span_end++; |
| @@ -1272,25 +1281,15 @@ | |
| 1281 | goto char_link_cleanup; |
| 1282 | } |
| 1283 | |
| 1284 | i = id_end+1; |
| 1285 | |
| 1286 | /* shortcut reference style link */ |
| 1287 | }else{ |
| 1288 | if( get_link_ref(rndr, link, title, data+1, txt_e-1)<0 ){ |
| 1289 | goto char_link_cleanup; |
| 1290 | } |
| 1291 | /* rewinding a closing square bracket */ |
| 1292 | i = txt_e+1; |
| 1293 | } |
| 1294 | |
| 1295 | /* building content: img alt is escaped, link content is parsed */ |
| 1296 |
+11
-1
| --- test/markdown-test3.md | ||
| +++ test/markdown-test3.md | ||
| @@ -36,11 +36,11 @@ | ||
| 36 | 36 | |
| 37 | 37 | [^i am strayed]: |
| 38 | 38 | This should be presented **verbatim** (without any [markup][^]) |
| 39 | 39 | in the end of the footnotes. |
| 40 | 40 | |
| 41 | - Default skin renders label in red bold font and the main text as gray. | |
| 41 | + Default skin renders label in red font and the main text in gray. | |
| 42 | 42 | Other styling may also apply. |
| 43 | 43 | |
| 44 | 44 | Inline footnotes are supported.(^These may be usefull for adding |
| 45 | 45 | <s>small</s> comments.) |
| 46 | 46 | |
| @@ -54,10 +54,18 @@ | ||
| 54 | 54 | If several labeled footnote definitions have the same equal label then texts |
| 55 | 55 | from all these definitions are joined.[^duplicate] |
| 56 | 56 | |
| 57 | 57 | Several references should be recognized as several distinct numbers. |
| 58 | 58 | (^There should be an interval between numbers.) [^many-refs] |
| 59 | + | |
| 60 | +If markup is ambigous between a span-bounded footnote and | |
| 61 | +a "free-standing" footnote followed by another footnote | |
| 62 | +then interpret as the later case. | |
| 63 | +This facilitates the usage in the usual case | |
| 64 | +when several footnotes are refenrenced at the end | |
| 65 | +of a phrase.[^scipub][^many-refs](^All these four should | |
| 66 | +be parsed as "free-standing" footnotes)[^Coelurosauria] | |
| 59 | 67 | |
| 60 | 68 | ## Footnotes |
| 61 | 69 | |
| 62 | 70 | [branch]: /timeline?r=markdown-footnotes&nowiki |
| 63 | 71 | |
| @@ -94,5 +102,7 @@ | ||
| 94 | 102 | BTW, this note may not have a backreference to the "stray". |
| 95 | 103 | |
| 96 | 104 | [^undefined label is used]: For example due to a typo. |
| 97 | 105 | |
| 98 | 106 | [^another stray]: Just to verify the correctness of ordering and styling. |
| 107 | + | |
| 108 | +[^scipub]: Which is common in the scientific publications. | |
| 99 | 109 |
| --- test/markdown-test3.md | |
| +++ test/markdown-test3.md | |
| @@ -36,11 +36,11 @@ | |
| 36 | |
| 37 | [^i am strayed]: |
| 38 | This should be presented **verbatim** (without any [markup][^]) |
| 39 | in the end of the footnotes. |
| 40 | |
| 41 | Default skin renders label in red bold font and the main text as gray. |
| 42 | Other styling may also apply. |
| 43 | |
| 44 | Inline footnotes are supported.(^These may be usefull for adding |
| 45 | <s>small</s> comments.) |
| 46 | |
| @@ -54,10 +54,18 @@ | |
| 54 | If several labeled footnote definitions have the same equal label then texts |
| 55 | from all these definitions are joined.[^duplicate] |
| 56 | |
| 57 | Several references should be recognized as several distinct numbers. |
| 58 | (^There should be an interval between numbers.) [^many-refs] |
| 59 | |
| 60 | ## Footnotes |
| 61 | |
| 62 | [branch]: /timeline?r=markdown-footnotes&nowiki |
| 63 | |
| @@ -94,5 +102,7 @@ | |
| 94 | BTW, this note may not have a backreference to the "stray". |
| 95 | |
| 96 | [^undefined label is used]: For example due to a typo. |
| 97 | |
| 98 | [^another stray]: Just to verify the correctness of ordering and styling. |
| 99 |
| --- test/markdown-test3.md | |
| +++ test/markdown-test3.md | |
| @@ -36,11 +36,11 @@ | |
| 36 | |
| 37 | [^i am strayed]: |
| 38 | This should be presented **verbatim** (without any [markup][^]) |
| 39 | in the end of the footnotes. |
| 40 | |
| 41 | Default skin renders label in red font and the main text in gray. |
| 42 | Other styling may also apply. |
| 43 | |
| 44 | Inline footnotes are supported.(^These may be usefull for adding |
| 45 | <s>small</s> comments.) |
| 46 | |
| @@ -54,10 +54,18 @@ | |
| 54 | If several labeled footnote definitions have the same equal label then texts |
| 55 | from all these definitions are joined.[^duplicate] |
| 56 | |
| 57 | Several references should be recognized as several distinct numbers. |
| 58 | (^There should be an interval between numbers.) [^many-refs] |
| 59 | |
| 60 | If markup is ambigous between a span-bounded footnote and |
| 61 | a "free-standing" footnote followed by another footnote |
| 62 | then interpret as the later case. |
| 63 | This facilitates the usage in the usual case |
| 64 | when several footnotes are refenrenced at the end |
| 65 | of a phrase.[^scipub][^many-refs](^All these four should |
| 66 | be parsed as "free-standing" footnotes)[^Coelurosauria] |
| 67 | |
| 68 | ## Footnotes |
| 69 | |
| 70 | [branch]: /timeline?r=markdown-footnotes&nowiki |
| 71 | |
| @@ -94,5 +102,7 @@ | |
| 102 | BTW, this note may not have a backreference to the "stray". |
| 103 | |
| 104 | [^undefined label is used]: For example due to a typo. |
| 105 | |
| 106 | [^another stray]: Just to verify the correctness of ordering and styling. |
| 107 | |
| 108 | [^scipub]: Which is common in the scientific publications. |
| 109 |