2013-04-23 70 views
0

我打開ckeditor,默認情況下顯示下面的內容。顯示ckeditor中的html標記

<textarea id="editor1" name="editor1" rows="30" cols="120"><p>We can use&nbsp;<strong>prettify&nbsp;</strong>to auto-format the Computer programming code at web page.</p> 

<p><strong>How to use?</strong></p> 

<p>Just add below line;</p> 

<p><code class="prettyprint"><span style="line-height: 1.6em;">&lt;script src=&quot;https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js&quot;&gt;&lt;/script&gt;</span></code</p> 

<p><span style="line-height: 1.6em;">Then, put the code line in below tab;</span></p> 

<p><code class="prettyprint">&lt;code class=&quot;prettyprint&quot;&gt;...&lt;/code&gt;</code></p> 

<p><span style="color: rgb(0, 0, 0); font-family: monospace; font-size: medium; line-height: normal;">or,</span></p> 

<p>Download the complete code files&nbsp;from&nbsp;<a href="https://code.google.com/p/google-code-prettify/">https://code.google.com/p/google-code-prettify/</a>(even can learn more about prettify)&nbsp;&nbsp;to your server and change above script tag line like below;</p> 

<p><code class="prettyprint">&lt;script src=&quot;path/to/directory/run_prettify.js&quot;&gt;&lt;/script&gt;</code><br />&nbsp;</p> 
</textarea> 
<script>CKEDITOR.replace("editor1");</script> 

但是,在輸出HTML標記代碼丟失。輸出低於(在行下);


我們可以使用prettify在網頁上自動格式化計算機編程代碼。

如何使用?

只需在下面添加行;

然後,將代碼行放在下面的選項卡中;

...

,或者

https://code.google.com/p/google-code-prettify/(even下載完整的代碼文件可以瞭解更多有關美化)到您的服務器,並更改上面的腳本標記線像下面;


期待輸出: expected output 請幫幫忙,我很想念這裏。

+0

您是否做了其他設置?你使用的是哪種版本的CKEditor?你如何創建編輯器?如果您可以提供更多信息,maby我們可以幫助.. – spons 2013-04-23 06:31:41

+0

我正在使用4.0.1.1版本。我沒有使用任何其他設置。在ckeditor設置中,我禁用了幾個按鈕,在'計算機代碼'選項'樣式'中添加屬性'class =「prettyprint」'。 – vips 2013-04-23 06:37:40

回答

0

這看起來像在這個問題上的另一個類似的問題:How to prevent CKEditor from stripping <and> (greater-than/less-than)

的解決方法是使用使用setData設定值。以下是我在4.1樣本中進行的一項測試。

<textarea id="editor1"> 
    <p>foo</p> 
</textarea> 
<script> 
    var txt = '<p>We can use&nbsp;<strong>prettify&nbsp;</strong>to auto-format the Computer programming code at web page.</p><p><strong>How to use?</strong></p><p>Just add below line;</p><p><code class="prettyprint"><span style="line-height: 1.6em;">&lt;script src=&quot;https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js&quot;&gt;&lt;/script&gt;</span></code</p><p><span style="line-height: 1.6em;">Then, put the code line in below tab;</span></p><p><code class="prettyprint">&lt;code class=&quot;prettyprint&quot;&gt;...&lt;/code&gt;</code></p><p><span style="color: rgb(0, 0, 0); font-family: monospace; font-size: medium; line-height: normal;">or,</span></p><p>Download the complete code files&nbsp;from&nbsp;<a href="https://code.google.com/p/google-code-prettify/">https://code.google.com/p/google-code-prettify/</a>(even can learn more about prettify)&nbsp;&nbsp;to your server and change above script tag line like below;</p><p><code class="prettyprint">&lt;script src=&quot;path/to/directory/run_prettify.js&quot;&gt;&lt;/script&gt;</code><br />&nbsp;</p>' 
    CKEDITOR.on('instanceReady', function(ev) { 
     ev.editor.setData(txt); 
    }); 
    CKEDITOR.replace('editor1', { allowedContent: 'p' }); 
</script> 
+1

或更好 - 正確編碼textarea的內容。所有'&' - >'&','<' ->'<'和'>' - >'>'就足夠了。您不需要使用任何解決方法。 – Reinmar 2013-04-23 07:35:07

+0

@Reinmar感謝您的提示!我試過了,我失敗了:)。如果我使用的內容,如

< >酒吧</P >

巴茲

它工作得很好。但是,如果使用

美孚

<腳本>酒吧< /腳本>

巴茲

,它失敗(ACF設置爲TRUE;在兩個測試)。所以它看起來像一些安全功能或過濾器是刪除腳本「標籤」,這就是爲什麼該方法不起作用。或者我只是做了一些錯誤的事情,這也是非常可能的:D – Nenotlep 2013-04-23 07:47:31

+0

哦,是的,OP,只要從那裏刪除「允許的內容」規則,或者將其設置爲任何你需要的東西,我已經將其用於測試目的。 – Nenotlep 2013-04-23 07:47:59