Fossil SCM
Clean-up and rephrase some comments.
Commit
a62c876896ae11002ba464a71fc92ef94a191be617042923dd0dd4db5dd461d3
Parent
a36dd09d17f3057…
1 file changed
+13
-9
+13
-9
| --- src/markdown.c | ||
| +++ src/markdown.c | ||
| @@ -213,11 +213,11 @@ | ||
| 213 | 213 | /*************************** |
| 214 | 214 | * STATIC HELPER FUNCTIONS * |
| 215 | 215 | ***************************/ |
| 216 | 216 | |
| 217 | 217 | /* 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? */ | |
| 219 | 219 | static int build_ref_id(struct Blob *id, const char *data, size_t size){ |
| 220 | 220 | size_t beg, i; |
| 221 | 221 | char *id_data; |
| 222 | 222 | |
| 223 | 223 | /* skip leading whitespace */ |
| @@ -284,13 +284,14 @@ | ||
| 284 | 284 | if( szB ){ |
| 285 | 285 | int cmp = blob_compare(&a->id, &b->id); |
| 286 | 286 | if( cmp ) return cmp; |
| 287 | 287 | }else return -1; |
| 288 | 288 | }else return szB ? 1 : 0; |
| 289 | - /* ids are equal and non-empty */ | |
| 289 | + /* IDs are equal and non-empty */ | |
| 290 | 290 | if( a->defno < b->defno ) return -1; |
| 291 | 291 | if( a->defno > b->defno ) return 1; |
| 292 | + assert(!"reachable"); | |
| 292 | 293 | return 0; /* should never reach here */ |
| 293 | 294 | } |
| 294 | 295 | |
| 295 | 296 | /* cmp_footnote_sort -- comparison function for footnotes qsort. |
| 296 | 297 | * Unreferenced footnotes (when nUsed == 0) sort last and |
| @@ -1122,23 +1123,28 @@ | ||
| 1122 | 1123 | return (struct footnote*)( blob_buffer(&rndr->notes.all) |
| 1123 | 1124 | +( blob_size(&rndr->notes.all)-sizeof fn )); |
| 1124 | 1125 | } |
| 1125 | 1126 | |
| 1126 | 1127 | /* 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 | +*/ | |
| 1128 | 1134 | static inline size_t matching_bracket_offset( |
| 1129 | 1135 | const char* begin, |
| 1130 | 1136 | const char* end |
| 1131 | 1137 | ){ |
| 1132 | 1138 | const char *i; |
| 1133 | 1139 | int level; |
| 1134 | 1140 | const char bra = *begin; |
| 1135 | 1141 | const char ket = bra=='[' ? ']' : ')'; |
| 1136 | - assert( bra=='[' || bra=='(' ); /* FIXME: only when debugging */ | |
| 1142 | + assert( bra=='[' || bra=='(' ); | |
| 1137 | 1143 | for(i=begin+1,level=1; i!=end; i++){ |
| 1138 | 1144 | if( *i=='\n' ) /* do nothing */; |
| 1139 | - else if( i[-1]=='\\' ) continue; /* ? FIXME: what if \\( ? */ | |
| 1145 | + else if( i[-1]=='\\' ) continue; | |
| 1140 | 1146 | else if( *i==bra ) level++; |
| 1141 | 1147 | else if( *i==ket ){ |
| 1142 | 1148 | if( --level<=0 ) return i-begin; |
| 1143 | 1149 | } |
| 1144 | 1150 | } |
| @@ -2310,11 +2316,11 @@ | ||
| 2310 | 2316 | && data[i]!='\n' |
| 2311 | 2317 | && data[i]!='\r' |
| 2312 | 2318 | ){ |
| 2313 | 2319 | i += 1; |
| 2314 | 2320 | } |
| 2315 | - /* ? FIXME: if( data[i-1]=='>' && data[link_offset-1]!='<' ) */ | |
| 2321 | + /* TODO: maybe require both data[i-1]=='>' && data[link_offset-1]=='<' ? */ | |
| 2316 | 2322 | if( data[i-1]=='>' ) link_end = i-1; else link_end = i; |
| 2317 | 2323 | |
| 2318 | 2324 | /* optional spacer: (space | tab)* (newline | '\'' | '"' | '(' ) */ |
| 2319 | 2325 | while( i<end && (data[i]==' ' || data[i]=='\t') ){ i++; } |
| 2320 | 2326 | if( i<end |
| @@ -2406,12 +2412,11 @@ | ||
| 2406 | 2412 | /* spacer: colon (space | tab)* */ |
| 2407 | 2413 | if( i>=end || data[i]!=':' ) return 0; |
| 2408 | 2414 | i++; |
| 2409 | 2415 | while( i<end && (data[i]==' ' || data[i]=='\t') ){ i++; } |
| 2410 | 2416 | |
| 2411 | - /* passthrough truncated footnote definition | |
| 2412 | - * FIXME: maybe omit it? */ | |
| 2417 | + /* passthrough truncated footnote definition */ | |
| 2413 | 2418 | if( i>=end ) return 0; |
| 2414 | 2419 | |
| 2415 | 2420 | if( build_ref_id(&fn.id, data+id_offset, id_end-id_offset)<0 ) return 0; |
| 2416 | 2421 | |
| 2417 | 2422 | /* footnote's text may start on the same line */ |
| @@ -2526,11 +2531,10 @@ | ||
| 2526 | 2531 | for(const size_t size = blob_size(ib); beg<size ;){ |
| 2527 | 2532 | const char* const data = blob_buffer(ib); |
| 2528 | 2533 | if( is_ref(data, beg, size, &end, &rndr.refs) ){ |
| 2529 | 2534 | beg = end; |
| 2530 | 2535 | }else if(is_footnote(data, beg, size, &end, &rndr.notes.all)){ |
| 2531 | - /* FIXME: fossil_print("\nfootnote found at %i\n", beg); */ | |
| 2532 | 2536 | beg = end; |
| 2533 | 2537 | }else{ /* skipping to the next line */ |
| 2534 | 2538 | end = beg; |
| 2535 | 2539 | while( end<size && data[end]!='\n' && data[end]!='\r' ){ |
| 2536 | 2540 | end += 1; |
| 2537 | 2541 |
| --- 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 |