diff options
author | Linnnus <[email protected]> | 2024-02-04 09:52:32 +0100 |
---|---|---|
committer | Linnnus <[email protected]> | 2024-02-04 20:26:23 +0100 |
commit | 48750fe720c2f4917803535ec56bc52f937764fd (patch) | |
tree | 2912ce65c5361061202fcf3f883527312ca99493 /src/creole.c | |
parent | de89d156ba203298d0c831f86e15b6354fbf8ed5 (diff) |
feat(creole): support headers
Diffstat (limited to 'src/creole.c')
-rw-r--r-- | src/creole.c | 29 |
1 files changed, 17 insertions, 12 deletions
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, "<h%u>", level); - process(begin, stop, false, out); + process(start, stop, false, out); fprintf(out, "</h%u>", 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; |