我想像下面的样子将博客文章存储在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 "First paragraph"] [:ul [:li "List Item 1"] [:li "List Item 2"] [:li "List Item 3"]] [:p "Second paragraph"]]不是有效的元素名称。
我该如何修复,也就是说。
- 手动编写一个EDN文件,然后
- 在Clojure中读取它,
- 将其插入Hiccup结构中,
- 然后将其导出为HTML?