Fossil SCM
Bug-fix: Do not loose referenced footnotes when inline footnotes are also used.
Commit
a8f0f1e7ff044ef9aef087b1386013715f8790a1fb95984269d3cf50ae56f724
Parent
78b7846b8eff7c6…
1 file changed
+6
-6
+6
-6
| --- src/markdown.c | ||
| +++ src/markdown.c | ||
| @@ -171,10 +171,11 @@ | ||
| 171 | 171 | int iDepth; /* Depth of recursion */ |
| 172 | 172 | int nBlobCache; /* Number of entries in aBlobCache */ |
| 173 | 173 | struct Blob *aBlobCache[20]; /* Cache of Blobs available for reuse */ |
| 174 | 174 | |
| 175 | 175 | struct Blob notes; /* array of footnotes */ |
| 176 | + int nLabeled; /* number of footnotes found by the first pass */ | |
| 176 | 177 | int iNotesCount; /* count distinct indices found in the second pass */ |
| 177 | 178 | }; |
| 178 | 179 | |
| 179 | 180 | /* html_tag -- structure for quick HTML tag search (inspired from discount) */ |
| 180 | 181 | struct html_tag { |
| @@ -1040,11 +1041,11 @@ | ||
| 1040 | 1041 | ){ |
| 1041 | 1042 | struct footnote *fn = NULL; |
| 1042 | 1043 | struct Blob *id = new_work_buffer(rndr); |
| 1043 | 1044 | if( build_ref_id(id, data, size)<0 ) goto cleanup; |
| 1044 | 1045 | fn = bsearch(id, blob_buffer(&rndr->notes), |
| 1045 | - COUNT_FOOTNOTES(&rndr->notes), | |
| 1046 | + rndr->nLabeled, | |
| 1046 | 1047 | sizeof (struct footnote), |
| 1047 | 1048 | cmp_link_ref); |
| 1048 | 1049 | if( !fn ) goto cleanup; |
| 1049 | 1050 | |
| 1050 | 1051 | if( fn->index == 0 ){ /* the first reference to the footnote */ |
| @@ -2375,11 +2376,10 @@ | ||
| 2375 | 2376 | struct link_ref *lr; |
| 2376 | 2377 | struct footnote *fn; |
| 2377 | 2378 | size_t i, beg, end = 0; |
| 2378 | 2379 | struct render rndr; |
| 2379 | 2380 | Blob text = BLOB_INITIALIZER; /* input after the first pass */ |
| 2380 | - int nLabeled; /* number of footnotes found by the first pass */ | |
| 2381 | 2381 | |
| 2382 | 2382 | /* filling the render structure */ |
| 2383 | 2383 | if( !rndrer ) return; |
| 2384 | 2384 | rndr.make = *rndrer; |
| 2385 | 2385 | rndr.nBlobCache = 0; |
| @@ -2429,22 +2429,22 @@ | ||
| 2429 | 2429 | end += 1; |
| 2430 | 2430 | } |
| 2431 | 2431 | beg = end; |
| 2432 | 2432 | } |
| 2433 | 2433 | } |
| 2434 | - | |
| 2434 | + assert( rndr.iNotesCount==0 ); | |
| 2435 | 2435 | /* sorting the reference array */ |
| 2436 | 2436 | if( blob_size(&rndr.refs) ){ |
| 2437 | 2437 | qsort(blob_buffer(&rndr.refs), |
| 2438 | 2438 | blob_size(&rndr.refs)/sizeof(struct link_ref), |
| 2439 | 2439 | sizeof(struct link_ref), |
| 2440 | 2440 | cmp_link_ref_sort); |
| 2441 | 2441 | } |
| 2442 | - nLabeled = COUNT_FOOTNOTES(&rndr.notes); | |
| 2442 | + rndr.nLabeled = COUNT_FOOTNOTES(&rndr.notes); | |
| 2443 | 2443 | /* 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), | |
| 2446 | 2446 | cmp_link_ref_sort); |
| 2447 | 2447 | } |
| 2448 | 2448 | |
| 2449 | 2449 | /* second pass: actual rendering */ |
| 2450 | 2450 | if( rndr.make.prolog ) rndr.make.prolog(ob, rndr.make.opaque); |
| 2451 | 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 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 |