70

CKEditor 3.x で <p></p> 内のすべての書き込みコンテンツの自動封入をオフにする可能性はありますか?

私は試した

  CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;

しかし、これはインライン改行を <br /> に変更するだけで、囲んでいる段落を残します。

現在「テスト」を書いていると、この出力が生成されます

<p>
    Test</p>

しかし、私はそれが単純であることを望みます

Test

このための構成プロパティはありますか、それとも別のインライン エディターの方が適しているでしょうか?

4

12 に答える 12

99

CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;-これは私にとって完璧に機能します。ブラウザのキャッシュをクリアしてみましたか?これは時々問題になります。
jQueryアダプターを使用してチェックアウトすることもできます。

<script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/js/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript">
$(function() {
    $('#your_textarea').ckeditor({
        toolbar: 'Full',
        enterMode : CKEDITOR.ENTER_BR,
        shiftEnterMode: CKEDITOR.ENTER_P
    });
});
</script>


@Tomkayのコメントによる更新:

CKEditorのバージョン3.6以降、インラインコンテンツをのようなタグで自動的にラップするかどうかを設定できます<p></p>。これは正しい設定です:

CKEDITOR.config.autoParagraph = false;

ソース: http ://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.autoParagraph

于 2010-04-21T15:10:56.500 に答える
34

Across the internet, people have noticed that setting config.enterMode to CKEDITOR.ENTER_BR removes the wrapping paragraph tags from CKEditor. It's worth noting that the setting changes the behavior of the enter key to insert line breaks rather than paragraphs, which is not desirable.

See: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.enterMode "It is recommended to use the CKEDITOR.ENTER_P setting because of its semantic value and correctness."

However, the setting that is designed to remove that initial paragraph, config.autoParagraph, isn't advisable either, as it introduces "unpredictable usability issues" because the editor really wants a top-level block element.

See: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.autoParagraph

The magic happens on wysiwygarea/plugin.js, line 410, where the editor selects the default block element based on config.enterMode. A config option to change the default block element would allow us to start with a div, but we'd continue getting more divs with every enter press, unless we changed the paragraph format via the menu.

See: http://docs.cksource.com/ckeditor_api/symbols/src/plugins_wysiwygarea_plugin.js.html

It would be possible to remove the wrapping paragraph tag with post-processing (either on the server or in CKEditor's getData event), but that leads us into the same problem as disabling autoParagraph: there's no top-level block.

I would rather say that there's not a good solution, but rather a handful of half-solutions, than to accept changing config.enterMode as the canonical solution.

于 2012-01-06T16:57:54.900 に答える
9

これをconfig.jsで試してください

CKEDITOR.editorConfig = function( config )
{
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_BR;
};
于 2011-03-07T13:51:39.710 に答える
5

それを見つけた!

ckeditor.js の 91 行目 ... 検索

B.config.enterMode==3?'div':'p'

への変更

B.config.enterMode==3?'div':''(いいえP!)

キャッシュと BAM をダンプしてください!

于 2011-01-07T23:42:40.210 に答える
2

私は回避策として誇りに思っていないことをしています。実際にデータベースに保存する Python サーブレットでは、次のようにします。

if description.startswith('<p>') and description.endswith('</p>'):
    description = description[3:-4]
于 2010-03-05T22:53:53.103 に答える
1

これをあなたのconfig.jsファイルコードにしてください

CKEDITOR.editorConfig = function( config ) {

   //   config.enterMode = 2; //disabled <p> completely
        config.enterMode = CKEDITOR.ENTER_BR // pressing the ENTER KEY input <br/>
        config.shiftEnterMode = CKEDITOR.ENTER_P; //pressing the SHIFT + ENTER KEYS input <p>
        config.autoParagraph = false; // stops automatic insertion of <p> on focus
    };
于 2015-04-28T02:36:04.710 に答える
1

ソースを編集して (またはリッチ テキストをオフにして)、p タグを div に置き換えます。次に、必要に応じて div のスタイルを設定します。

そこにdivがあるため、ckEditorは次の送信時にラッパー要素を追加しません。

(これで問題は解決しました。私は Drupal を使用しており、エディターが常に余分に追加した html の小さなスニペットが必要ですが、残りの時間はラッピング p タグが必要です)。

于 2012-12-13T12:07:35.153 に答える
1
if (substr_count($this->content,'<p>') == 1)
{
  $this->content = preg_replace('/<\/?p>/i', '', $this->content);
}
于 2010-06-16T15:36:05.120 に答える