Fossil

Check-in [cae7a5d1ca]
Login

Check-in [cae7a5d1ca]

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

Overview
Comment:Switch to <tt>(^...)</tt> for inline footnotes. Implement span-specific footnotes. Add [/doc/markdown-footnotes/src/markdown.md#ftnts|documentation].
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | markdown-footnotes
Files: files | file ages | folders
SHA3-256: cae7a5d1cab9b6101ae7230468f7281856f933abc530fdff50643752f6471299
User & Date: george 2022-02-04 00:37:06.450
Context
2022-02-04
16:54
Fix documentation so that an example of a referenced footnote definition inside of the fenced code block is not recognized as a real footnote defenition. This demonstrates a subtle gotcha and a possible work-arround of it. ... (check-in: 7229d0f588 user: george tags: markdown-footnotes)
00:37
Switch to <tt>(^...)</tt> for inline footnotes. Implement span-specific footnotes. Add [/doc/markdown-footnotes/src/markdown.md#ftnts|documentation]. ... (check-in: cae7a5d1ca user: george tags: markdown-footnotes)
2022-02-02
17:50
Bug-fix: Do not loose referenced footnotes when inline footnotes are also used. ... (check-in: a8f0f1e7ff user: george tags: markdown-footnotes)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/backlink.c.
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
    /* dbl_emphas */ (int(*)(Blob*,Blob*,char,void*))mkdn_noop1,
    /* emphasis   */ (int(*)(Blob*,Blob*,char,void*))mkdn_noop1,
    /* image      */ (int(*)(Blob*,Blob*,Blob*,Blob*,void*))mkdn_noop1,
    /* linebreak  */ (int(*)(Blob*,void*))mkdn_noop1,
    /* link       */ backlink_md_link,
    /* r_html_tag */ (int(*)(Blob*,Blob*,void*))mkdn_noop1,
    /* tri_emphas */ (int(*)(Blob*,Blob*,char,void*))mkdn_noop1,
    /* footnoteref*/ (int(*)(Blob*,int,int,void*))mkdn_noop1,

    0,  /* entity */
    0,  /* normal_text */
    "*_", /* emphasis characters */
    0   /* client data */
  };
  Blob out, in;







|







277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
    /* dbl_emphas */ (int(*)(Blob*,Blob*,char,void*))mkdn_noop1,
    /* emphasis   */ (int(*)(Blob*,Blob*,char,void*))mkdn_noop1,
    /* image      */ (int(*)(Blob*,Blob*,Blob*,Blob*,void*))mkdn_noop1,
    /* linebreak  */ (int(*)(Blob*,void*))mkdn_noop1,
    /* link       */ backlink_md_link,
    /* r_html_tag */ (int(*)(Blob*,Blob*,void*))mkdn_noop1,
    /* tri_emphas */ (int(*)(Blob*,Blob*,char,void*))mkdn_noop1,
    /* footnoteref*/ (int(*)(Blob*,const Blob*,int,int,void*))mkdn_noop1,

    0,  /* entity */
    0,  /* normal_text */
    "*_", /* emphasis characters */
    0   /* client data */
  };
  Blob out, in;
Changes to src/default.css.
1678
1679
1680
1681
1682
1683
1684






1685
1686
1687
1688
1689
1690
1691
  font-weight: bold;
}
div.markdown > ol.footnotes > li > .footnote-backrefs > a:target {
  background: gold;
}
div.markdown a.noteref:target > sup {
  background: gold;






}

/* Objects in the "desktoponly" class are invisible on mobile */
@media screen and (max-width: 600px) {
  .desktoponly {
    display: none;
  }







>
>
>
>
>
>







1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
  font-weight: bold;
}
div.markdown > ol.footnotes > li > .footnote-backrefs > a:target {
  background: gold;
}
div.markdown a.noteref:target > sup {
  background: gold;
}
div.markdown span.notescope:target {
  border-bottom: 2px solid gold;
}
div.markdown span.notescope:target > a.noteref > sup {
  background: gold;
}

