我想像下面这样将博客文章存储在EDN文件中,然后将其转换为HTML。
这是一个示例文件
{:slug "slug"
:title "The first blog post"
:body [[:div
[:p "First paragraph"]
[:ul
[:li "List Item 1"]
[:li "List Item 2"]
[:li "List Item 3"]]
[:p "Second paragraph"]]]}
然后我尝试使用以下代码读取它
(ns cl-www.core
(:use [hiccup.core])
(:require [cl-www.logic :refer [render-everything]]
[cl-www.common :refer [prettify-html]]
[clojure.edn]
[clojure.java.io])
(:import (org.jsoup Jsoup)
(org.jsoup.nodes Document))
(:gen-class))
(def path "/Users/myuser/cl-www/resources/p-2022-12-17.edn")
(defn test-edn
[]
(let [post-data (-> path
(slurp)
(read-string))
post-struct (:body post-data)
html-struct [:html
[:body
[:h1 "Hello"]
post-struct]]
html (->> html-struct
(html)
(prettify-html))]
(println html)))
当我运行(test-edn)
时,我得到了以下错误
执行错误(IllegalArgumentException)在hiccup.compiler/normalize-element (compiler.clj:59)。[:div [:p "第一段"] [:ul [:li "列表项1"] [:li "列表项2"] [:li "列表项3"]] [:p "第二段"]] 不是有效的元素名称。
我该如何修复它,也就是说
- 手动编写一个EDN文件,然后
- 在Clojure中读取它,
- 将其插入到Hiccup结构中,并
- 将其导出为HTML?