The textContent
DOM property will let you access the plain text content of a DOM node, so just get the prettified <pre>
element.
document.getElementsByClassName('prettyprinted')[0].textContent
Since textContent
just concatenates text nodes, it works for prettyprinted <pre>
and <xmp>
elements and <code>
elements that have CSS style whitespace:pre
.
It should work for elements with linenums
where prettify inserts an <li>
element per line because the text still contains the original line-breaks, but I would test that separately if you rely upon that.