从数据库获取的HTML格式的数据被弄乱了

问题描述 投票:0回答:1

我的数据库(新闻稿)中有一些HTML数据,我想在CK编辑器中显示这些数据,但是由于某些原因,CKEditor会“弄乱”这种HTML格式。例如,这是db中原始数据的一部分

<P style="FONT-SIZE: 2pt; MARGIN-BOTTOM: 0pt; MARGIN-TOP: 0pt">
    <SPAN style="FONT-FAMILY: Verdana">&nbsp;</SPAN>
</P>
<DIV style="TEXT-ALIGN: center">
    <TABLE style="WIDTH: 408.8pt; BORDER-COLLAPSE: collapse; MARGIN-LEFT: auto; MARGIN-RIGHT: auto" cellSpacing=0 cellPadding=0>
        <TBODY>

这就是它在CKEditor中的显示方式:-

<p><span style="font-family:Verdana">&nbsp;</span></p>
<div>
    <table cellspacing="0" cellpadding="0" style="width:408.8pt" class=" cke_show_border">
        <tbody>

结果是文本没有居中对齐并且格式也不相同。

所以我想知道,CKEditor是否有任何设置可以使所有内容保持原样而不触动HTML?

我现有的配置如下:-

const GetDefaultConfig = {
    toolbar: [
        { name: 'document', items: ['Save', 'NewPage', 'Preview', 'Print', '-', 'Templates'] },
        { name: 'clipboard', items: ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo'] },
        { name: 'editing', items: ['Find', 'Replace', '-', 'SelectAll', 'Scayt'] },
        { name: 'forms', items: ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'] },
        { name: 'styles', items: ['Styles', 'Format', 'Font', 'FontSize'] },
        { name: 'colors', items: ['TextColor', 'BGColor'] },
        { name: 'tools', items: ['Maximize', 'ShowBlocks'] },
        '/',
        { name: 'basicstyles', items: ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat'] },
        { name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language'] },
        { name: 'links', items: ['Link', 'Unlink', 'Anchor'] },
        { name: 'insert', items: ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe'] }
    ],
    extraPlugins: 'font',
    font_names: 'Arial;Comic Sans MS;Courier New;Georgia;Lucida Sans Unicode;Open Sans Regular;Tahoma;Times New Roman;Trebuchet MS;Verdana;',
    language: 'en', //if ommitted the language of the users' browser is taken
    removeDialogTabs: 'link:advanced;link:target;table:advanced', // Simplify the dialog windows.
    format_tags: 'p;h1;h2;h3;h4', // Set the most common block elements.
    fontSize_sizes: '8/8pt;9/9pt;10/10pt;11/11pt;12/12pt;14/14pt;16/16pt;18/18pt;20/20pt',
    extraAllowedContent: 'div[id, contenteditable]',
    enterMode: 2,
    font_defaultLabel: 'Verdana',
    fontSize_defaultLabel: '9',
    disableNativeSpellChecker: false,
    scayt_autoStartup: true,

    // remove this line below for disabling browser spellcheck
    removePlugins : 'scayt,menubutton,contextmenu,htmldataprocessor',

    // HOW TO USE THE BROWSER SPELLCHECK
    // To use the browser spellcheck, the user has to CTRL+RightClick on an empty space in the text area, so that he can choose the Language he 
    // wants to work with for checking the spelling of his text.
    // To change a word that is wrong (red underlined), CTLR+RightClick on the actual word to get suggestions to change it to a different word 

    scayt_uiTabs : '0,1,0',
};

我想进行某种设置,使所有HTML标记保持原始状态。

有可能吗?

感谢您的帮助和时间

reactjs ckeditor ckeditor4.x
1个回答
0
投票

我通过添加解决了此问题>

allowedContent: true,

到CKEditor的配置。

© www.soinside.com 2019 - 2024. All rights reserved.