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.

george 2022-02-12 20:52 markdown-footnotes
Commit b363a4dbe7d62fef6dff08a4691055da5a99aeb611d81a18595095e1c1f8fe0d
2 files changed +16 -17 +11 -1
+16 -17
--- src/markdown.c
+++ src/markdown.c
@@ -1208,21 +1208,30 @@
12081208
title = new_work_buffer(rndr);
12091209
content = new_work_buffer(rndr);
12101210
link = new_work_buffer(rndr);
12111211
ret = 0; /* error if we don't get to the callback */
12121212
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;
12151223
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 */
12181227
12191228
const size_t k = matching_bracket_offset(data+i, data+size);
12201229
if( !k ) goto char_link_cleanup;
12211230
fn = add_inline_footnote(rndr, data+(i+2), k-2);
12221231
i += k+1;
1223
- }else{
1232
+ }else{ /* inline style link */
12241233
size_t span_end = i;
12251234
while( span_end<size
12261235
&& !(data[span_end]==')' && (span_end==i || data[span_end-1]!='\\'))
12271236
){
12281237
span_end++;
@@ -1272,25 +1281,15 @@
12721281
goto char_link_cleanup;
12731282
}
12741283
12751284
i = id_end+1;
12761285
1277
- /* shortcut reference style link or free-standing footnote refernece */
1286
+ /* shortcut reference style link */
12781287
}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 ){
12891289
goto char_link_cleanup;
12901290
}
1291
-
12921291
/* rewinding a closing square bracket */
12931292
i = txt_e+1;
12941293
}
12951294
12961295
/* building content: img alt is escaped, link content is parsed */
12971296
--- 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
--- test/markdown-test3.md
+++ test/markdown-test3.md
@@ -36,11 +36,11 @@
3636
3737
[^i am strayed]:
3838
This should be presented **verbatim** (without any [markup][^])
3939
in the end of the footnotes.
4040
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.
4242
Other styling may also apply.
4343
4444
Inline footnotes are supported.(^These may be usefull for adding
4545
<s>small</s> comments.)
4646
@@ -54,10 +54,18 @@
5454
If several labeled footnote definitions have the same equal label then texts
5555
from all these definitions are joined.[^duplicate]
5656
5757
Several references should be recognized as several distinct numbers.
5858
(^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]
5967
6068
## Footnotes
6169
6270
[branch]: /timeline?r=markdown-footnotes&nowiki
6371
@@ -94,5 +102,7 @@
94102
BTW, this note may not have a backreference to the "stray".
95103
96104
[^undefined label is used]: For example due to a typo.
97105
98106
[^another stray]: Just to verify the correctness of ordering and styling.
107
+
108
+[^scipub]: Which is common in the scientific publications.
99109
--- 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

Keyboard Shortcuts

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