粘贴到KendoUI编辑器时,如何从文本中删除所有html格式?

时间:2013-03-24 23:03:09

标签: kendo-ui kendo-asp.net-mvc

我想使用KendoUI编辑器基本上只允许用户将文本格式化为段落。可能允许加粗和下划线。

我正在努力解决两件事:

  1. 我想在粘贴
  2. 时从文本中删除所有html格式
  3. 我想禁用粗体,下划线等键盘快捷键 - 即使工具栏元素不存在,它们似乎也能正常工作。
  4. 谢谢!

4 个答案:

答案 0 :(得分:8)

对于粘贴唯一的文本,您可以定义一个粘贴处理程序,删除除文本之外的所有内容。这很简单:

$("#editor").kendoEditor({
    paste: function (ev) {
        ev.html = $(ev.html).text();
    }
});

paste处理程序接收一个事件,该事件在html中被解析的文本。我们可以使用jQuery仅使用$(ev.html).text()

获取文本

要删除快捷方式,并且我可以使用最新的Kendo UI版本进行测试,如果只定义所需的工具,则只有那些快捷方式处于活动状态。所以,如果你说的话:

$("#editor").kendoEditor({
    tools: [
        "italic"
    ],
    paste: function (ev) {
        ev.html = $(ev.html).text();
    }
});

只有italic个快捷方式<ctrl>+i可用。如果您将tools数组保留为空,则表示您没有任何数据。

答案 1 :(得分:1)

现在可以使用for /L %%j in (1,1,%n%) do ( :: subproject dir, relative to the sandobox dir call set SUBPROJECT_DIR=%%ADRESS_ARRAY[%%j]%% :: sandbox name call set SANDBOX_NAME=C:\%SANDBOX_FOLDER_NAME%\%%SUBPROJECT_DIR%%\project.pj :: name of sandbox folder call set SANDBOX_DIR=C:\%SANDBOX_FOLDER_NAME%\%%SUBPROJECT_DIR%% :: name of presentation to be copied call set PRESENTATION_NAME=%%NAME_ARRAY[%%j]%% :: check out file call si co --sandbox=%%SANDBOX_NAME%% --changePackageId=:none --hostname=%SERVERNAME% --port=%PORTNAME% %%SANDBOX_DIR%%\%%PRESENTATION_NAME%% :: Copying new files (Option /xo of robocopy) call robocopy x: %%SANDBOX_DIR%% %%PRESENTATION_NAME%% :: check in modified file call si ci --sandbox=%%SANDBOX_NAME%% --changePackageId=:none --hostname=%SERVERNAME% --port=%PORTNAME% --description="Automated weekly update." %%SANDBOX_DIR%%\%%PRESENTATION_NAME%% ) 选项轻松实现此目的。

见这里:http://docs.telerik.com/kendo-ui/controls/editors/editor/pasting

答案 2 :(得分:0)

Kendo MVC也为此目的进行了扩展。用法示例:

.PasteCleanup(x => x.KeepNewLines(false))

false在这种情况下意味着您要清除除换行以外的所有内容。

答案 3 :(得分:0)

对我来说这是完整的解决方案

                pasteCleanup: {
                custom: function (html)
                {
                    html = html.replace(/<\s*br\/*>/gi, '');
                    html = html.replace(/<\s*a.*href="(.*?)".*>(.*?)<\/a>/gi, " $2 (Link - $1) ");
                    html = html.replace(/<\s*\/*.+?>/ig, '');
                    html = html.replace(/ {2,}/gi, '');
                    html = html.replace(/\n+\s*/gi, '');
                    html = html.replace("&nbsp;", '');
                    html = html.replace(/&lt;.*?&gt;/g, '');
                    return html;
                }
            }