javascript - Tinymce 添加 &nbsp

标签 javascript html tinymce piranha-cms

我正在尝试按照此处的建议覆盖 peranhacms 中的默认 tinymce Configure / override Piranha CMS html editor so as not to add &nbsp's to 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>

这是我用来粘贴到 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>

它是它在浏览器源代码中的样子: enter image description here

我发出警报以检查 paste_postprocessmy_cleanup_callback 是否实际触发,但它们没有触发。我在 html 中仍然有  。

我试图设置 cleanup: truepaste_auto_cleanup_on_paste: true 但它没有帮助触发 paste_postprocessmy_cleanup_callback

您将如何解决   问题?

最佳答案

只需添加 entity_encoding: 'raw' 即可解决问题。

关于javascript - Tinymce 添加 &nbsp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27791824/

相关文章:

javascript - 对来自第三方控件的事件使用react,更新状态

javascript - HTML 表单提交至 Google 日历 : Uncaught TypeError, 由于属性值非法而失败:1

html - 使用 bootstrap 在悬停时边框到 div 的边缘

html - CSS float 空格

javascript - 带分页演示的无限滚动

javascript - 根据 X/Y 位置更改鼠标光标

JavaScript 输出到文件

asp.net-mvc-3 - 在 MVC3 应用程序中获取 TinyMCE 下拉图像列表

tinymce - 在 PHP 站点的 TinyMCE 内容编辑器中插入和显示图像

wordpress - 如何彻底删除Wordpress中的TinyMCE?