2012-12-02 7 views
2

나는 contenteditable pre에서 코드를 강조하기 위해 google prettify를 사용하고 있습니다. contenteditable pre는 div 노드를 포함하고 사용자가 enter 또는 bspace를 누를 때 각 행에 div를 작성/삭제합니다.contenteditable에서 문법 강조 강조 pre

내 pre 요소에 한 줄에 모두 초기 코드가 포함되어 있습니다 (한 줄에 있어야만 제대로 작동합니다. &이므로 성가신 \ n 또는 텍스트 노드가 없습니다). //one line comments을 할 때 싸게 치장이 좋아하지 않는

<pre contenteditable="true" class="prettyprint"><div>&lt;html&gt;</div><div>&lt;body&gt;</div><div>&lt;script&gt;</div><div>var a =3;</div><div>//this is the problem</div><div>function problem(){ return 3; }</div><div>function wrongColor(){};<div>&lt;/script&gt;</div><div>&lt;/body&gt;</div><div>&lt;/html&gt;</div></pre> 

, 그것은 여러 줄에 걸쳐 코멘트. http://jsfiddle.net/grantk/jwfMr/

내 질문은 : 소스를 수정하지 않고 CSS 나 자바 스크립트로이 문제를 해결하는 쉬운 방법이있다

이 가장 쉬운 방법은 바이올린 보는 것입니다 설명하기?

답변

1

각 div 노드의 innerHTML을 for 루프에 prettyPrintOne() 만들었습니다.