Fossil SCM

Bug-fix: Do not loose referenced footnotes when inline footnotes are also used.

george 2022-02-02 17:50 markdown-footnotes
Commit a8f0f1e7ff044ef9aef087b1386013715f8790a1fb95984269d3cf50ae56f724
1 file changed +6 -6
+6 -6
--- src/markdown.c
+++ src/markdown.c
@@ -171,10 +171,11 @@
171171
int iDepth; /* Depth of recursion */
172172
int nBlobCache; /* Number of entries in aBlobCache */
173173
struct Blob *aBlobCache[20]; /* Cache of Blobs available for reuse */
174174
175175
struct Blob notes; /* array of footnotes */
176
+ int nLabeled; /* number of footnotes found by the first pass */
176177
int iNotesCount; /* count distinct indices found in the second pass */
177178
};
178179
179180
/* html_tag -- structure for quick HTML tag search (inspired from discount) */
180181
struct html_tag {
@@ -1040,11 +1041,11 @@
10401041
){
10411042
struct footnote *fn = NULL;
10421043
struct Blob *id = new_work_buffer(rndr);
10431044
if( build_ref_id(id, data, size)<0 ) goto cleanup;
10441045
fn = bsearch(id, blob_buffer(&rndr->notes),
1045
- COUNT_FOOTNOTES(&rndr->notes),
1046
+ rndr->nLabeled,
10461047
sizeof (struct footnote),
10471048
cmp_link_ref);
10481049
if( !fn ) goto cleanup;
10491050
10501051
if( fn->index == 0 ){ /* the first reference to the footnote */
@@ -2375,11 +2376,10 @@
23752376
struct link_ref *lr;
23762377
struct footnote *fn;
23772378
size_t i, beg, end = 0;
23782379
struct render rndr;
23792380
Blob text = BLOB_INITIALIZER; /* input after the first pass */
2380
- int nLabeled; /* number of footnotes found by the first pass */
23812381
23822382
/* filling the render structure */
23832383
if( !rndrer ) return;
23842384
rndr.make = *rndrer;
23852385
rndr.nBlobCache = 0;
@@ -2429,22 +2429,22 @@
24292429
end += 1;
24302430
}
24312431
beg = end;
24322432
}
24332433
}
2434
-
2434
+ assert( rndr.iNotesCount==0 );
24352435
/* sorting the reference array */
24362436
if( blob_size(&rndr.refs) ){
24372437
qsort(blob_buffer(&rndr.refs),
24382438
blob_size(&rndr.refs)/sizeof(struct link_ref),
24392439
sizeof(struct link_ref),
24402440
cmp_link_ref_sort);
24412441
}
2442
- nLabeled = COUNT_FOOTNOTES(&rndr.notes);
2442
+ rndr.nLabeled = COUNT_FOOTNOTES(&rndr.notes);
24432443
/* sorting the footnotes array by id */
2444
- if( nLabeled ){
2445
- qsort(blob_buffer(&rndr.notes), nLabeled, sizeof(struct footnote),
2444
+ if( rndr.nLabeled ){
2445
+ qsort(blob_buffer(&rndr.notes), rndr.nLabeled, sizeof(struct footnote),
24462446
cmp_link_ref_sort);
24472447
}
24482448
24492449
/* second pass: actual rendering */
24502450
if( rndr.make.prolog ) rndr.make.prolog(ob, rndr.make.opaque);
24512451
--- src/markdown.c
+++ src/markdown.c
@@ -171,10 +171,11 @@
171 int iDepth; /* Depth of recursion */
172 int nBlobCache; /* Number of entries in aBlobCache */
173 struct Blob *aBlobCache[20]; /* Cache of Blobs available for reuse */
174
175 struct Blob notes; /* array of footnotes */
 
176 int iNotesCount; /* count distinct indices found in the second pass */
177 };
178
179 /* html_tag -- structure for quick HTML tag search (inspired from discount) */
180 struct html_tag {
@@ -1040,11 +1041,11 @@
1040 ){
1041 struct footnote *fn = NULL;
1042 struct Blob *id = new_work_buffer(rndr);
1043 if( build_ref_id(id, data, size)<0 ) goto cleanup;
1044 fn = bsearch(id, blob_buffer(&rndr->notes),
1045 COUNT_FOOTNOTES(&rndr->notes),
1046 sizeof (struct footnote),
1047 cmp_link_ref);
1048 if( !fn ) goto cleanup;
1049
1050 if( fn->index == 0 ){ /* the first reference to the footnote */
@@ -2375,11 +2376,10 @@
2375 struct link_ref *lr;
2376 struct footnote *fn;
2377 size_t i, beg, end = 0;
2378 struct render rndr;
2379 Blob text = BLOB_INITIALIZER; /* input after the first pass */
2380 int nLabeled; /* number of footnotes found by the first pass */
2381
2382 /* filling the render structure */
2383 if( !rndrer ) return;
2384 rndr.make = *rndrer;
2385 rndr.nBlobCache = 0;
@@ -2429,22 +2429,22 @@
2429 end += 1;
2430 }
2431 beg = end;
2432 }
2433 }
2434
2435 /* sorting the reference array */
2436 if( blob_size(&rndr.refs) ){
2437 qsort(blob_buffer(&rndr.refs),
2438 blob_size(&rndr.refs)/sizeof(struct link_ref),
2439 sizeof(struct link_ref),
2440 cmp_link_ref_sort);
2441 }
2442 nLabeled = COUNT_FOOTNOTES(&rndr.notes);
2443 /* sorting the footnotes array by id */
2444 if( nLabeled ){
2445 qsort(blob_buffer(&rndr.notes), nLabeled, sizeof(struct footnote),
2446 cmp_link_ref_sort);
2447 }
2448
2449 /* second pass: actual rendering */
2450 if( rndr.make.prolog ) rndr.make.prolog(ob, rndr.make.opaque);
2451
--- src/markdown.c
+++ src/markdown.c
@@ -171,10 +171,11 @@
171 int iDepth; /* Depth of recursion */
172 int nBlobCache; /* Number of entries in aBlobCache */
173 struct Blob *aBlobCache[20]; /* Cache of Blobs available for reuse */
174
175 struct Blob notes; /* array of footnotes */
176 int nLabeled; /* number of footnotes found by the first pass */
177 int iNotesCount; /* count distinct indices found in the second pass */
178 };
179
180 /* html_tag -- structure for quick HTML tag search (inspired from discount) */
181 struct html_tag {
@@ -1040,11 +1041,11 @@
1041 ){
1042 struct footnote *fn = NULL;
1043 struct Blob *id = new_work_buffer(rndr);
1044 if( build_ref_id(id, data, size)<0 ) goto cleanup;
1045 fn = bsearch(id, blob_buffer(&rndr->notes),
1046 rndr->nLabeled,
1047 sizeof (struct footnote),
1048 cmp_link_ref);
1049 if( !fn ) goto cleanup;
1050
1051 if( fn->index == 0 ){ /* the first reference to the footnote */
@@ -2375,11 +2376,10 @@
2376 struct link_ref *lr;
2377 struct footnote *fn;
2378 size_t i, beg, end = 0;
2379 struct render rndr;
2380 Blob text = BLOB_INITIALIZER; /* input after the first pass */
 
2381
2382 /* filling the render structure */
2383 if( !rndrer ) return;
2384 rndr.make = *rndrer;
2385 rndr.nBlobCache = 0;
@@ -2429,22 +2429,22 @@
2429 end += 1;
2430 }
2431 beg = end;
2432 }
2433 }
2434 assert( rndr.iNotesCount==0 );
2435 /* sorting the reference array */
2436 if( blob_size(&rndr.refs) ){
2437 qsort(blob_buffer(&rndr.refs),
2438 blob_size(&rndr.refs)/sizeof(struct link_ref),
2439 sizeof(struct link_ref),
2440 cmp_link_ref_sort);
2441 }
2442 rndr.nLabeled = COUNT_FOOTNOTES(&rndr.notes);
2443 /* sorting the footnotes array by id */
2444 if( rndr.nLabeled ){
2445 qsort(blob_buffer(&rndr.notes), rndr.nLabeled, sizeof(struct footnote),
2446 cmp_link_ref_sort);
2447 }
2448
2449 /* second pass: actual rendering */
2450 if( rndr.make.prolog ) rndr.make.prolog(ob, rndr.make.opaque);
2451

Keyboard Shortcuts

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