Nodereadonを使用している場合。
js-htmlencode をインストールします パッケージ:
npm install -S js-htmlencode
次に、生のデータベース出力を htmlDecodeで実行します。 一度メソッド。 Pugスクリプトにデータを渡す前に、サーバーアプリでこれを行う必要があります:
サーバーJavascript:
const htmlDecode = require("js-htmlencode").htmlDecode;
app.get("/htmldecode", (req, res) => {
const raw = "<h1>This is <span style='color:red'>RED</span>!!</h1>"
res.render("htmldecode", { raw: raw, decoded: htmlDecode(raw) })
});
htmldecode.pug:
html
head
body
h3 Html Decoding Twice
p Using !: !{raw}
p Using #: #{raw}
p Final: !{decoded}
実際の出力:
!{raw}に注意する必要があります にはレンダリングされません 。文字通り、つまり…
&lt;h1>…にレンダリングされます 。 &lt;を表示するのはブラウザです <として 。
!の使用に伴うすべての注意事項に注意してください。 演算子。