我正在尝试覆盖 peranhacms 中的默认tinymce,就像这里建议的那样配置/覆盖 Piranha CMS html 编辑器,以免将 's 添加到 html 我已经花了大约一个小时试图解决这个问题。关于这个问题有很多资源,但不能让它工作。
- https://wordpress.org/support/topic/correct-way-to-allow-nbsp-entity-in-tinymce
- tinyMCE 自动添加 p 标签和 nbsp
- http://blog.room34.com/archives/5075
- TinyMCE 在使用 paste 一词时添加 而不是空格
这是我的 tinymce.init 的样子。
<script type="text/javascript" src="~/res.ashx/areas/manager/content/js/ext/tiny_mce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
mode: 'specific_textareas',
editor_selector: "editor",
apply_source_formatting: false,
cleanup_on_startup: false,
trim_span_elements: false,
cleanup: false,
convert_urls: false,
force_br_newlines: true,
force_p_newlines: false,
remove_linebreaks: false,
convert_newlines_to_brs: false,
forced_root_block: '',
inline_styles : true,
entity_encoding: 'raw',
verify_html: false,
//forced_root_block: false,
validate_children: false,
remove_redundant_brs: false,
fix_table_elements: false,
entities: '160,nbsp,38,amp,60,lt,62,gt',
plugins: [
"autoresize autolink code hr paste piranhaimage link"
],
width: "100%",
height: "340",
autoresize_min_height: 340,
@if (File.Exists(Server.MapPath("~/areas/manager/content/css/editor.css"))) {
<text>content_css: "@Url.Content("~/areas/manager/content/css/editor.css")",</text>
}
toolbar: "bold italic underline | bullist numlist hr | formatselect removeformat | cut copy paste | link piranhaimage | code",
paste_auto_cleanup_on_paste: false,
paste_postprocess: function (pl, o) {
// remove extra line breaks
o.node.innerHTML = o.node.innerHTML.replace(/ /ig, " ");
alert("a1");
},
cleanup_callback: 'my_cleanup_callback',
});
function my_cleanup_callback(type, value) {
alert("a2");
switch (type) {
case 'get_from_editor':
// Remove characters
value = value.replace(/ /ig, ' ');
alert("a3");
break;
case 'insert_to_editor':
case 'submit_content':
case 'get_from_editor_dom':
case 'insert_to_editor_dom':
case 'setup_content_dom':
case 'submit_content_dom':
default:
break;
}
return value;
}
</script>
这是我用来粘贴到 tinyice textarea 的 html 示例
<div class="catelog-box">
<img src="images/dance.png" alt="dine">
<div class="cat-detail">
<h2>Dance</h2>
<p>Dis purus arcu etiam auctor risus aliquam mid turpis eu vel, nunc rhoncus lacus natoque ridiculus...</p>
</div>
</div>
这就是它在浏览器源代码中的样子:
我发出警报以检查是否paste_postprocess
并my_cleanup_callback
实际触发,但事实并非如此。而且我仍然在 html 中有 。
我试图设置cleanup: true
,paste_auto_cleanup_on_paste: true
但它没有帮助开火paste_postprocess
和my_cleanup_callback
您将如何解决 问题?