【发布时间】:2013-01-09 11:00:58
【问题描述】:
假设我有一个 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 是否内置了这个?没找到。
【问题讨论】: