X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=src%2Fparser.c;h=815b9a25d9a73048f138a257cb7ebd940d55d5d9;hb=4499a0ea0cecd41b7053ce5768a85efdfc48848a;hp=ce3f7028b5345214f83778c2c6ed2fa494610b4a;hpb=d35a52bc79a1f8b1b1cd48519b7a9aef86439633;p=smdp.git diff --git a/src/parser.c b/src/parser.c index ce3f702..815b9a2 100644 --- a/src/parser.c +++ b/src/parser.c @@ -225,6 +225,7 @@ deck_t *markdown_load(FILE *input) { // delete line (tmp->text->delete)(tmp->text); free(tmp); + } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_3)) { tmp = line->next; line_t *list_last_level_3 = line; @@ -240,6 +241,7 @@ deck_t *markdown_load(FILE *input) { for(tmp = line; tmp != list_last_level_3; tmp = tmp->next) { SET_BIT(tmp->bits, IS_UNORDERED_LIST_3); } + } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_2)) { tmp = line->next; line_t *list_last_level_2 = line; @@ -256,6 +258,7 @@ deck_t *markdown_load(FILE *input) { for(tmp = line; tmp != list_last_level_2; tmp = tmp->next) { SET_BIT(tmp->bits, IS_UNORDERED_LIST_2); } + } else if(CHECK_BIT(line->bits, IS_UNORDERED_LIST_1)) { tmp = line->next; line_t *list_last_level_1 = line; @@ -299,6 +302,12 @@ int markdown_analyse(cstring_t *text) { const int unordered_list_offset = unordered_list_level_offset[unordered_list_level]; + // return IS_EMPTY on null pointers + if(!text || !text->text) { + SET_BIT(bits, IS_EMPTY); + return bits; + } + // count leading spaces offset = next_nonblank(text, 0); @@ -358,6 +367,36 @@ int markdown_analyse(cstring_t *text) { } else { + // IS_QUOTE + if(text->text[offset] == '>') { + SET_BIT(bits, IS_QUOTE); + } + + // IS_CENTER + if(text->size >= offset + 3 && + text->text[offset] == '-' && + text->text[offset + 1] == '>' && + text->text[offset + 2] == ' ') { + SET_BIT(bits, IS_CENTER); + + // remove start tag + (text->strip)(text, offset, 3); + eol -= 3; + + if(text->size >= offset + 3 && + text->text[eol - 1] == '-' && + text->text[eol - 2] == '<' && + text->text[eol - 3] == ' ') { + + // remove end tags + (text->strip)(text, eol - 3, 3); + + // adjust end of line + for(eol = text->size; eol > offset && isspace((unsigned char) text->text[eol - 1]); eol--); + + } + } + for(i = offset; i < eol; i++) { if(text->text[i] == ' ') { @@ -378,9 +417,7 @@ int markdown_analyse(cstring_t *text) { // IS_H1 if((equals > 0 && hashes + stars + minus + spaces + other == 0) || - (text && - text->text && - text->text[offset] == '#' && + (text->text[offset] == '#' && text->text[offset+1] != '#')) { SET_BIT(bits, IS_H1); @@ -389,22 +426,12 @@ int markdown_analyse(cstring_t *text) { // IS_H2 if((minus > 0 && equals + hashes + stars + spaces + other == 0) || - (text && - text->text && - text->text[offset] == '#' && + (text->text[offset] == '#' && text->text[offset+1] == '#')) { SET_BIT(bits, IS_H2); } - // IS_QUOTE - if(text && - text->text && - text->text[offset] == '>') { - - SET_BIT(bits, IS_QUOTE); - } - // IS_HR if((minus >= 3 && equals + hashes + stars + other == 0) || (stars >= 3 && equals + hashes + minus + other == 0)) {