Fossil SCM
Minor code refactoring: rename a temporary variable and utilize <code>matching_bracket_offset()</code> one more time. No changes in functionality.
Commit
5b845a0790d102965a842d7d33a072bc313a6fe99f48c6e76cbdabb036138a9c
Parent
23c3e0b2a7fd896…
1 file changed
+12
-21
+12
-21
| --- src/markdown.c | ||
| +++ src/markdown.c | ||
| @@ -1176,31 +1176,22 @@ | ||
| 1176 | 1176 | size_t i = 1, txt_e; |
| 1177 | 1177 | struct Blob *content = 0; |
| 1178 | 1178 | struct Blob *link = 0; |
| 1179 | 1179 | struct Blob *title = 0; |
| 1180 | 1180 | const struct footnote *fn = 0; |
| 1181 | - int level, ret; | |
| 1181 | + int ret; | |
| 1182 | 1182 | /* ? FIXME: assert( size>0 ); */ |
| 1183 | 1183 | |
| 1184 | 1184 | /* checking whether the correct renderer exists */ |
| 1185 | 1185 | if( (is_img && !rndr->make.image) || (!is_img && !rndr->make.link) ){ |
| 1186 | 1186 | return 0; |
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | /* looking for the matching closing bracket */ |
| 1190 | - for(level=1; i<size; i++){ | |
| 1191 | - if( data[i]=='\n' ) /* do nothing */; | |
| 1192 | - else if( data[i-1]=='\\' ) continue; | |
| 1193 | - else if( data[i]=='[' ) level += 1; | |
| 1194 | - else if( data[i]==']' ){ | |
| 1195 | - level--; | |
| 1196 | - if( level<=0 ) break; | |
| 1197 | - } | |
| 1198 | - } | |
| 1199 | - if( i>=size ) return 0; | |
| 1200 | - txt_e = i; | |
| 1201 | - i++; | |
| 1190 | + txt_e = matching_bracket_offset(data, data+size); | |
| 1191 | + if( !txt_e ) return 0; | |
| 1192 | + i = txt_e + 1; | |
| 1202 | 1193 | |
| 1203 | 1194 | /* skip any amount of whitespace or newline */ |
| 1204 | 1195 | /* (this is much more laxist than original markdown syntax) */ |
| 1205 | 1196 | while( i<size && (data[i]==' ' || data[i]=='\t' || data[i]=='\n') ){ i++; } |
| 1206 | 1197 | |
| @@ -2584,26 +2575,26 @@ | ||
| 2584 | 2575 | k += blob_size(&fn[j].text) + 10; |
| 2585 | 2576 | j++; |
| 2586 | 2577 | nDups++; |
| 2587 | 2578 | } |
| 2588 | 2579 | if( i+1<j ){ |
| 2589 | - Blob tmp = empty_blob; | |
| 2590 | - blob_reserve(&tmp, k); | |
| 2580 | + Blob list = empty_blob; | |
| 2581 | + blob_reserve(&list, k); | |
| 2591 | 2582 | /* must match _joined_footnote_indicator in html_footnote_item() */ |
| 2592 | - blob_append_string(&tmp, "<ul class='fn-joined'>\n"); | |
| 2583 | + blob_append_string(&list, "<ul class='fn-joined'>\n"); | |
| 2593 | 2584 | for(k=i; k<j; k++){ |
| 2594 | 2585 | struct footnote *y = fn + k; |
| 2595 | - blob_append_string(&tmp, "<li>"); | |
| 2596 | - blob_append(&tmp, blob_buffer(&y->text), blob_size(&y->text)); | |
| 2597 | - blob_append_string(&tmp, "</li>\n"); | |
| 2586 | + blob_append_string(&list, "<li>"); | |
| 2587 | + blob_append(&list, blob_buffer(&y->text), blob_size(&y->text)); | |
| 2588 | + blob_append_string(&list, "</li>\n"); | |
| 2598 | 2589 | |
| 2599 | 2590 | /* free memory buffer */ |
| 2600 | 2591 | blob_reset(&y->text); |
| 2601 | 2592 | if( k!=i ) blob_reset(&y->id); |
| 2602 | 2593 | } |
| 2603 | - blob_append_string(&tmp, "</ul>\n"); | |
| 2604 | - x->text = tmp; | |
| 2594 | + blob_append_string(&list, "</ul>\n"); | |
| 2595 | + x->text = list; | |
| 2605 | 2596 | } |
| 2606 | 2597 | i = j; |
| 2607 | 2598 | } |
| 2608 | 2599 | if( nDups ){ /* clean rndr.notes.all from invalidated footnotes */ |
| 2609 | 2600 | const int n = rndr.notes.nLbled - nDups; |
| 2610 | 2601 |
| --- src/markdown.c | |
| +++ src/markdown.c | |
| @@ -1176,31 +1176,22 @@ | |
| 1176 | size_t i = 1, txt_e; |
| 1177 | struct Blob *content = 0; |
| 1178 | struct Blob *link = 0; |
| 1179 | struct Blob *title = 0; |
| 1180 | const struct footnote *fn = 0; |
| 1181 | int level, ret; |
| 1182 | /* ? FIXME: assert( size>0 ); */ |
| 1183 | |
| 1184 | /* checking whether the correct renderer exists */ |
| 1185 | if( (is_img && !rndr->make.image) || (!is_img && !rndr->make.link) ){ |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | /* looking for the matching closing bracket */ |
| 1190 | for(level=1; i<size; i++){ |
| 1191 | if( data[i]=='\n' ) /* do nothing */; |
| 1192 | else if( data[i-1]=='\\' ) continue; |
| 1193 | else if( data[i]=='[' ) level += 1; |
| 1194 | else if( data[i]==']' ){ |
| 1195 | level--; |
| 1196 | if( level<=0 ) break; |
| 1197 | } |
| 1198 | } |
| 1199 | if( i>=size ) return 0; |
| 1200 | txt_e = i; |
| 1201 | i++; |
| 1202 | |
| 1203 | /* skip any amount of whitespace or newline */ |
| 1204 | /* (this is much more laxist than original markdown syntax) */ |
| 1205 | while( i<size && (data[i]==' ' || data[i]=='\t' || data[i]=='\n') ){ i++; } |
| 1206 | |
| @@ -2584,26 +2575,26 @@ | |
| 2584 | k += blob_size(&fn[j].text) + 10; |
| 2585 | j++; |
| 2586 | nDups++; |
| 2587 | } |
| 2588 | if( i+1<j ){ |
| 2589 | Blob tmp = empty_blob; |
| 2590 | blob_reserve(&tmp, k); |
| 2591 | /* must match _joined_footnote_indicator in html_footnote_item() */ |
| 2592 | blob_append_string(&tmp, "<ul class='fn-joined'>\n"); |
| 2593 | for(k=i; k<j; k++){ |
| 2594 | struct footnote *y = fn + k; |
| 2595 | blob_append_string(&tmp, "<li>"); |
| 2596 | blob_append(&tmp, blob_buffer(&y->text), blob_size(&y->text)); |
| 2597 | blob_append_string(&tmp, "</li>\n"); |
| 2598 | |
| 2599 | /* free memory buffer */ |
| 2600 | blob_reset(&y->text); |
| 2601 | if( k!=i ) blob_reset(&y->id); |
| 2602 | } |
| 2603 | blob_append_string(&tmp, "</ul>\n"); |
| 2604 | x->text = tmp; |
| 2605 | } |
| 2606 | i = j; |
| 2607 | } |
| 2608 | if( nDups ){ /* clean rndr.notes.all from invalidated footnotes */ |
| 2609 | const int n = rndr.notes.nLbled - nDups; |
| 2610 |
| --- src/markdown.c | |
| +++ src/markdown.c | |
| @@ -1176,31 +1176,22 @@ | |
| 1176 | size_t i = 1, txt_e; |
| 1177 | struct Blob *content = 0; |
| 1178 | struct Blob *link = 0; |
| 1179 | struct Blob *title = 0; |
| 1180 | const struct footnote *fn = 0; |
| 1181 | int ret; |
| 1182 | /* ? FIXME: assert( size>0 ); */ |
| 1183 | |
| 1184 | /* checking whether the correct renderer exists */ |
| 1185 | if( (is_img && !rndr->make.image) || (!is_img && !rndr->make.link) ){ |
| 1186 | return 0; |
| 1187 | } |
| 1188 | |
| 1189 | /* looking for the matching closing bracket */ |
| 1190 | txt_e = matching_bracket_offset(data, data+size); |
| 1191 | if( !txt_e ) return 0; |
| 1192 | i = txt_e + 1; |
| 1193 | |
| 1194 | /* skip any amount of whitespace or newline */ |
| 1195 | /* (this is much more laxist than original markdown syntax) */ |
| 1196 | while( i<size && (data[i]==' ' || data[i]=='\t' || data[i]=='\n') ){ i++; } |
| 1197 | |
| @@ -2584,26 +2575,26 @@ | |
| 2575 | k += blob_size(&fn[j].text) + 10; |
| 2576 | j++; |
| 2577 | nDups++; |
| 2578 | } |
| 2579 | if( i+1<j ){ |
| 2580 | Blob list = empty_blob; |
| 2581 | blob_reserve(&list, k); |
| 2582 | /* must match _joined_footnote_indicator in html_footnote_item() */ |
| 2583 | blob_append_string(&list, "<ul class='fn-joined'>\n"); |
| 2584 | for(k=i; k<j; k++){ |
| 2585 | struct footnote *y = fn + k; |
| 2586 | blob_append_string(&list, "<li>"); |
| 2587 | blob_append(&list, blob_buffer(&y->text), blob_size(&y->text)); |
| 2588 | blob_append_string(&list, "</li>\n"); |
| 2589 | |
| 2590 | /* free memory buffer */ |
| 2591 | blob_reset(&y->text); |
| 2592 | if( k!=i ) blob_reset(&y->id); |
| 2593 | } |
| 2594 | blob_append_string(&list, "</ul>\n"); |
| 2595 | x->text = list; |
| 2596 | } |
| 2597 | i = j; |
| 2598 | } |
| 2599 | if( nDups ){ /* clean rndr.notes.all from invalidated footnotes */ |
| 2600 | const int n = rndr.notes.nLbled - nDups; |
| 2601 |