6

私はJavascriptコードプリティファイアーを試していて、質問を思いつきました.

静的 html に割り当てず、class="prettyprint"後で<pre>prettyprint を適用したい場合 (たとえば、ユーザーが Web ページの「カラー化」ボタンをクリックしたとき)、どうすればこれを実現できますか?

元の run_prettify.js または prettify.js を少し変更しても問題ありません。オフラインで使用するためです。

私の実験:

try-delay-class.html の書き込み:

<html>
<head>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
</head>
See it:
<pre>
class Voila {
public:
  // Voila
  static const string VOILA = "Voila";

  // will not interfere with embedded <a href="#voila1">tags</a>.
}
</pre>
</html>

Chrome v26 で開き、コンソールを起動して、次を実行します。

pres=document.getElementsByTagName('pre')
pres[0].className+=" prettyprint"

シンタックスカラーが出ません。

ここに画像の説明を入力

4

2 に答える 2