本文整理汇总了TypeScript中tinymce/core/api/Settings.getForcedRootBlock函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getForcedRootBlock函数的具体用法?TypeScript getForcedRootBlock怎么用?TypeScript getForcedRootBlock使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getForcedRootBlock函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
const setContentString = (editor: Editor, body: HTMLElement, content: string, args: SetContentArgs): string => {
let forcedRootBlockName, padd;
// Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
// It will also be impossible to place the caret in the editor unless there is a BR element present
if (content.length === 0 || /^\s+$/.test(content)) {
padd = '<br data-mce-bogus="1">';
// Todo: There is a lot more root elements that need special padding
// so separate this and add all of them at some point.
if (body.nodeName === 'TABLE') {
content = '<tr><td>' + padd + '</td></tr>';
} else if (/^(UL|OL)$/.test(body.nodeName)) {
content = '<li>' + padd + '</li>';
}
forcedRootBlockName = Settings.getForcedRootBlock(editor);
// Check if forcedRootBlock is configured and that the block is a valid child of the body
if (forcedRootBlockName && editor.schema.isValidChild(body.nodeName.toLowerCase(), forcedRootBlockName.toLowerCase())) {
content = padd;
content = editor.dom.createHTML(forcedRootBlockName, editor.settings.forced_root_block_attrs, content);
} else if (!content) {
// We need to add a BR when forced_root_block is disabled on non IE browsers to place the caret
content = '<br data-mce-bogus="1">';
}
editor.dom.setHTML(body, content);
editor.fire('SetContent', args);
} else {
if (args.format !== 'raw') {
content = Serializer({
validate: editor.validate
}, editor.schema).serialize(
editor.parser.parse(content, { isRootContent: true, insert: true })
);
}
args.content = Tools.trim(content);
editor.dom.setHTML(body, args.content);
if (!args.no_events) {
editor.fire('SetContent', args);
}
}
return args.content as string;
};
示例2: moveToRange
const renderBlock = (down: boolean, editor: Editor, table: HTMLElement, pos: CaretPosition) => {
const forcedRootBlock = Settings.getForcedRootBlock(editor);
if (forcedRootBlock) {
editor.undoManager.transact(() => {
const element = SugarElement.fromTag(forcedRootBlock);
Attr.setAll(element, Settings.getForcedRootBlockAttrs(editor));
Insert.append(element, SugarElement.fromTag('br'));
if (down) {
Insert.after(SugarElement.fromDom(table), element);
} else {
Insert.before(SugarElement.fromDom(table), element);
}
const rng = editor.dom.createRng();
rng.setStart(element.dom(), 0);
rng.setEnd(element.dom(), 0);
moveToRange(editor, rng);
});
} else {
moveToRange(editor, pos.toRange());
}
};
示例3: RegExp
const trimEmptyContents = (editor: Editor, html: string): string => {
const blockName = Settings.getForcedRootBlock(editor);
const emptyRegExp = new RegExp(`^(<${blockName}[^>]*>( | |\\s|\u00a0|<br \\/>|)<\\/${blockName}>[\r\n]*|<br \\/>[\r\n]*)$`);
return html.replace(emptyRegExp, '');
};