0

Is there a (already implemented) solution that decodes already encoded syntax from googles code-prettify?

<?php
$foo = "bar";

gets to

<pre class="prettyprint prettyprinted"><span class="pun">&lt;?</span><span class="pln">php
$foo </span><span class="pun">=</span><span class="pln"> </span><span class="str">"bar"</span><span class="pun">;</span></pre>

Now I want decode it again to

<?php
$foo = "bar";
4

1 回答 1

1

DOM 属性将textContent允许您访问 DOM 节点的纯文本内容,因此只需获取美化<pre>元素。

document.getElementsByClassName('prettyprinted')[0].textContent

由于textContent只是连接文本节点,因此它适用于 prettyprinted<pre>和具有 CSS 样式的<xmp>元素和元素。<code>whitespace:pre

它应该适用于linenumsprettify 每行插入一个<li>元素的元素,因为文本仍然包含原始换行符,但如果你依赖它,我会单独测试。

于 2014-04-27T04:51:46.157 回答