X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=markdown_io.c;h=ba2ff7acb25afa54e2bb22cc0665042329e78dfc;hb=c8c3b3d8b2755bddb5c9562ead12d659c31f3090;hp=58c7f3ab4a6bec25fde1f07cda1b5888f6a6de9d;hpb=5ef15d236a390f60d3bfb435325c6b40e3bfede2;p=smdp.git diff --git a/markdown_io.c b/markdown_io.c index 58c7f3a..ba2ff7a 100644 --- a/markdown_io.c +++ b/markdown_io.c @@ -74,7 +74,25 @@ 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; } @@ -133,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; +}; +