X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=parser.c;h=1ff125c69775ca61ce981e10f5216a26ed7fbff3;hb=6edf0543111ac7f119c0255ae254159d9508f770;hp=9c5d62864e585b3d251df88d770c97c0141f9176;hpb=4ec3d2a00fa0a10505afd7f0fe80d80ee576a738;p=smdp.git diff --git a/parser.c b/parser.c index 9c5d628..1ff125c 100644 --- a/parser.c +++ b/parser.c @@ -40,6 +40,7 @@ deck_t *markdown_load(FILE *input) { deck_t *deck = new_deck(); slide_t *slide = new_slide(); line_t *line = NULL; + line_t *tmp = NULL; cstring_t *text = cstring_init(); // assign first slide to deck @@ -52,9 +53,15 @@ deck_t *markdown_load(FILE *input) { // markdown analyse bits = markdown_analyse(text); + // if first line in file is markdown hr + if(!line && CHECK_BIT(bits, IS_HR)) { + + // clear text + (text->reset)(text); + // if text is markdown hr - if(CHECK_BIT(bits, IS_HR) && - CHECK_BIT(line->bits, IS_EMPTY)) { + } else if(CHECK_BIT(bits, IS_HR) && + CHECK_BIT(line->bits, IS_EMPTY)) { slide->lines = lc; @@ -198,7 +205,7 @@ deck_t *markdown_load(FILE *input) { if(line->next) line->next->prev = line->prev; - // set bits on revious line + // set bits on previous line if(CHECK_BIT(line->bits, IS_H1)) { SET_BIT(line->prev->bits, IS_H1); } else { @@ -208,9 +215,13 @@ deck_t *markdown_load(FILE *input) { // adjust line count slide->lines -= 1; + // maintain loop condition + tmp = line; + line = line->prev; + // delete line - (line->text->delete)(line->text); - free(line); + (tmp->text->delete)(tmp->text); + free(tmp); } line = line->next; }