diff options
| author | verdant <i@glowisle.me> | 2026-05-24 13:55:39 +0800 |
|---|---|---|
| committer | verdant <i@glowisle.me> | 2026-05-24 13:55:39 +0800 |
| commit | b6fe9fc6a4f31d4fa0ddad7fdfd3324cd1c88d3e (patch) | |
| tree | be10b7b732e8358a0fa1bb0b407903fae1fa91c6 /parser.c | |
| download | vmp-b6fe9fc6a4f31d4fa0ddad7fdfd3324cd1c88d3e.tar.gz vmp-b6fe9fc6a4f31d4fa0ddad7fdfd3324cd1c88d3e.zip | |
Initial commit
Diffstat (limited to 'parser.c')
| -rw-r--r-- | parser.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/parser.c b/parser.c new file mode 100644 index 0000000..abb8ca6 --- /dev/null +++ b/parser.c @@ -0,0 +1,47 @@ +#include <stdio.h> +#include "parser.h" + + +/* Return the level of title */ +int parse_title(struct md_token* mt){ + + int level = 0; + if (mt->idx >= mt->line_len) { + return -1; + } + + if (mt->line[mt->idx] == '\0' || mt->line[mt->idx] == '\n') { + return -1; + } + + while(mt->idx < mt->line_len && mt->line[mt->idx] == '#') { + level++; + mt->idx++; + } + + mt->start_pos = mt->idx + 1; + char tmp[1024] = ""; + size_t mt_idx = mt->start_pos; + int idx = 0; + while (mt_idx < mt->line_len && mt->line[mt_idx] != '\0' && mt->line[mt_idx] != '\n') { + tmp[idx] = mt->line[mt_idx]; + mt_idx++; + idx++; + } + printf("<h%d>%s</h%d>", level, tmp, level); + return level; +} + + +int parse_content(struct md_token* mt) { + if (mt->idx >= mt->line_len) { + return -1; + } + + if (mt->line[mt->idx] == '\0' || mt->line[mt->idx] == '\n') { + return -1; + } + + printf("<p>%s</p>",mt->line); + return 0; +} |
