假设我有一个 html 文档:
<html>test<html>
我想在浏览器中显示该代码。然后我会创建类似的东西:
<html><body>
<pre><html>test<html></pre>
</body></html>
为了制作中间的gubbins,我有一个功能:
(defn html-escape [string]
(str "<pre>" (clojure.string/escape string {\< "<", \> ">"}) "</pre>"))
它为我做了上述转换:
user> (html-escape "<html>test<html>")
"<pre><html>test<html></pre>"
我的问题是:这是否足够好,还是我会遇到 html 会使转换中断?
第二个问题可能是:clojure 是否内置了这个?我找不到它。