Fossil SCM

Clean-up and rephrase some comments.

george 2022-02-17 00:17 markdown-footnotes
Commit a62c876896ae11002ba464a71fc92ef94a191be617042923dd0dd4db5dd461d3
1 file changed +13 -9
+13 -9
--- src/markdown.c
+++ src/markdown.c
@@ -213,11 +213,11 @@
213213
/***************************
214214
* STATIC HELPER FUNCTIONS *
215215
***************************/
216216
217217
/* build_ref_id -- collapse whitespace from input text to make it a ref id */
218
-/* FIXME: does this function handle non-Unix newlines? */
218
+/* TODO: maybe also handle CR+LF line endings? */
219219
static int build_ref_id(struct Blob *id, const char *data, size_t size){
220220
size_t beg, i;
221221
char *id_data;
222222
223223
/* skip leading whitespace */
@@ -284,13 +284,14 @@
284284
if( szB ){
285285
int cmp = blob_compare(&a->id, &b->id);
286286
if( cmp ) return cmp;
287287
}else return -1;
288288
}else return szB ? 1 : 0;
289
- /* ids are equal and non-empty */
289
+ /* IDs are equal and non-empty */
290290
if( a->defno < b->defno ) return -1;
291291
if( a->defno > b->defno ) return 1;
292
+ assert(!"reachable");
292293
return 0; /* should never reach here */
293294
}
294295
295296
/* cmp_footnote_sort -- comparison function for footnotes qsort.
296297
* Unreferenced footnotes (when nUsed == 0) sort last and
@@ -1122,23 +1123,28 @@
11221123
return (struct footnote*)( blob_buffer(&rndr->notes.all)
11231124
+( blob_size(&rndr->notes.all)-sizeof fn ));
11241125
}
11251126
11261127
/* Return the offset of the matching closing bracket or 0 if not found.
1127
- * begin[0] must be either '[' or '(' */
1128
+** begin[0] must be either '[' or '('
1129
+**
1130
+** TODO: It seems that things like "\\(" are not handled correctly.
1131
+** That is historical behavior for a corner-case,
1132
+** so it's left as it is until somebody complains.
1133
+*/
11281134
static inline size_t matching_bracket_offset(
11291135
const char* begin,
11301136
const char* end
11311137
){
11321138
const char *i;
11331139
int level;
11341140
const char bra = *begin;
11351141
const char ket = bra=='[' ? ']' : ')';
1136
- assert( bra=='[' || bra=='(' ); /* FIXME: only when debugging */
1142
+ assert( bra=='[' || bra=='(' );
11371143
for(i=begin+1,level=1; i!=end; i++){
11381144
if( *i=='\n' ) /* do nothing */;
1139
- else if( i[-1]=='\\' ) continue; /* ? FIXME: what if \\( ? */
1145
+ else if( i[-1]=='\\' ) continue;
11401146
else if( *i==bra ) level++;
11411147
else if( *i==ket ){
11421148
if( --level<=0 ) return i-begin;
11431149
}
11441150
}
@@ -2310,11 +2316,11 @@
23102316
&& data[i]!='\n'
23112317
&& data[i]!='\r'
23122318
){
23132319
i += 1;
23142320
}
2315
- /* ? FIXME: if( data[i-1]=='>' && data[link_offset-1]!='<' ) */
2321
+ /* TODO: maybe require both data[i-1]=='>' && data[link_offset-1]=='<' ? */
23162322
if( data[i-1]=='>' ) link_end = i-1; else link_end = i;
23172323
23182324
/* optional spacer: (space | tab)* (newline | '\'' | '"' | '(' ) */
23192325
while( i<end && (data[i]==' ' || data[i]=='\t') ){ i++; }
23202326
if( i<end
@@ -2406,12 +2412,11 @@
24062412
/* spacer: colon (space | tab)* */
24072413
if( i>=end || data[i]!=':' ) return 0;
24082414
i++;
24092415
while( i<end && (data[i]==' ' || data[i]=='\t') ){ i++; }
24102416
2411
- /* passthrough truncated footnote definition
2412
- * FIXME: maybe omit it? */
2417
+ /* passthrough truncated footnote definition */
24132418
if( i>=end ) return 0;
24142419
24152420
if( build_ref_id(&fn.id, data+id_offset, id_end-id_offset)<0 ) return 0;
24162421
24172422
/* footnote's text may start on the same line */
@@ -2526,11 +2531,10 @@
25262531
for(const size_t size = blob_size(ib); beg<size ;){
25272532
const char* const data = blob_buffer(ib);
25282533
if( is_ref(data, beg, size, &end, &rndr.refs) ){
25292534
beg = end;
25302535
}else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){
2531
- /* FIXME: fossil_print("\nfootnote found at %i\n", beg); */
25322536
beg = end;
25332537
}else{ /* skipping to the next line */
25342538
end = beg;
25352539
while( end<size && data[end]!='\n' && data[end]!='\r' ){
25362540
end += 1;
25372541
--- src/markdown.c
+++ src/markdown.c
@@ -213,11 +213,11 @@
213 /***************************
214 * STATIC HELPER FUNCTIONS *
215 ***************************/
216
217 /* build_ref_id -- collapse whitespace from input text to make it a ref id */
218 /* FIXME: does this function handle non-Unix newlines? */
219 static int build_ref_id(struct Blob *id, const char *data, size_t size){
220 size_t beg, i;
221 char *id_data;
222
223 /* skip leading whitespace */
@@ -284,13 +284,14 @@
284 if( szB ){
285 int cmp = blob_compare(&a->id, &b->id);
286 if( cmp ) return cmp;
287 }else return -1;
288 }else return szB ? 1 : 0;
289 /* ids are equal and non-empty */
290 if( a->defno < b->defno ) return -1;
291 if( a->defno > b->defno ) return 1;
 
292 return 0; /* should never reach here */
293 }
294
295 /* cmp_footnote_sort -- comparison function for footnotes qsort.
296 * Unreferenced footnotes (when nUsed == 0) sort last and
@@ -1122,23 +1123,28 @@
1122 return (struct footnote*)( blob_buffer(&rndr->notes.all)
1123 +( blob_size(&rndr->notes.all)-sizeof fn ));
1124 }
1125
1126 /* Return the offset of the matching closing bracket or 0 if not found.
1127 * begin[0] must be either '[' or '(' */
 
 
 
 
 
1128 static inline size_t matching_bracket_offset(
1129 const char* begin,
1130 const char* end
1131 ){
1132 const char *i;
1133 int level;
1134 const char bra = *begin;
1135 const char ket = bra=='[' ? ']' : ')';
1136 assert( bra=='[' || bra=='(' ); /* FIXME: only when debugging */
1137 for(i=begin+1,level=1; i!=end; i++){
1138 if( *i=='\n' ) /* do nothing */;
1139 else if( i[-1]=='\\' ) continue; /* ? FIXME: what if \\( ? */
1140 else if( *i==bra ) level++;
1141 else if( *i==ket ){
1142 if( --level<=0 ) return i-begin;
1143 }
1144 }
@@ -2310,11 +2316,11 @@
2310 && data[i]!='\n'
2311 && data[i]!='\r'
2312 ){
2313 i += 1;
2314 }
2315 /* ? FIXME: if( data[i-1]=='>' && data[link_offset-1]!='<' ) */
2316 if( data[i-1]=='>' ) link_end = i-1; else link_end = i;
2317
2318 /* optional spacer: (space | tab)* (newline | '\'' | '"' | '(' ) */
2319 while( i<end && (data[i]==' ' || data[i]=='\t') ){ i++; }
2320 if( i<end
@@ -2406,12 +2412,11 @@
2406 /* spacer: colon (space | tab)* */
2407 if( i>=end || data[i]!=':' ) return 0;
2408 i++;
2409 while( i<end && (data[i]==' ' || data[i]=='\t') ){ i++; }
2410
2411 /* passthrough truncated footnote definition
2412 * FIXME: maybe omit it? */
2413 if( i>=end ) return 0;
2414
2415 if( build_ref_id(&fn.id, data+id_offset, id_end-id_offset)<0 ) return 0;
2416
2417 /* footnote's text may start on the same line */
@@ -2526,11 +2531,10 @@
2526 for(const size_t size = blob_size(ib); beg<size ;){
2527 const char* const data = blob_buffer(ib);
2528 if( is_ref(data, beg, size, &end, &rndr.refs) ){
2529 beg = end;
2530 }else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){
2531 /* FIXME: fossil_print("\nfootnote found at %i\n", beg); */
2532 beg = end;
2533 }else{ /* skipping to the next line */
2534 end = beg;
2535 while( end<size && data[end]!='\n' && data[end]!='\r' ){
2536 end += 1;
2537
--- src/markdown.c
+++ src/markdown.c
@@ -213,11 +213,11 @@
213 /***************************
214 * STATIC HELPER FUNCTIONS *
215 ***************************/
216
217 /* build_ref_id -- collapse whitespace from input text to make it a ref id */
218 /* TODO: maybe also handle CR+LF line endings? */
219 static int build_ref_id(struct Blob *id, const char *data, size_t size){
220 size_t beg, i;
221 char *id_data;
222
223 /* skip leading whitespace */
@@ -284,13 +284,14 @@
284 if( szB ){
285 int cmp = blob_compare(&a->id, &b->id);
286 if( cmp ) return cmp;
287 }else return -1;
288 }else return szB ? 1 : 0;
289 /* IDs are equal and non-empty */
290 if( a->defno < b->defno ) return -1;
291 if( a->defno > b->defno ) return 1;
292 assert(!"reachable");
293 return 0; /* should never reach here */
294 }
295
296 /* cmp_footnote_sort -- comparison function for footnotes qsort.
297 * Unreferenced footnotes (when nUsed == 0) sort last and
@@ -1122,23 +1123,28 @@
1123 return (struct footnote*)( blob_buffer(&rndr->notes.all)
1124 +( blob_size(&rndr->notes.all)-sizeof fn ));
1125 }
1126
1127 /* Return the offset of the matching closing bracket or 0 if not found.
1128 ** begin[0] must be either '[' or '('
1129 **
1130 ** TODO: It seems that things like "\\(" are not handled correctly.
1131 ** That is historical behavior for a corner-case,
1132 ** so it's left as it is until somebody complains.
1133 */
1134 static inline size_t matching_bracket_offset(
1135 const char* begin,
1136 const char* end
1137 ){
1138 const char *i;
1139 int level;
1140 const char bra = *begin;
1141 const char ket = bra=='[' ? ']' : ')';
1142 assert( bra=='[' || bra=='(' );
1143 for(i=begin+1,level=1; i!=end; i++){
1144 if( *i=='\n' ) /* do nothing */;
1145 else if( i[-1]=='\\' ) continue;
1146 else if( *i==bra ) level++;
1147 else if( *i==ket ){
1148 if( --level<=0 ) return i-begin;
1149 }
1150 }
@@ -2310,11 +2316,11 @@
2316 && data[i]!='\n'
2317 && data[i]!='\r'
2318 ){
2319 i += 1;
2320 }
2321 /* TODO: maybe require both data[i-1]=='>' && data[link_offset-1]=='<' ? */
2322 if( data[i-1]=='>' ) link_end = i-1; else link_end = i;
2323
2324 /* optional spacer: (space | tab)* (newline | '\'' | '"' | '(' ) */
2325 while( i<end && (data[i]==' ' || data[i]=='\t') ){ i++; }
2326 if( i<end
@@ -2406,12 +2412,11 @@
2412 /* spacer: colon (space | tab)* */
2413 if( i>=end || data[i]!=':' ) return 0;
2414 i++;
2415 while( i<end && (data[i]==' ' || data[i]=='\t') ){ i++; }
2416
2417 /* passthrough truncated footnote definition */
 
2418 if( i>=end ) return 0;
2419
2420 if( build_ref_id(&fn.id, data+id_offset, id_end-id_offset)<0 ) return 0;
2421
2422 /* footnote's text may start on the same line */
@@ -2526,11 +2531,10 @@
2531 for(const size_t size = blob_size(ib); beg<size ;){
2532 const char* const data = blob_buffer(ib);
2533 if( is_ref(data, beg, size, &end, &rndr.refs) ){
2534 beg = end;
2535 }else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){
 
2536 beg = end;
2537 }else{ /* skipping to the next line */
2538 end = beg;
2539 while( end<size && data[end]!='\n' && data[end]!='\r' ){
2540 end += 1;
2541

Keyboard Shortcuts

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