X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=markdown_io.c;h=ba2ff7acb25afa54e2bb22cc0665042329e78dfc;hb=c8c3b3d8b2755bddb5c9562ead12d659c31f3090;hp=af04eed61c04ccd1d2b846e7dd7008bb5f03c973;hpb=76cedc9066d3fd65788f86ea5d0b71db98bb6e24;p=smdp.git diff --git a/markdown_io.c b/markdown_io.c index af04eed..ba2ff7a 100644 --- a/markdown_io.c +++ b/markdown_io.c @@ -6,7 +6,7 @@ document_t *markdown_load(FILE *input) { - int c, i, bits; + int c = 0, i = 0, bits = 0; document_t *doc; page_t *page; @@ -56,9 +56,12 @@ document_t *markdown_load(FILE *input) { // calc offset line->offset = next_nonblank(text, 0); + + // new text + text = cstring_init(); } - } else if('\t') { + } else if(c == '\t') { // expand tab to spaces for (i = 0; i <= 4; i++) @@ -71,16 +74,34 @@ document_t *markdown_load(FILE *input) { } } - //TODO detect header + // detect header + line = doc->page->line; + if(line && line->text->size > 0 && line->text->text[0] == '%') { + + // assign header to document + doc->header = line; + + // find first non-header line + while(line->text->size > 0 && line->text->text[0] == '%') { + line = line->next; + } + + // split linked list + line->prev->next = (void*)0; + line->prev = (void*)0; + + // remove header lines from page + doc->page->line = line; + } return doc; } int markdown_analyse(cstring_t *text) { - int c, i, bits, - offset, eol, - equals, hashes, stars, minus, plus, - spaces, other; + int i = 0, bits = 0, + offset = 0, eol = 0, + equals = 0, hashes = 0, stars = 0, minus = 0, plus = 0, + spaces = 0, other = 0; // count leading spaces offset = next_nonblank(text, 0); @@ -130,3 +151,9 @@ int next_nonblank(cstring_t *text, int i) { return i; }; +int next_blank(cstring_t *text, int i) { + while ((i < text->size) && !isspace((text->text)[i])) + ++i; + return i; +}; +