parses md files and adds css. doesnt make dirs tho

This commit is contained in:
Simon Kellet
2026-03-07 13:02:26 +00:00
parent 023ae00e71
commit 6f3e0899bb
2 changed files with 57 additions and 28 deletions
+27 -5
View File
@@ -1,5 +1,6 @@
package main
import "base:runtime"
import "core:fmt"
import "core:os"
import "core:strings"
@@ -7,11 +8,10 @@ import cm "vendor:commonmark"
MD_SUFFIX :: ".md"
CSS_PREFIX :: "<head><link rel=\"stylesheet\" href=\"./css/style.css\">"
MASTODON_PREFIX :: "<a rel=me href=https://linuxrocks.online/@simonkellet></a>"
walk_tree_and_get_md_names :: proc(
path: string,
allocator := context.allocator,
) -> [dynamic]string {
walk_tree_and_get_md_names :: proc(path: string, allocator: runtime.Allocator) -> [dynamic]string {
files := make([dynamic]string, allocator)
@@ -70,9 +70,10 @@ walk_tree :: proc(path: string) -> []u8 {
}
/*
parse_file_md_to_html :: proc(
filename: string,
allocator := context.allocator,
allocator: runtime.Allocator,
) -> (
parsed: cstring,
err: os.Error,
@@ -88,3 +89,24 @@ parse_file_md_to_html :: proc(
return html, nil
}
*/
parse_file_md_to_html :: proc(
filename: string,
allocator: runtime.Allocator,
) -> (
parsed: string,
err: os.Error,
) {
str := os.read_entire_file_from_path(filename, allocator) or_return
root := cm.parse_document(raw_data(str), len(str), cm.DEFAULT_OPTIONS)
defer cm.node_free(root)
html := cm.render_html(root, cm.DEFAULT_OPTIONS)
defer cm.free(html)
parsed = strings.clone_from_cstring(html, allocator)
return parsed, nil
}