/* Objects in the "desktoponly" class are invisible on mobile */
@media screen and (max-width: 600px) {
  .desktoponly {
    display: none;
  }
Changes to src/markdown.c.
80
81
82
83
84
85
86
87

88
89
90
91
92
93
94
            struct Blob *alt, void *opaque);
  int (*linebreak)(struct Blob *ob, void *opaque);
  int (*link)(struct Blob *ob, struct Blob *link, struct Blob *title,
          struct Blob *content, void *opaque);
  int (*raw_html_tag)(struct Blob *ob, struct Blob *tag, void *opaque);
  int (*triple_emphasis)(struct Blob *ob, struct Blob *text,
            char c, void *opaque);
  int (*footnote_ref)(struct Blob *ob, int index, int locus, void *opaque);


  /* low level callbacks - NULL copies input directly into the output */
  void (*entity)(struct Blob *ob, struct Blob *entity, void *opaque);
  void (*normal_text)(struct Blob *ob, struct Blob *text, void *opaque);

  /* renderer data */
  const char *emph_chars; /* chars that trigger emphasis rendering */







|
>







80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
            struct Blob *alt, void *opaque);
  int (*linebreak)(struct Blob *ob, void *opaque);
  int (*link)(struct Blob *ob, struct Blob *link, struct Blob *title,
          struct Blob *content, void *opaque);
  int (*raw_html_tag)(struct Blob *ob, struct Blob *tag, void *opaque);
  int (*triple_emphasis)(struct Blob *ob, struct Blob *text,
            char c, void *opaque);
  int (*footnote_ref)(struct Blob *ob, const struct Blob *span,
                      int index, int locus, void *opaque);

  /* low level callbacks - NULL copies input directly into the output */
  void (*entity)(struct Blob *ob, struct Blob *entity, void *opaque);
  void (*normal_text)(struct Blob *ob, struct Blob *text, void *opaque);

  /* renderer data */
  const char *emph_chars; /* chars that trigger emphasis rendering */
1055
1056
1057
1058
1059
1060
1061




























































1062
1063
1064
1065
1066
1067
1068
  fn->nUsed++;
  assert( fn->index > 0 );
  assert( fn->nUsed > 0 );
cleanup:
  release_work_buffer( rndr, id );
  return fn;
}





























































/* char_link -- '[': parsing a link or an image */
static size_t char_link(
  struct Blob *ob,
  struct render *rndr,
  char *data,
  size_t offset,







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
  fn->nUsed++;
  assert( fn->index > 0 );
  assert( fn->nUsed > 0 );
cleanup:
  release_work_buffer( rndr, id );
  return fn;
}
/* Adds unlabeled footnote to the rndr.
 * If text is blank then returns 0,
 * otherwise returns the address of the added footnote. */
static inline const struct footnote* add_inline_footnote(
  struct render *rndr,
  const char *text,
  size_t size
){
  struct footnote fn = { empty_blob, empty_blob, 0, 0 };
  while(size && (*text==' ' || *text=='\t')){ text++; size--; }
  if(!size) return 0;
  fn.index = ++(rndr->iNotesCount);
  fn.nUsed = 1;
  assert( fn.index > 0 );
  blob_append(&fn.text, text, size);
  blob_append(&rndr->notes, (char *)&fn, sizeof fn);
  return (struct footnote*)( blob_buffer(&rndr->notes)
                            +( blob_size(&rndr->notes)-sizeof fn ));
}

/* Return the offset of the matching closing bracket or 0 if not found.
 * begin[0] must be either '[' or '('          */
static inline size_t matching_bracket_offset(
  const char* begin,
  const char* end
){
  const char *i;
  int level;
  const char bra = *begin;
  const char ket = bra=='[' ? ']' : ')';
  assert( bra=='[' || bra=='(' );      /* FIXME: only when debugging */
  for(i=begin+1,level=1; i!=end; i++){
    if( *i=='\n' )        /* do nothing */;
    else if( i[-1]=='\\' ) continue;   /* ? FIXME: what if \\( ? */
    else if( *i==bra )     level++;
    else if( *i==ket ){
      if( --level<=0 ) return i-begin;
    }
  }
  return 0;
}

/* char_footnote -- '(': parsing a standalone inline footnote */
static size_t char_footnote(
  struct Blob *ob,
  struct render *rndr,
  char *data,
  size_t offset,
  size_t size
){
  size_t end;
  const struct footnote* fn;

  if( size<4 || data[1]!='^' || !rndr->make.footnote_ref ) return 0;
  end = matching_bracket_offset(data, data+size);
  if( !end ) return 0;
  fn = add_inline_footnote(rndr, data+2, end-2);
  if(fn) rndr->make.footnote_ref(ob,0,fn->index,1,rndr->make.opaque);
  return end+1;
}

