chore: added example binary showcasing simple html conversion
parent
8a758d3824
commit
07539403cc
|
@ -3,3 +3,4 @@ build/
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
.cache/
|
.cache/
|
||||||
vgcore.*
|
vgcore.*
|
||||||
|
perf.*
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -81,7 +81,7 @@ $(BUILD_DIR)/$(TEST_DIR)/%.c.o: $(TEST_DIR)/%.c
|
||||||
build-example: $(BINS_EXAMPLE)
|
build-example: $(BINS_EXAMPLE)
|
||||||
|
|
||||||
$(BINS_EXAMPLE): %: %.c.o $(LIB)
|
$(BINS_EXAMPLE): %: %.c.o $(LIB)
|
||||||
$(CC) \
|
$(CC) $(_LDFLAGS) \
|
||||||
$^ -o $@
|
$^ -o $@
|
||||||
|
|
||||||
# Example binaries link the resulting library
|
# Example binaries link the resulting library
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.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)";
|
||||||
|
|
||||||
|
mrk_lexer *lexer;
|
||||||
|
assert(mrk_lexer_init(&lexer) == mrk_err_ok);
|
||||||
|
mrk_lexer_open(lexer, buf, 0);
|
||||||
|
|
||||||
|
mrk_parser *parser;
|
||||||
|
assert(mrk_parser_init(&parser) == mrk_err_ok);
|
||||||
|
mrk_parser_open(parser, lexer);
|
||||||
|
|
||||||
|
mrk_ast_node *root;
|
||||||
|
assert(mrk_parser_parse(&root, parser) == mrk_err_ok);
|
||||||
|
|
||||||
|
char *html;
|
||||||
|
assert(mrk_ast_to_html(&html, buf, root) == mrk_err_ok);
|
||||||
|
|
||||||
|
printf("%s\n", html);
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
#include "mrk/lexer.h"
|
#include "mrk/lexer.h"
|
||||||
#include "mrk/parser_internal.h"
|
#include "mrk/parser.h"
|
||||||
|
|
||||||
#define LEXER_INIT() \
|
#define LEXER_INIT() \
|
||||||
mrk_lexer *lxr; \
|
mrk_lexer *lxr; \
|
||||||
|
|
Loading…
Reference in New Issue