Simple HTML render

This commit is contained in:
2026-07-14 15:39:06 +02:00
parent 7f6950b8fe
commit dc49129999
3 changed files with 111 additions and 1 deletions
+83
View File
@@ -0,0 +1,83 @@
package main
import "core:fmt"
print_html :: proc(token: ^Token) {
switch token.type {
case TokenType.Root:
for child in token.children {
print_html(child)
}
case TokenType.Header:
level := 1
if v, ok := token.value.(int); ok {
level = v
}
fmt.printf("<h%d>", level)
for child in token.children {
print_html(child)
}
fmt.printf("</h%d>\n", level)
case TokenType.Paragraph:
fmt.print("<p>")
for child in token.children {
print_html(child)
}
fmt.print("</p>\n")
case TokenType.Blockquote:
fmt.print("<blockquote>\n")
for child in token.children {
print_html(child)
}
fmt.print("</blockquote>\n")
case TokenType.UnorderedList:
fmt.print("<ul>\n")
for child in token.children {
print_html(child)
}
fmt.print("</ul>\n")
case TokenType.OrderedList:
fmt.print("<ol>\n")
for child in token.children {
print_html(child)
}
fmt.print("</ol>\n")
case TokenType.ListItem:
fmt.print("<li>")
for child in token.children {
print_html(child)
}
fmt.print("</li>\n")
case TokenType.Bold:
fmt.print("<strong>")
for child in token.children {
print_html(child)
}
fmt.print("</strong>")
case TokenType.Italics:
fmt.print("<em>")
for child in token.children {
print_html(child)
}
fmt.print("</em>")
case TokenType.BreakLine:
fmt.print("<br>\n")
case TokenType.Text:
if v, ok := token.value.(string); ok {
fmt.print(v)
}
for child in token.children {
print_html(child)
}
}
}