1

このhtmlスニペットがあります。そのスニペットを解析し、javascript タグなしで html を出力したい

<html>
    <body>
        <div class="content">lorem ipsum</div>
        <script  src="/js/jquery.js" type="text/javascript"></script>
        <script src="/js/bootstrap.min.js" type="text/javascript"></script>
    </body>
</html>

これになる

<html>
    <body>
        <div class="content">lorem ipsum</div>
    </body>
</html>

タグを削除する enlive ヘルパー関数が見つかりませんでした。

例のおかげで解決策が見つかりました。だから私はこのコードを書いて、jsが消えました

(html/deftemplate template-about "../resources/public/build/about/index.html"
    []
    [:script] (fn js-clear [& args] nil)
)
4

3 に答える 3

2

レンダリングされたページのいくつかのタグを条件付きで削除する必要がある場合の私の通常のアプローチは、nil returning関数を使用することです。

例えば

(html/defsnippet upgrade-plan "page_templates/upgrade-plan.html" [:#upgradePlanSection]
  [pending-invoice ... ]
  ...
  [:#delayedPlanWarning] #(when pending-invoice
                            (html/at %
                                     [:#delayedPlanWarning] (html/remove-attr :style)
                                     [:.messagesText] (html/html-content (tower/t :plans/pending-invoice 
                                                                                (:id pending-invoice)))))
  ...

その特定のケースでpending-invoiceは、関数が を返すためnildelayedPlanWarning要素がレンダリングされた html から削除されますnil

于 2013-10-24T16:41:02.450 に答える
0

余分な解析と発行を気にしない場合は、次のようにするとうまくいきます。

(def orig (html-resource (java.io.StringReader. "<html>
<body>
    <div class=\"content\">lorem ipsum</div>
    <script  src=\"/js/jquery.js\" type=\"text/javascript\"></script>
    <script src=\"/js/bootstrap.min.js\" type=\"text/javascript\"></script>
</body>
</html>")))
(def stripped (transform orig [(keyword "script")] (substitute "")))
(apply str (emit* stripped))
于 2013-10-24T17:53:31.023 に答える