2014-04-27 9 views
0

Google에서 이미 인코딩 된 구문을 디코딩하는 (이미 구현 된) 솔루션이 코드가 있습니까?prettify를 디코딩 할 수 있습니까?

<?php 
$foo = "bar"; 

내가 그래서 그냥 얻을, 당신이 DOM 노드의 일반 텍스트 콘텐츠에 액세스하게됩니다

<?php 
$foo = "bar"; 
+0

'textContent'가 작동해야합니다 –

+0

예를 들어 주시겠습니까? – Lucas

+0

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

답변

1

textContent DOM 속성에 다시 디코딩하려면 지금

<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> 

에 도달 prettified <pre> 요소입니다. textContent 그냥 텍스트 노드를 연결합니다 때문에

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

, 그것은 prettyprinted <pre><xmp> 요소 및 CSS 스타일 whitespace:pre<code> 요소를 사용할 수 있습니다.

이있는 요소의 경우 prettify는 <li> 개의 요소를 삽입합니다. 텍스트는 원래 줄 바꿈 문자가 여전히 포함되어 있기 때문에이 정보를 사용하는 것이 좋습니다.