Tinymce添加&nbsp

sre*_*moh 6 html javascript tinymce piranha-cms

我尝试覆盖peranhacms中的默认tinymce,如此处建议配置/覆盖Piranha CMS html编辑器,以便不添加html 我花了大约一个小时试图修复该问题.关于这个问题有很多资源,但不能让它发挥作用.

这是我的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(/&nbsp;/ig, " ");
            alert("a1");
        },
        cleanup_callback: 'my_cleanup_callback',
    });
    function my_cleanup_callback(type, value) {
        alert("a2");
        switch (type) {
            case 'get_from_editor':
                // Remove &nbsp; characters
                value = value.replace(/&nbsp;/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>
Run Code Online (Sandbox Code Playgroud)

这是我用来粘贴到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>
Run Code Online (Sandbox Code Playgroud)

它是如何在浏览器源中查找: 在此输入图像描述

我把警报,以检查是否paste_postprocessmy_cleanup_callback实际射击,但他们不是.我仍然在html中.

我试图设置cleanup: true,paste_auto_cleanup_on_paste: true但它没有帮助解雇paste_postprocessmy_cleanup_callback

你会如何解决这个问题?

Din*_*amy 6

刚添加entity_encoding: 'raw'解决了问题.


小智 2

TinyMCE 是一个怪物般的选项和设置,但考虑到您提供的链接以及您使用 TinyMCE 的清理方法,在使用单词“粘贴”时添加   而不是空格,您是否尝试过设置:

\n\n
paste_auto_cleanup_on_paste: true\n
Run Code Online (Sandbox Code Playgroud)\n\n

由于这是在您引用的示例中设置的。除了这个猜测之外,我不知道为什么该事件没有触发。

\n\n

此致

\n\n

H\xc3\xa5kan

\n