我们使用Tinymce 4.x进行文本格式化。生成的输出HTML字符串不包含默认文本的font-family。在这种情况下,输出HTML是
这是一个文字字符串
但是,如果我们从下拉列表中选择不同的字体系列,它会在html span元素中加起来。输出字符串看起来像
这是一个文本字符串
我们需要输出HTML字符串中输入文本的默认字体系列。我们已经做了很多研究但是找不到有效的解决方案帮助。感谢是否有人可以提供帮助。
当前代码
tinyMCE.init({
// General options
mode: "textareas",
height: "167",
directionality: 'rtl',
selector: '#mytextarea',
convert_fonts_to_spans : false,
body_class: 'arn_richclass',
statusbar: false,
theme: "modern",
plugins: "link textcolor lists directionality",
removed_menuitems: "newdocument visualaid",
toolbar: "bold italic underline forecolor bullist link",
menu: {
edit: { title: 'Edit', items: 'undo redo | cut copy paste pastetext | selectall' },
format: { title: 'Format', items: 'bold italic underline | formats' }
}
});
答案 0 :(得分:1)
默认情况下,TinyMCE将使用提供给编辑器的CSS来控制内容的外观 - 这将包括默认字体,大小,颜色等。
如果你想在内容中的根块上使用某种内联样式,你需要自己添加它们 - 我不知道任何HTML编辑器会默认添加它们,因为它会破坏整个通过CSS控制内容的外观。
也许您可以使用forced_root_block
和forced_root_block_attrs
在根块上设置某种样式属性?
https://www.tinymce.com/docs/configure/content-filtering/#forced_root_block https://www.tinymce.com/docs/configure/content-filtering/#forced_root_block_attrs
您的配置中包含以下内容:
forced_root_block : 'p',
forced_root_block_attrs: {
'class': 'myclass',
'style': 'font-family: arial times sans-serif; font-weight: bold;'
}
每当编辑器插入新的根块时,它将获得类和内联样式。