我正在构建一个小部件。因此,用户必须复制粘贴代码从我的网站到他们的HTML。
我想做两件事。
我担心如果代码中有</br>,也会被复制。我不想要的。
<code>{` <!-- Start of client code snippet -->
<script>
(function (w, d, s, o, f, js, fjs) {
w[o] =
w[o] ||
function () {
(w[o].q = w[o].q || []).push(arguments);
};
(js = d.createElement(s)), (fjs = d.getElementsByTagName(s)[0]);
js.id = o;
js.src = f;
js.async = 1;
fjs.parentNode.insertBefore(js, fjs);
})(window, document, "script", "_hw", "./widget.js");
_hw("init", { debug: true, clientID: "abcd" });
</script>
<!-- End of client code snippet -->
`} </code>发布于 2022-02-07 13:07:20
使用<pre>标签
<code>
<pre>
(function (w, d, s, o, f, js, fjs) {
w[o] =
w[o] ||
function () {
(w[o].q = w[o].q || []).push(arguments);
};
(js = d.createElement(s)), (fjs = d.getElementsByTagName(s)[0]);
js.id = o;
js.src = f;
js.async = 1;
fjs.parentNode.insertBefore(js, fjs);
})(window, document, "script", "_hw", "./widget.js");
_hw("init", { debug: true, clientID: "abcd" });
</pre>
</code>
发布于 2022-02-07 13:20:25
或者,您可以像使用Syntax Highlighters一样使用prismjs。
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.26.0/prism.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.26.0/themes/prism-okaidia.min.css" rel="stylesheet" />
<pre>
<code class="language-js">
(function (w, d, s, o, f, js, fjs) {
w[o] =
w[o] ||
function () {
(w[o].q = w[o].q || []).push(arguments);
};
(js = d.createElement(s)), (fjs = d.getElementsByTagName(s)[0]);
js.id = o;
js.src = f;
js.async = 1;
fjs.parentNode.insertBefore(js, fjs);
})(window, document, "script", "_hw", "./widget.js");
_hw("init", { debug: true, clientID: "abcd" });
</code>
</pre>
https://stackoverflow.com/questions/71019058
复制相似问题