[英]Preferred way of adding custom elements to TinyMCE
I am new to tinyMCE and currently investigating the preferred way of adding custom elements to tinyMCE? 我是tinyMCE的新手,目前正在研究向tinyMCE添加自定义元素的首选方法?
I added a number of buttons to the toolbar, that in turn trigger (a) the insertion of elements for selected parts of text and (b) remove those elements from selected text when clicked on again. 我向工具栏添加了许多按钮,依次触发了(a)为选定的文本部分插入元素,以及(b)再次单击时从选定的文本中删除这些元素。
I do not want to allow nesting for these elements, so basically I just want to markup parts of a sentence or word with a given, non-overlapping, tag, eg: <foo>Hello</foo> world
我不想让这些元素嵌套,所以基本上我只想用给定的,不重叠的标记来标记句子或单词的某些部分,例如:
<foo>Hello</foo> world
For the moment I found these two possibilities in the tinyMCE docs: 目前,我在tinyMCE文档中发现了两种可能性:
#1 tinyMCE.execInstanceCommand(editor_id, command, user_interface, value, focus)
and 和
#2 var n = dom.create(element);
n.innerText = sel.getContent({format : 'text'});
tinyMCE.activeEditor.selection.setNode(n);
where #2 looks like the more flexible approach and hence worth pursuing to me. #2看起来更灵活,因此值得我追求。
I already started implementing a plugin using approach #2, but I am unsure how I would handle stuff like: 我已经开始使用方法2实施插件,但是不确定如何处理以下内容:
<foo>hello</foo> world <bar>!</bar>
<foo>hello</foo> world <bar>!</bar>
<foo>bar</foo><foo>bar</foo>
) or <foo>bar</foo><foo>bar</foo>
)或 This is why I am wondering if I am missing some kind of predefined interface, because lots of these functionalities should as well be needed by the "normal" elements such as strong, em, h1,…,h6
and the like. 这就是为什么我想知道是否缺少某种预定义的接口的原因,因为“普通”元素(例如,
strong, em, h1,…,h6
等)也应该需要许多这些功能。
If you need any more information let me know, any hints or pointers will be appreciated. 如果您需要更多信息,请告诉我,任何提示或指针将不胜感激。
For formatting purposes there is the Formatter.js
class in the tinymce core files. 出于格式化目的,tinymce核心文件中包含
Formatter.js
类。 But what you want is pretty complicated. 但是您想要的是非常复杂的。 We tried to hinder tinymce to nest spans and tweaked
Formatter.js
to our needs. 我们试图阻止tinymce嵌套跨区,并根据需要调整
Formatter.js
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.