diff --git a/github_flavoured.c b/github_flavoured.c index 12ed609..0600194 100644 --- a/github_flavoured.c +++ b/github_flavoured.c @@ -66,9 +66,9 @@ gfm_populate(getc_func getc, void* ctx, int flags) */ Line *headers = T(a->content); - a->title = headers; __mkd_header_dle(a->title); - a->author= headers->next; __mkd_header_dle(a->author); - a->date = headers->next->next; __mkd_header_dle(a->date); + a->title = headers; __mkd_trim_line(a->title, 1); + a->author= headers->next; __mkd_trim_line(a->author, 1); + a->date = headers->next->next; __mkd_trim_line(a->date, 1); T(a->content) = headers->next->next->next; } diff --git a/markdown.c b/markdown.c index 513b4bb..44dffe5 100644 --- a/markdown.c +++ b/markdown.c @@ -608,8 +608,7 @@ codeblock(Paragraph *p) Line *t = p->text, *r; for ( ; t; t = r ) { - CLIP(t->text,0,4); - t->dle = mkd_firstnonblank(t); + __mkd_trim_line(t,4); if ( !( (r = skipempty(t->next)) && iscode(r)) ) { ___mkd_freeLineRange(t,r); @@ -804,9 +803,8 @@ quoteblock(Paragraph *p, DWORD flags) /* clip next space, if any */ if ( T(t->text)[qp] == ' ' ) qp++; - CLIP(t->text, 0, qp); + __mkd_trim_line(t,qp); UNCHECK(t); - t->dle = mkd_firstnonblank(t); } q = skipempty(t->next); @@ -855,9 +853,8 @@ listitem(Paragraph *p, int indent, DWORD flags, linefn check) int z; for ( t = p->text; t ; t = q) { - CLIP(t->text, 0, clip); UNCHECK(t); - t->dle = mkd_firstnonblank(t); + __mkd_trim_line(t, clip); /* even though we had to trim a long leader off this item, * the indent for trailing paragraphs is still 4... @@ -1021,10 +1018,7 @@ extrablock(Line *p) p->next = 0; return np; } - if ( np->dle >= 4 ) { - CLIP(np->text, 0, 4); - np->dle -= 4; - } + __mkd_trim_line(np,4); p = np; } return 0; @@ -1064,8 +1058,7 @@ addfootnote(Line *p, MMIOT* f) * snip that out as we go. */ foot->flags |= EXTRA_FOOTNOTE; - CLIP(p->text, 0, j); - p->dle = mkd_firstnonblank(p); + __mkd_trim_line(p,j); np = extrablock(p); diff --git a/markdown.h b/markdown.h index 370e12d..66c527a 100644 --- a/markdown.h +++ b/markdown.h @@ -233,7 +233,7 @@ extern void ___mkd_tidy(Cstring *); extern Document *__mkd_new_Document(); extern void __mkd_enqueue(Document*, Cstring *); -extern void __mkd_header_dle(Line *); +extern void __mkd_trim_line(Line *, int); extern int __mkd_io_strget(struct string_stream *); diff --git a/mkdio.c b/mkdio.c index 79581d1..cc9c269 100644 --- a/mkdio.c +++ b/mkdio.c @@ -74,13 +74,17 @@ __mkd_enqueue(Document* a, Cstring *line) } -/* trim leading blanks from a header line +/* trim leading characters from a line, then adjust the dle. */ void -__mkd_header_dle(Line *p) +__mkd_trim_line(Line *p, int clip) { - CLIP(p->text, 0, 1); - p->dle = mkd_firstnonblank(p); + if ( clip > S(p->text) ) + clip = S(p->text); + if ( clip ) { + CLIP(p->text, 0, clip); + p->dle = mkd_firstnonblank(p); + } } @@ -129,9 +133,9 @@ populate(getc_func getc, void* ctx, int flags) */ Line *headers = T(a->content); - a->title = headers; __mkd_header_dle(a->title); - a->author= headers->next; __mkd_header_dle(a->author); - a->date = headers->next->next; __mkd_header_dle(a->date); + a->title = headers; __mkd_trim_line(a->title, 1); + a->author= headers->next; __mkd_trim_line(a->author, 1); + a->date = headers->next->next; __mkd_trim_line(a->date, 1); T(a->content) = headers->next->next->next; }