feat(ast): add list html export

This commit is contained in:
Jef Roosens 2024-03-19 15:09:51 +01:00
parent e0852de230
commit 2dfbf8a986
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
3 changed files with 44 additions and 3 deletions

View file

@ -1,16 +1,36 @@
#include <assert.h>
#include <stdio.h>
#include <sys/stat.h>
#include "mrk/lexer.h"
#include "mrk/parser.h"
#include "mrk/ast.h"
int main() {
const char *buf = "# this is a header\n\nthis is a paragraph with a [link](https://example.com)";
int main(int argc, char **argv) {
if (argc == 1) {
fprintf(stderr, "No file provided.");
return 1;
}
struct stat stat_s;
assert(stat(argv[1], &stat_s) == 0);
char *buf = malloc(stat_s.st_size);
assert(buf);
long read = 0;
FILE *f = fopen(argv[1], "rb");
assert(f);
while (read < stat_s.st_size) {
read += fread(buf + read, 1, stat_s.st_size - read, f);
}
mrk_lexer *lexer;
assert(mrk_lexer_init(&lexer) == mrk_err_ok);
mrk_lexer_open(lexer, buf, 0);
mrk_lexer_open(lexer, buf, stat_s.st_size);
mrk_parser *parser;
assert(mrk_parser_init(&parser) == mrk_err_ok);

10
example/example.md Normal file
View file

@ -0,0 +1,10 @@
## This is header
This is a paragraph with a [link](https://example.com).
1. list item 1
1. sublist item 1
this is a continuation block
another paragraph
2. list item 2