Fossil SCM

Minor code refactoring: rename a temporary variable and utilize <code>matching_bracket_offset()</code> one more time. No changes in functionality.

george 2022-02-14 23:32 markdown-footnotes
Commit 5b845a0790d102965a842d7d33a072bc313a6fe99f48c6e76cbdabb036138a9c
1 file changed +12 -21
+12 -21
--- src/markdown.c
+++ src/markdown.c
@@ -1176,31 +1176,22 @@
11761176
size_t i = 1, txt_e;
11771177
struct Blob *content = 0;
11781178
struct Blob *link = 0;
11791179
struct Blob *title = 0;
11801180
const struct footnote *fn = 0;
1181
- int level, ret;
1181
+ int ret;
11821182
/* ? FIXME: assert( size>0 ); */
11831183
11841184
/* checking whether the correct renderer exists */
11851185
if( (is_img && !rndr->make.image) || (!is_img && !rndr->make.link) ){
11861186
return 0;
11871187
}
11881188
11891189
/* 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;
12021193
12031194
/* skip any amount of whitespace or newline */
12041195
/* (this is much more laxist than original markdown syntax) */
12051196
while( i<size && (data[i]==' ' || data[i]=='\t' || data[i]=='\n') ){ i++; }
12061197
@@ -2584,26 +2575,26 @@
25842575
k += blob_size(&fn[j].text) + 10;
25852576
j++;
25862577
nDups++;
25872578
}
25882579
if( i+1<j ){
2589
- Blob tmp = empty_blob;
2590
- blob_reserve(&tmp, k);
2580
+ Blob list = empty_blob;
2581
+ blob_reserve(&list, k);
25912582
/* 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");
25932584
for(k=i; k<j; k++){
25942585
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");
25982589
25992590
/* free memory buffer */
26002591
blob_reset(&y->text);
26012592
if( k!=i ) blob_reset(&y->id);
26022593
}
2603
- blob_append_string(&tmp, "</ul>\n");
2604
- x->text = tmp;
2594
+ blob_append_string(&list, "</ul>\n");
2595
+ x->text = list;
26052596
}
26062597
i = j;
26072598
}
26082599
if( nDups ){ /* clean rndr.notes.all from invalidated footnotes */
26092600
const int n = rndr.notes.nLbled - nDups;
26102601
--- 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

Keyboard Shortcuts

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