Fossil

Check-in [b363a4db]
Login

Check-in [b363a4db]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:If markup is ambigous between a "span-bounded" footnote and a "free-standing" footnote followed by another footnote then interpret as the later case.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | markdown-footnotes
Files: files | file ages | folders
SHA3-256: b363a4dbe7d62fef6dff08a4691055da5a99aeb611d81a18595095e1c1f8fe0d
User & Date: george 2022-02-12 20:52:21
Context
2022-02-13
19:29
Fix parsing of "free-standing" footnotes that was (slightly) broken by the previous check-in. ... (check-in: 23c3e0b2 user: george tags: markdown-footnotes)
2022-02-12
20:52
If markup is ambigous between a "span-bounded" footnote and a "free-standing" footnote followed by another footnote then interpret as the later case. ... (check-in: b363a4db user: george tags: markdown-footnotes)
2022-02-11
01:26
Fix parsing of a multiline definition of labeled footnote for the case when lines end with CR+LF. ... (check-in: ea66d15c user: george tags: markdown-footnotes)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/markdown.c.

1206
1207
1208
1209
1210
1211
1212










1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230

  /* allocate temporary buffers to store content, link and title */
  title = new_work_buffer(rndr);
  content = new_work_buffer(rndr);
  link = new_work_buffer(rndr);
  ret = 0; /* error if we don't get to the callback */











  /* inline style link or span-bounded inline footnote */
  if( i<size && data[i]=='(' ){

    /* inline footnote */
    if( i+2<size && data[i+1]=='^' ){

      const size_t k = matching_bracket_offset(data+i, data+size);
      if( !k ) goto char_link_cleanup;
      fn = add_inline_footnote(rndr, data+(i+2), k-2);
      i += k+1;
    }else{
      size_t span_end = i;
      while( span_end<size
       && !(data[span_end]==')' && (span_end==i || data[span_end-1]!='\\'))
      ){
        span_end++;
      }








>
>
>
>
>
>
>
>
>
>
|
|

<
|





|







1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225

1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239

  /* allocate temporary buffers to store content, link and title */
  title = new_work_buffer(rndr);
  content = new_work_buffer(rndr);
  link = new_work_buffer(rndr);
  ret = 0; /* error if we don't get to the callback */

  /* free-standing footnote refernece */
  if(!is_img && size>3 && data[1]=='^'){
      /* free-standing footnote reference */
      fn = get_footnote(rndr, data+2, txt_e-2);
      if( !fn ) {
        rndr->notes.misref.nUsed++;
        fn = &rndr->notes.misref;
      }
      release_work_buffer(rndr, content);
      content = 0;

  }else if( i<size && data[i]=='(' ){


    if( i+2<size && data[i+1]=='^' ){  /* span-bounded inline footnote */

      const size_t k = matching_bracket_offset(data+i, data+size);
      if( !k ) goto char_link_cleanup;
      fn = add_inline_footnote(rndr, data+(i+2), k-2);
      i += k+1;
    }else{                             /* inline style link  */
      size_t span_end = i;
      while( span_end<size
       && !(data[span_end]==')' && (span_end==i || data[span_end-1]!='\\'))
      ){
        span_end++;
      }

1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
      }
    }else if( get_link_ref(rndr, link, title, id_data, id_size)<0 ){
      goto char_link_cleanup;
    }

    i = id_end+1;

  /* shortcut reference style link or free-standing footnote refernece */
  }else{
    if(!is_img && size>3 && data[1]=='^'){
      /* free-standing footnote reference */
      fn = get_footnote(rndr, data+2, txt_e-2);
      if( !fn ) {
        rndr->notes.misref.nUsed++;
        fn = &rndr->notes.misref;
      }
      release_work_buffer(rndr, content);
      content = 0; 
    }else if( get_link_ref(rndr, link, title, data+1, txt_e-1)<0 ){
      goto char_link_cleanup;
    }

    /* rewinding a closing square bracket */
    i = txt_e+1;
  }

  /* building content: img alt is escaped, link content is parsed */
  if( txt_e>1 && content ){
    if( is_img ) blob_append(content, data+1, txt_e-1);







|

<
<
<
<
<
<
<
<
<
|


<







1279
1280
1281
1282
1283
1284
1285
1286
1287









1288
1289
1290

1291
1292
1293
1294
1295
1296
1297
      }
    }else if( get_link_ref(rndr, link, title, id_data, id_size)<0 ){
      goto char_link_cleanup;
    }

    i = id_end+1;

  /* shortcut reference style link */
  }else{









    if( get_link_ref(rndr, link, title, data+1, txt_e-1)<0 ){
      goto char_link_cleanup;
    }

    /* rewinding a closing square bracket */
    i = txt_e+1;
  }

  /* building content: img alt is escaped, link content is parsed */
  if( txt_e>1 && content ){
    if( is_img ) blob_append(content, data+1, txt_e-1);

Changes to test/markdown-test3.md.

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58








59
60
61
62
63
64
65
   It references [its previous][^lost3] 
   and [the forthcoming][^lost1] siblings.

[^i am strayed]:
  This should be presented **verbatim** (without any [markup][^])
  in the end of the footnotes.
  
  Default skin renders label in red bold font and the main text as gray.
  Other styling may also apply.

Inline footnotes are supported.(^These may be usefull for adding
<s>small</s> comments.)

If [undefined label is used][^] then red "`misref`" is emited instead of
a numeric marker.[^ see it yourself ]
This can be overridden by the skin though.

The refenrence at the end of this sentence is the sole reason of
rendering of <s>`lost1` and</s> [lost2][^].

If several labeled footnote definitions have the same equal label then texts
from all these definitions are joined.[^duplicate]

Several references should be recognized as several distinct numbers.
(^There should be an interval between numbers.) [^many-refs]









## Footnotes

[branch]: /timeline?r=markdown-footnotes&nowiki

[^ 1]:  Footnotes is a Fossil' extention of
        Markdown. Your other tools may have limited support for these.







|

















>
>
>
>
>
>
>
>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
   It references [its previous][^lost3] 
   and [the forthcoming][^lost1] siblings.

[^i am strayed]:
  This should be presented **verbatim** (without any [markup][^])
  in the end of the footnotes.
  
  Default skin renders label in red font and the main text in gray.
  Other styling may also apply.

Inline footnotes are supported.(^These may be usefull for adding
<s>small</s> comments.)

If [undefined label is used][^] then red "`misref`" is emited instead of
a numeric marker.[^ see it yourself ]
This can be overridden by the skin though.

The refenrence at the end of this sentence is the sole reason of
rendering of <s>`lost1` and</s> [lost2][^].

If several labeled footnote definitions have the same equal label then texts
from all these definitions are joined.[^duplicate]

Several references should be recognized as several distinct numbers.
(^There should be an interval between numbers.) [^many-refs]

If markup is ambigous between a span-bounded footnote and
a "free-standing" footnote followed by another footnote
then interpret as the later case.
This facilitates the usage in the usual case
when several footnotes are refenrenced at the end
of a phrase.[^scipub][^many-refs](^All these four should
be parsed as "free-standing" footnotes)[^Coelurosauria]

## Footnotes

[branch]: /timeline?r=markdown-footnotes&nowiki

[^ 1]:  Footnotes is a Fossil' extention of
        Markdown. Your other tools may have limited support for these.
92
93
94
95
96
97
98



[^markup]:   E.g. *emphasis*, and [so on](/md_rules).
   BTW, this note may not have a backreference to the "stray".

[^undefined label is used]: For example due to a typo.

[^another stray]: Just to verify the correctness of ordering and styling.









>
>
100
101
102
103
104
105
106
107
108

[^markup]:   E.g. *emphasis*, and [so on](/md_rules).
   BTW, this note may not have a backreference to the "stray".

[^undefined label is used]: For example due to a typo.

[^another stray]: Just to verify the correctness of ordering and styling.

[^scipub]: Which is common in the scientific publications.