/* char_link -- '[': parsing a link or an image */
static size_t char_link(
  struct Blob *ob,
  struct render *rndr,
  char *data,
  size_t offset,
1102
1103
1104
1105
1106
1107
1108
1109
1110









1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125

1126
1127
1128
1129

1130
1131
1132
1133

1134
1135
1136
1137
1138
1139
1140
1141
1142



1143
1144




1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167


1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190

1191
1192
1193
1194
1195
1196
1197

  /* 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 */
  if( i<size && data[i]=='(' ){









    size_t span_end = i;
    while( span_end<size
     && !(data[span_end]==')' && (span_end==i || data[span_end-1]!='\\'))
    ){
      span_end++;
    }

    if( span_end>=size
     || get_link_inline(link, title, data+i+1, span_end-(i+1))<0
    ){
      goto char_link_cleanup;
    }

    i = span_end+1;


  /* reference style link */
  }else if( i<size && data[i]=='[' ){
    char *id_data;
    size_t id_size, id_end = i;


    while( id_end<size && data[id_end]!=']' ){ id_end++; }

    if( id_end>=size ) goto char_link_cleanup;


    if( i+1==id_end ){
      /* implicit id - use the contents */
      id_data = data+1;
      id_size = txt_e-1;
    }else{
      /* explicit id - between brackets */
      id_data = data+i+1;
      id_size = id_end-(i+1);



    }





    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( offset && data[-1]=='^' ){

      /* free-standing inline note */
      struct footnote note = {empty_blob,empty_blob,0,0};
      note.index = ++(rndr->iNotesCount);
      note.nUsed = 1;
      blob_append(&note.text,data+1,txt_e-1);
      blob_append(&rndr->notes, (char *)&note, sizeof note);
      fn = (struct footnote*)(blob_buffer(&rndr->notes)
              + blob_size(&rndr->notes) - sizeof(note));
    }else if(!is_img && size>2 && data[1]=='^'){

      /* free-standing reference */
      fn = get_footnote(rndr, data+1, txt_e-1);
      if( !fn ) goto char_link_cleanup;


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

    /* rewinding the whitespace */
    i = txt_e+1;
  }

  /* building content: img alt is escaped, link content is parsed */
  if( txt_e>1 ){
    if( is_img ) blob_append(content, data+1, txt_e-1);
    else if(!fn) parse_inline(content, rndr, data+1, txt_e-1);
  }

  /* calling the relevant rendering function */
  if( is_img ){
    if( blob_size(ob)>0 && blob_buffer(ob)[blob_size(ob)-1]=='!' ) ob->nUsed--;
    ret = rndr->make.image(ob, link, title, content, rndr->make.opaque);
  }else if(fn){
    if( blob_size(ob)>0 && blob_buffer(ob)[blob_size(ob)-1]=='^' ) ob->nUsed--;
    /* ? FIXME: the above line looks like a hack */
    if(rndr->make.footnote_ref){
      ret = rndr->make.footnote_ref(ob,fn->index,fn->nUsed,rndr->make.opaque);

    }
  }else{
    ret = rndr->make.link(ob, link, title, content, rndr->make.opaque);
  }

  /* cleanup */
char_link_cleanup:







|

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

|
|
|
|
|

|
|
>
|



>




>

|







>
>
>
|
|
>
>
>
>
|





|

<
<
<
<
<
<
<
<
<
<
|
<
|
|

>
>




|




|

|







<
<

|
>







1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
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
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257


1258
1259
1260
1261
1262
1263
1264
1265
1266
1267

  /* 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++;
      }

      if( span_end>=size
       || get_link_inline(link, title, data+i+1, span_end-(i+1))<0
      ){
        goto char_link_cleanup;
      }

      i = span_end+1;
    }

  /* reference style link or span-bounded footnote reference */
  }else if( i<size && data[i]=='[' ){
    char *id_data;
    size_t id_size, id_end = i;
    int bFootnote;

    while( id_end<size && data[id_end]!=']' ){ id_end++; }

    if( id_end>=size ) goto char_link_cleanup;
    bFootnote = data[i+1]=='^';

    if( i+1==id_end || (bFootnote && i+2==id_end) ){
      /* implicit id - use the contents */
      id_data = data+1;
      id_size = txt_e-1;
    }else{
      /* explicit id - between brackets */
      id_data = data+i+1;
      id_size = id_end-(i+1);
      if( bFootnote ){
        id_data++;
        id_size--;
      }
    }

    if( bFootnote ){
      fn = get_footnote(rndr, id_data, id_size);
      if( !fn ) goto char_link_cleanup;
    }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 ) goto char_link_cleanup;
      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);
    else parse_inline(content, rndr, data+1, txt_e-1);
  }

  /* calling the relevant rendering function */
  if( is_img ){
    if( blob_size(ob)>0 && blob_buffer(ob)[blob_size(ob)-1]=='!' ) ob->nUsed--;
    ret = rndr->make.image(ob, link, title, content, rndr->make.opaque);
  }else if(fn){


    if(rndr->make.footnote_ref){
      ret = rndr->make.footnote_ref(ob, content, fn->index, fn->nUsed,
                                    rndr->make.opaque);
    }
  }else{
    ret = rndr->make.link(ob, link, title, content, rndr->make.opaque);
  }

  /* cleanup */
