move html tag into function

Signed-off-by: Superkooka <aymeric.gueracague@gmail.com>
This commit is contained in:
Aymeric GUERACAGUE 2023-12-19 18:23:33 +01:00
parent 9d01f74cd5
commit 842841acff
1 changed files with 17 additions and 8 deletions

View File

@ -65,29 +65,38 @@
(defn ast-to-html
"Convert an AST to html"
[ast]
(defn to-codeblock [lang value] (string "<pre><code>" (htmlspecialchars value) "</code></pre>"))
(defn to-codeline [value] (string "<code>" (ast-to-html value) "</code>"))
(defn to-heading [level value] (string "<h" level ">" (htmlspecialchars value) "</h" level ">"))
(defn to-quote [value] (string "<blockquote>" (ast-to-html value) "</blockquote>"))
(defn to-line [value] (string "<p>" (ast-to-html value) "</p>"))
(defn to-italic [value] (string "<em>" (ast-to-html value) "</em>"))
(defn to-bold [value] (string "<strong>" (ast-to-html value) "</strong>"))
(defn to-stroke [value] (string "<stroke>" (ast-to-html value) "</stroke>"))
(string/join
(map
|(match $0
[:code-block lang value]
(string "<pre><code>" (htmlspecialchars value) "</code></pre>")
(to-codeblock lang value)
[:heading level value]
(string "<h" level ">" (htmlspecialchars value) "</h" level ">")
(to-heading level value)
[:quote value]
(string "<blockquote>" (ast-to-html value) "</blockquote>")
(to-quote value)
[:hr]
"<hr/>"
[:line value]
(string "<p>" (ast-to-html value) "</p>")
(to-line value)
[:text value]
(htmlspecialchars value)
[:italic value]
(string "<em>" (ast-to-html value) "</em>")
(to-italic value)
[:stroke value]
(string "<stroke>" (ast-to-html value) "</stroke>")
(to-stroke value)
[:bold value]
(string "<strong>" (ast-to-html value) "</strong>")
(to-bold value)
[:code-line value]
(string "<code>" (ast-to-html value) "</code>")
(to-codeline value)
_
(error (string "Invalid symbol: " (get $0 0))))
ast)