4

私はサイトのスクレイパーを書いています。目標は、再フォーマットされたサイトのバージョンを作成することです。スクレイピングの一環として、いくつかのコメントに飛び込みます。コメントには、html 形式が含まれている可能性があるため、次のようになります。

{... :content ("そして、低い声で\"これは" {:tag :em, :attrs nil, :content ("common")} "?\"")}

問題は、次のように、この :content 値のコンテンツを取得して、組み込みの enlive 関数を使用して HTML に変換できるかどうかです。

これは<em>一般的</em>ですか?

これらのタグを処理するために何かを書く方法はわかりますが、エッジケースを見逃す可能性があるため、何かを自作することを非常にためらっています.

4

1 に答える 1

4

私が知る限り組み込まれておらず、組み込まれるにはあまりにも具体的すぎるようです。私の解決策:

(require '[net.cgrand.enlive-html :as html])

(def my-node '{:tag :p, 
               :content ("And, in a lower voice, \"Is this" 
                        {:tag :em, :attrs nil, :content ("common")} "?\"")})

;; for escaped string:
(apply str (html/emit* (:content my-node)))
=> "And, in a lower voice, \"Is this<em>common</em>?\""

;; print in human readable form
(print (apply str (html/emit* (:content my-node))))
=> And, in a lower voice, "Is this<em>common</em>?"
   nil
于 2014-02-02T09:16:30.797 に答える