char_link_cleanup:
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
  if( beg+5>=end ) return 0;
  i = beg;

  /* footnote definition must start at the begining of a line */
  if( data[i]!='[' ) return 0;
  i++;
  if( data[i]!='^' ) return 0;
  id_offset = i++;

  /* id part: anything but a newline between brackets */
  while( i<end && data[i]!=']' && data[i]!='\n' && data[i]!='\r' ){ i++; }
  if( i>=end || data[i]!=']' ) return 0;
  id_end = i++;

  /* spacer: colon (space | tab)* */







|







2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
  if( beg+5>=end ) return 0;
  i = beg;

  /* footnote definition must start at the begining of a line */
  if( data[i]!='[' ) return 0;
  i++;
  if( data[i]!='^' ) return 0;
  id_offset = ++i;

  /* id part: anything but a newline between brackets */
  while( i<end && data[i]!=']' && data[i]!='\n' && data[i]!='\r' ){ i++; }
  if( i>=end || data[i]!=']' ) return 0;
  id_end = i++;

  /* spacer: colon (space | tab)* */
2396
2397
2398
2399
2400
2401
2402

2403
2404
2405
2406
2407
2408
2409
    for(i=0; rndr.make.emph_chars[i]; i++){
      rndr.active_char[(unsigned char)rndr.make.emph_chars[i]] = char_emphasis;
    }
  }
  if( rndr.make.codespan ) rndr.active_char['`'] = char_codespan;
  if( rndr.make.linebreak ) rndr.active_char['\n'] = char_linebreak;
  if( rndr.make.image || rndr.make.link ) rndr.active_char['['] = char_link;

  rndr.active_char['<'] = char_langle_tag;
  rndr.active_char['\\'] = char_escape;
  rndr.active_char['&'] = char_entity;

  /* first pass: iterate over lines looking for references,
   * copying everything else into "text" */
  beg = 0;







>







2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
    for(i=0; rndr.make.emph_chars[i]; i++){
      rndr.active_char[(unsigned char)rndr.make.emph_chars[i]] = char_emphasis;
    }
  }
  if( rndr.make.codespan ) rndr.active_char['`'] = char_codespan;
  if( rndr.make.linebreak ) rndr.active_char['\n'] = char_linebreak;
  if( rndr.make.image || rndr.make.link ) rndr.active_char['['] = char_link;
  if( rndr.make.footnote_ref ) rndr.active_char['('] = char_footnote;
  rndr.active_char['<'] = char_langle_tag;
  rndr.active_char['\\'] = char_escape;
  rndr.active_char['&'] = char_entity;

  /* first pass: iterate over lines looking for references,
   * copying everything else into "text" */
  beg = 0;
Changes to src/markdown.md.
148
149
150
151
152
153
154

































