从TinyMCE编辑器获取特定内容

Getting specific content from TinyMCE editor

本文关键字:获取 TinyMCE 编辑器      更新时间:2023-09-26

我有一个插件我正在建设的wordpress,注入短代码与内容里面的用户选择该插件的选项后。我遇到的麻烦是tinyMCE.get('content').getContent(),这是当用户想要更新这些选项时调用的,但使用这个拉一切那是在时间,我需要它限制在短代码打开和关闭标签内的内容。例如:在用户选择插件的选项后,将创建[plugin]---HTML OPTIONS---[/plugin]的短代码,但是当tinyMCE.get('content').getContent()被调用时,我需要它来抓取所述插件标签内的所有内容,而不是像这样:[plugin]---GET THIS CODE----[/plugin]任何帮助都将不胜感激。

如果我明白你在尝试什么,那么你正在寻找的是选择类(doc)

更具体地说:

// Sets some contents to the current selection in the editor
tinymce.activeEditor.selection.setContent('Some contents');
// Gets the current selection
alert(tinymce.activeEditor.selection.getContent());

您可以查看一些可用插件中的代码。链接插件特别适用于文本选择。