开始输入时,TinyMCE 编辑器会将所有
替换为常规空格。我想阻止 html 实体转换。它会在每次按键时转换实体。
我已经尝试过
entity_encoding: "named",
entities: '160,nbsp,38,amp,60,lt,62,gt'
和
entity_encoding: "named",
entities: ' '
还有什么事情要做吗? 这是我的 TinyMCE 初始化,
tinymce.init({
selector: selector,
apply_source_formatting:true,
entity_encoding: "named",
entities: '160,nbsp,38,amp,60,lt,62,gt',
force_p_newlines: force_p,
forced_root_block: forced_root,
valid_elements: "*[*]",
invalid_elements: invalid_elms,
valid_children: "+span[div],+th[input]",
extended_valid_elements: "sc[id],dd[*],dt[*],monospace[*],input[*]",
custom_elements: "~sc,~monospace,~input",
table_toolbar: "",
menubar: false,
save_enablewhendirty: false,
toolbar1: toolbar_icons,
plugins: [plugins_str],
inline: true,
formats: format_array_new,
resize: true,
toolbar_sticky: true,
contextmenu: false,
remove_script_host: false,
skin_url: this._global.tinymceUrl + "/skins/ui/oxide",
autofocus: true,
fixed_toolbar_container: "#editor-toolbar",
draggable_modal: true,
paste_auto_cleanup_on_paste: true,
paste_remove_spans: true,
paste_remove_styles: true,
paste_text_sticky: true,
paste_strip_class_attributes: "all",
paste_retain_style_properties: "",
paste_as_text: true,
});
最佳答案
TinyMCE 在处理包含任何类型的多个空格的字符串时,将(无论配置设置如何)混合使用硬空格 (
) 和常规空格。
例如,如果您输入一个字母,按空格键 5 次,然后输入另一个字母 TinyMCE,最终会出现如下内容:
a b
这样做有几个原因:
- 它允许人们以与在文字处理程序中可能执行的操作一致的方式在内容中插入空格
- 交替使用硬空格和常规空格可以让内容包裹在其包含元素内。一长串硬空格通常会导致内容脱离其包含的元素,并且典型的内容作者不会理解该句子或如何解决该问题。
当 TinyMCE 序列化器运行时,此空间管理是进程的一部分,您无法禁用它。
您可以做的就是包裹您不想修改的硬空间。如果您加载 Non Breaking Space TinyMCE 插件,则会有一个用于此功能的配置选项:
https://www.tiny.cloud/docs/plugins/nonbreaking/#nonbreaking_wrap
由于当您加载不间断空间插件时,默认情况下此功能处于“打开”状态,因此您将看到,如果您使用菜单插入/不间断空间,您会得到如下所示的内容:
<span class="mce-nbsp-wrap" contenteditable="false"> </span>
除了具有适当类的跨度之外,没有任何“魔法”。如果您以这种方式包装任何想要维护的硬空间,TinyMCE 将不会在空间管理过程中修改该空间。
关于javascript - 防止 TinyMCE 替换为常规空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61221847/