简体   繁体   English

CKEditor:如何在DIV中强制P?

[英]CKEditor: how to force P within DIV?

In the CMS I'm working on, I need to insert some custom HTML (which works): 在我正在使用的CMS中,我需要插入一些自定义HTML(有效):

var element = CKEDITOR.dom.element.createFromHtml("<div class='sidebar'>Edit Sidebar Text</div>");

The problem is that when editing what's inside the sidebar element, pressing ENTER duplicates the sidebar DIV instead of adding a P tag within the sidebar. 问题是,在编辑侧边栏元素中的内容时,按Enter键将复制侧边栏DIV,而不是在侧边栏中添加P标签。 How do I tell the editor to use a paragraph instead? 如何告诉编辑器改用段落?

I expect this: 我期望这样:

<div class="sidebar">
    Enter sidebar text
<p></p>
</div>

and get this: 并得到这个:

<div class="sidebar">
    Enter sidebar text</div>
<div class="sidebar">
    &nbsp;</div>

I have not made any changes to "entermode" settings. 我尚未对“进入模式”设置进行任何更改。

您几乎猜中了首选项的名称: http : //docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.forceEnterMode (是的,我认为此设置应默认为true,但至少选项设置)

In addition to Alfonso's post, the second thing you need to do is insert your own paragraph as part of the wrapping element. 除了Alfonso的帖子之外,您需要做的第二件事是在包装元素中插入自己的段落。 That way CK will create a plain <p> tag inside the wrapper instead of <p class="sidebar"> . 这样,CK将在包装器内创建一个普通的<p>标记,而不是<p class="sidebar">

var element = CKEDITOR.dom.element.createFromHtml("<div class='sidebar'><p>Edit Sidebar Text</p></div>");

Found this clue from here: http://ckeditor.com/forums/CKEditor-3.x/inside 从这里找到了这个线索: http : //ckeditor.com/forums/CKEditor-3.x/inside

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM