From 48750fe720c2f4917803535ec56bc52f937764fd Mon Sep 17 00:00:00 2001 From: Linnnus Date: Sun, 4 Feb 2024 09:52:32 +0100 Subject: feat(creole): support headers --- src/creole.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/creole.c') diff --git a/src/creole.c b/src/creole.c index f69c543..7eb6ad5 100644 --- a/src/creole.c +++ b/src/creole.c @@ -32,29 +32,35 @@ int do_headers(const char *begin, const char *end, bool new_block, FILE *out) { } unsigned level = 0; - while (*begin == '=') { + const char *start = begin; + while (*start == '=') { level += 1; - begin += 1; + start += 1; + } + if (level > 6) { + return 0; } - DEBUG("level %d\n", level); - while (isspace(*begin)) { - begin += 1; + while (isspace(*start)) { + start += 1; } - const char *stop = end; - while (stop + 1 != end && stop[1] != '\n') { - stop += 1; + const char *eol = start; + while (eol != end && *eol != '\n') { + eol += 1; } - while (*stop == '=') { + + const char *stop = eol; + assert(stop > begin); + while (stop[-1] == '=' || isspace(stop[-1])) { stop -= 1; } fprintf(out, "", level); - process(begin, stop, false, out); + process(start, stop, false, out); fprintf(out, "", level); - return -(stop - begin); + return -(eol - begin); } void process(const char *begin, const char *end, bool new_block, FILE *out) { @@ -73,7 +79,6 @@ void process(const char *begin, const char *end, bool new_block, FILE *out) { // Greedily try all parsers. int affected; for (unsigned i = 0; i < LENGTH(parsers); ++i) { - DEBUG("%p\n", parsers[i]); affected = parsers[i](p, end, new_block, out); if (affected) { break; -- cgit v1.2.3