155
156
157
158
159
160
161
> Formatted using [Pikchr](https://pikchr.org/home), resulting in:

>
~~~ pikchr
oval "Start" fit; arrow; box "Hello, World!" fit; arrow; oval "Done" fit
~~~


































## Miscellaneous ##

> *   In-line images are made using **\!\[alt-text\]\(image-URL\)**.
> *   Use HTML for advanced formatting such as forms.
> *   **\<!--** HTML-style comments **-->** are supported.
> *   Escape special characters (ex: **\[** **\(** **\|** **\***)
>     using backslash (ex: **\\\[** **\\\(** **\\\|** **\\\***).







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
> Formatted using [Pikchr](https://pikchr.org/home), resulting in:

>
~~~ pikchr
oval "Start" fit; arrow; box "Hello, World!" fit; arrow; oval "Done" fit
~~~

<a id="ftnts"></a>
## Footnotes ##

> Footnotes (or "endnotes") is a Fossil's extention of classical Markdown.
> Fossil's syntax for footnotes is similar to links and
> is distinguished by the use of character **^**
> that *immediately* follows an opening bracket.

> 1. **\(^** footnote's text **)**
> 2. **\[** fragment of text **]\(^** a comment about that fragment **\)**
> 3. **\[^**&nbsp;label&nbsp;**\]**
> 4. **\[** fragment of text **\]\[^**&nbsp;label&nbsp;**\]**
> 5. **\[** fragment of text **\]\[^\]**

> With formats 1 and 2 ("inline footnotes") text of a footnote is provided
> in the place where the corresponding numeric mark will be rendered.
> With formats 3, 4, and 5 ("reference footnotes") text of a footnote
> is supplied elsewhere in the document, as shown below.
> Formats 2, 4 and 5 ("span-specific footnotes") mark a specific fragment
> that is being commented in the footnote.
> Format 5 reuses a fragment of text as a label.
> Labels are case-insensitive.

>
```
[^label]: Footnote definition must start on the first column.
      The second line (if any) must be indented by two or more spaces.
      Definition continues until indentation drops below that of the 2nd line.
```
> Charachter **^** is not part of a label, it is part of the syntax.
> Both a footnote's text and a fragment to which a footnote applies
> are subject to further interpretation as Markdown sources.

## Miscellaneous ##

> *   In-line images are made using **\!\[alt-text\]\(image-URL\)**.
> *   Use HTML for advanced formatting such as forms.
> *   **\<!--** HTML-style comments **-->** are supported.
> *   Escape special characters (ex: **\[** **\(** **\|** **\***)
>     using backslash (ex: **\\\[** **\\\(** **\\\|** **\\\***).
Changes to src/markdown_html.c.
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339




340




341
342

343
344
345
346
347
348
349
){
  BLOB_APPEND_LITERAL(ob, "  <tr>\n");
  BLOB_APPEND_BLOB(ob, cells);
  BLOB_APPEND_LITERAL(ob, "  </tr>\n");
}

static int html_footnote_ref(
  struct Blob *ob, int index, int locus, void *opaque
){
  const struct MarkdownToHtml *ctx = (struct MarkdownToHtml*)opaque;
  const bitfield64_t l = to_base26(locus-1,0);
  char pos[32];

  /* expect BUGs if the following yields compiler warnings */
  memset(pos,0,32);
  sprintf(pos, "%s%i-%s", ctx->unique.c, index, l.c);





  BLOB_APPEND_LITERAL(ob,"<a class='noteref' href='#footnote-");




  blob_appendf(ob,"%s' id='noteref-%s'><sup>%i</sup></a>",
                   pos,            pos,   index);

  return 1;
}

/* Render a single item of the footnotes list.
 * Each backref gets a unique id to enable dynamic styling. */
static void html_footnote_item(
  struct Blob *ob, const struct Blob *text, int index, int nUsed, void *opaque







|








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







323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
){
  BLOB_APPEND_LITERAL(ob, "  <tr>\n");
  BLOB_APPEND_BLOB(ob, cells);
  BLOB_APPEND_LITERAL(ob, "  </tr>\n");
}

static int html_footnote_ref(
  struct Blob *ob, const struct Blob *span, int index, int locus, void *opaque
){
  const struct MarkdownToHtml *ctx = (struct MarkdownToHtml*)opaque;
  const bitfield64_t l = to_base26(locus-1,0);
  char pos[32];

  /* expect BUGs if the following yields compiler warnings */
  memset(pos,0,32);
  sprintf(pos, "%s%i-%s", ctx->unique.c, index, l.c);
  if(span && blob_size(span)) {
    BLOB_APPEND_LITERAL(ob,"<span class='notescope' id='noteref-");
    blob_appendf(ob,"%s'>",pos);
    BLOB_APPEND_BLOB(ob, span);
    blob_trim(ob);
    BLOB_APPEND_LITERAL(ob,"<a class='noteref' href='#footnote-");
    blob_appendf(ob,"%s'><sup>%i</sup></a></span>", pos, index);
  }else{
    blob_trim(ob);
    BLOB_APPEND_LITERAL(ob,"<a class='noteref' href='#footnote-");
    blob_appendf(ob,"%s' id='noteref-%s'><sup>%i</sup></a>",
                    pos,            pos,   index);
  }
  return 1;
}

/* Render a single item of the footnotes list.
 * Each backref gets a unique id to enable dynamic styling. */
static void html_footnote_item(
  struct Blob *ob, const struct Blob *text, int index, int nUsed, void *opaque