Sitecore:RTE粘贴为纯文本自定义

时间:2015-09-09 05:51:57

标签: sitecore rte sitecore8

我正在尝试使用RTE按钮,发现从单词粘贴到RTE的副本允许所有样式保持不变。所以我读了post并删除了额外的格式。现在我想处理空格和换行符。所以,通过一些分析我决定允许:

单行中断的一个空格。语句显示为单个段落。例如

    "This is new. </br> This is weird." should become "<p>This is new. &nbsp;This is weird.</p>"

如果找到多个换行符,则所有中断分隔语句应该作为单个段落,它们之间只有一个中断。例如

    "This is new. </br></br></br> This is weird." should become "<p>This is new.</p> </br> <p>This is weird.</p>"

对于以前需要在粘贴后调整整个废料的作者来说,这将非常有效。

我已尝试使用“粘贴为纯文本”按钮,但它不会处理换行符。所以我想知道如何自定义按钮功能以根据我的需要进行调整?我应该在哪里以及如何做到这一点??

2 个答案:

答案 0 :(得分:1)

在web.config文件中,您可以更改和更新HTMLEditor设置。
但是,您可能在HTML编辑器中有不同的方面和动态用户输入。所以,我建议您在Core DB中创建一个自定义的RichText Editor,如果需要,还可以在程序集中创建。然后,在App_include文件夹中创建另一个配置文件以修补并添加具有不同设置的自定义HTML编辑器。

以下是来自web.config文件,如果你想继续使用默认的RichText Editor,你可以更新这个配置。

<!--  HTML EDITOR DEFAULT CONFIGURATION TYPE 
    Specifies the type responsible for setting up the rich text editor. Can be overriden at profile level. Must inherit from 
    Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration,Sitecore.Client.
    Default value: Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration,Sitecore.Client
-->
    <setting name="HtmlEditor.DefaultConfigurationType" value="Sitecore.Shell.Controls.RichTextEditor.EditorConfiguration,Sitecore.Client" />
<!--  HTML EDITOR DEFAULT PROFILE
Path to the default html editor profile.
Default value: /sitecore/system/Settings/Html Editor Profiles/Rich Text Default
-->
    <setting name="HtmlEditor.DefaultProfile" value="/sitecore/system/Settings/Html Editor Profiles/Rich Text Default" />
<!--  HTML EDITOR LINE BREAK
Specifies the tag that the HTML editor inserts on Enter. Values can be
"br", "div" and "p".
-->
    <setting name="HtmlEditor.LineBreak" value="p" />
<!--  HTML EDITOR REMOVE SCRIPTS
If true, the rich text editor removes script tags from RTE field values before saving. Setting the value to true reduces the potential for cross-site scripting and other script-related issues.
Default value: true
-->
    <setting name="HtmlEditor.RemoveScripts" value="true" />
<!--  HTML EDITOR SUPPORT WEB CONTROLS
Indicates if the Html Editor supports web controls. If true, Web Controls are shown as yellow boxes.
Default value: true
-->
    <setting name="HtmlEditor.SupportWebControls" value="true" />
<!--  HTML EDITOR VALIDATOR SERVICE URL
Specifies the url that validates XHtml.
-->
    <setting name="HtmlEditor.ValidatorServiceUrl" value="http://validator.w3.org/check" />

答案 1 :(得分:0)

您必须在Javascript中进行此更改...当您处于创作模式以捕获粘贴事件并在javascript中执行HTML操作时,您可以使用自定义JS ... 在ContentTree中也可以使用的另一个选项是在RTE中添加一个调用此javascript的按钮,在这里您可以找到有关如何将按钮添加到RTE的一些说明。 https://markstiles.net/Blog/2011/02/05/adding-button-to-rich-text-editor.aspx