关闭封闭的

CKEditor 3.0 中的标签

发布于 2024-08-16 17:55:14 字数 338 浏览 3 评论 0原文

是否可以关闭

中所有书面内容的自动封装?在 CKEditor 3.x 中?

我尝试过

  CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;

,但这只是将内联换行符更改为
同时留下所附段落。

目前编写“测试”会产生此输出

<p>
    Test</p>

,但我希望它只是简单的

Test

是否有配置属性,或者另一个内联编辑器更适合此输出?

Is there a possibility to turn off the automatic enclosing of all written content within <p></p> in CKEditor 3.x?

I tried

  CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;

but this just changes the inline linebreaks to <br /> while leaving the enclosing paragraph.

Currently writing "Test" produces this output

<p>
    Test</p>

but I want it to be simply

Test

Is there a configuration property for this or would another inline editor to be better suited for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

滥情哥ㄟ 2024-08-23 17:55:15

{{ 博客.描述 | safe }} 只要使用 safe 它就会删除不需要的东西。

{{ blog.description | safe }} just use safe it will remove un-necessary things.

写下不归期 2024-08-23 17:55:15

在 VS2015 中,这可以将 Enter 键变成

myCKEControl.EnterMode = CKEditor.NET.EnterMode.BR

就我个人而言,我不在乎我的结果文本是否只有
而不是

。它渲染得非常好,而且看起来就像我想要的那样。最后,它起作用了。

In VS2015, this worked to turn the Enter key into <br>

myCKEControl.EnterMode = CKEditor.NET.EnterMode.BR

Personally, I don't care if my resulting text only has <br> and not <p>. It renders perfectly fine and it looks the way I want it to. In the end, it works.

自在安然 2024-08-23 17:55:14

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 版本开始,您可以配置是否希望内联内容自动使用

等标签进行包装。这是正确的设置:

CKEDITOR.config.autoParagraph = false;

来源:
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR。 config.html#.autoParagraph

CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR; - this works perfectly for me.
Have you tried clearing your browser cache - this is an issue sometimes.
You can also check it out with the jQuery adapter:

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

UPDATE according to @Tomkay's comment:

Since version 3.6 of CKEditor you can configure if you want inline content to be automatically wrapped with tags like <p></p>. This is the correct setting:

CKEDITOR.config.autoParagraph = false;

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

青朷 2024-08-23 17:55:14

在互联网上,人们注意到将 config.enterMode 设置为 CKEDITOR.ENTER_BR 会从 CKEditor 中删除换行段落标签。值得注意的是,该设置更改了回车键的行为以插入换行符而不是段落,这是不可取的。

请参阅:http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html #.enterMode “由于其语义价值和正确性,建议使用 CKEDITOR.ENTER_P 设置。”

然而,旨在删除初始段落 config.autoParagraph 的设置也不可取,因为它引入了“不可预测的可用性问题”,因为编辑器确实想要一个顶级块元素。

请参阅:http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html #.autoParagraph

神奇的事情发生在 wysiwygarea/plugin.js 的第 410 行,编辑器根据 config.enterMode 选择默认的块元素。更改默认块元素的配置选项将允许我们从 div 开始,但每次按下 Enter 键我们都会继续获得更多 div,除非我们通过菜单更改段落格式。

请参阅:http://docs.cksource.com/ckeditor_api/symbols/src/plugins_wysiwygarea_plugin.js。 html

可以通过后处理(在服务器上或在 CKEditor 的 getData 事件中)删除换行段落标记,但这会导致我们遇到与禁用 autoParagraph 相同的问题:没有顶级块。

我宁愿说没有一个好的解决方案,而是一些半解决方案,而不是接受更改 config.enterMode 作为规范解决方案。

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.

卖梦商人 2024-08-23 17:55:14

在 config.js 中尝试一下

CKEDITOR.editorConfig = function( config )
{
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_BR;
};

Try this in config.js

CKEDITOR.editorConfig = function( config )
{
config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_BR;
};
剧终人散尽 2024-08-23 17:55:14

找到了!

ckeditor.js 第 #91 行 ... 搜索

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

更改为

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

转储你的缓存然后砰!

Found it!

ckeditor.js line #91 ... search for

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

change to

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

Dump your cache and BAM!

愁以何悠 2024-08-23 17:55:14

将此作为您的 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
    };

MAKE THIS YOUR config.js file code

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
    };
耶耶耶 2024-08-23 17:55:14

我正在做一些我并不自豪的解决方法。在实际保存到数据库的 Python servlet 中,我执行以下操作:

if description.startswith('<p>') and description.endswith('</p>'):
    description = description[3:-4]

I'm doing something I'm not proud of as workaround. In my Python servlet that actually saves to the database, I do:

if description.startswith('<p>') and description.endswith('</p>'):
    description = description[3:-4]
夏了南城 2024-08-23 17:55:14

编辑源(或关闭富文本)并将 p 标签替换为 div。然后按照您想要的方式设置 div 的样式。

ckEditor 不会在下一次提交时添加任何包装元素,因为您已经在其中添加了 div。

(这解决了我的问题,我正在使用 Drupal 并且需要 html 的小片段,编辑器总是添加额外的内容,但其余时间我想要包装 p 标签)。

Edit the source (or turn off rich text) and replace the p tag with a div. Then style the div any which way you want.

ckEditor won't add any wrapper element on the next submit as you've got the div in there.

(This solved my issue, I'm using Drupal and need small snippets of html which the editor always added the extra, but the rest of the time I want the wrapping p tag).

伪装你 2024-08-23 17:55:14
if (substr_count($this->content,'<p>') == 1)
{
  $this->content = preg_replace('/<\/?p>/i', '', $this->content);
}
if (substr_count($this->content,'<p>') == 1)
{
  $this->content = preg_replace('/<\/?p>/i', '', $this->content);
}
榕城若虚 2024-08-23 17:55:14

将此作为您的 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
    };

MAKE THIS YOUR config.js file code

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
    };
云淡风轻 2024-08-23 17:55:14

设置这样的配置:

    CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR
    CKEDITOR.config.forcePasteAsPlainText = true

Set such config:

    CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR
    CKEDITOR.config.forcePasteAsPlainText = true
荒人说梦 2024-08-23 17:55:14

好吧,在 laravel 中,使用 ckeditor,它使用简单的 strip_tags($var) 函数进行输出,如下所示:

将值发送到其他页面:{!! strip_tags($six_answer) !!}

和/或输出时使用相同的代码:{!! strip_tags($six_answer)!!}

结果如下,没有任何

标签。
输入图片此处描述

Well, with me in laravel, with using ckeditor, it work using simple strip_tags($var) function for output like below:

Sending value to like this to the other page: {!! strip_tags($six_answer) !!}

And/Or when outputting use the same code: {!! strip_tags($six_answer) !!}.

the result is below without any <p> tags.
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文