HTML format of data retreived from the database is messed up - reactjs

I have some HTML data in my database (newsletter) which I would like to display inside the CK Editor, however for some reason, the CKEditor is "messing" up the format of this HTML. For example, this is part of the original data in the db
<P style="FONT-SIZE: 2pt; MARGIN-BOTTOM: 0pt; MARGIN-TOP: 0pt">
<SPAN style="FONT-FAMILY: Verdana"> </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>
and this is how it is displayed inside the CKEditor :-
<p><span style="font-family:Verdana"> </span></p>
<div>
<table cellspacing="0" cellpadding="0" style="width:408.8pt" class=" cke_show_border">
<tbody>
with the result that the text is not centre aligned and also not the same format.
So I was wondering, is there any setting for the CKEditor that leaves everything as it is without touching the HTML?
My exisiting config is as follows:-
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',
};
I would like to have some kind of setting that leaves all the HTML tags as they are originally.
Is it possible?
Thanks for your help and time

I solved this by adding
allowedContent: true,
to the config of the CKEditor.

Related

Some features of react-quill don't work in production

I have a Next app and Text Editor using react-quill. In localhost everything works well, but when I got my project in vercel some features of react-quill don't work, like fontSize, color of font, align and so on.
`
import { Box } from '#chakra-ui/react';
import dynamic from 'next/dynamic';
import 'react-quill/dist/quill.snow.css';
const QuillNoSSRWrapper = dynamic(import('react-quill'), {
ssr: false,
loading: () => <p>Loading ...</p>,
});
const modules = {
toolbar: [
[{ header: '1' }, { header: '2' }, 'code-block'],
[{ size: [] }],
[{ script: 'super' }, { script: 'sub' }],
[{ color: [] }, { background: [] }],
['bold', 'italic', 'underline', 'strike', 'blockquote'],
[
'direction',
{ align: [] },
{ list: 'ordered' },
{ list: 'bullet' },
{ indent: '-1' },
{ indent: '+1' },
],
['link', 'image', 'video'],
['clean'],
],
};
const formats = [
'header',
'font',
'size',
'bold',
'italic',
'underline',
'strike',
'blockquote',
'list',
'bullet',
'indent',
'link',
'image',
'video',
'code-block',
'align',
'direction',
'color',
'background',
'script',
'super',
'sub',
];
const TextEditor = ({ setContentValue, value }: any) => {
return (
<QuillNoSSRWrapper
bounds={'.app'}
modules={modules}
formats={formats}
onChange={setContentValue}
placeholder="Write your post here. You can edit your text by tools above"
value={value}
theme="snow"
/>
);
};
export default TextEditor;
`
Here my code of TextEditor
Do you have any ideas about this?
I tried to use Text Editor react-quill that works well in development, but it doesn't work in vercel
Check if your next.config.ts has swcMinify: true. Removing this in my project helped.
More info here: ReactJs quill editor add color to text not working for deployed app

how to change the dropdown text in Quill?

i can change the value of the text but am unable to change the text on the drop down of the ngx-quill
i tried both ways the ts way and the creation of a new container still doesn't fix my issue. went through the doc and still was unable to find a suitable solution to this problem.As the doc doesnt define how to change the labels
html
<div id="toolBarConfig"></div>
ts
const sizeVal = Quill.import('attributors/style/size');
sizeVal.whitelist = ['14px', '16px', '72px'];
Quill.register(sizeVal, true);
const quill = new Quill('#toolBarConfig', {
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ header: 1 }, { header: 2 }], // custom button values
[{ list: 'ordered' }, { list: 'bullet' }],
[{ script: 'sub' }, { script: 'super' }], // superscript/subscript
[{ indent: '-1' }, { indent: '+1' }], // outdent/indent
[{ direction: 'rtl' }], // text direction
[{ size: ['14px', '16px', '72px'] }], // custom dropdown
[{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ color: [] }, { background: [] }], // dropdown with defaults from theme
[{ font: [] }],
[{ align: [] }],
['clean'],
['table'], // remove formatting button
['link', 'image', 'video'], //
link and image, video
],
},
theme: 'snow',
});
SCSS
.ql-snow .ql-picker.ql-size span[data-label="14px"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-
value="14px"]::before {
content: '14px'!important;
font-size: 14px !important;
}
.ql-snow .ql-picker.ql-size span[data-label="16px"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-
value="16px"]::before {
content: '16px'!important;
font-size: 16px !important;
}
.ql-snow .ql-picker.ql-size span[data-label="72px"]::before,
.ql-snow .ql-picker.ql-size .ql-picker-item[data-
value="72px"]::before {
content: '72px'!important;
font-size: 72px !important;
}
How to add font types on Quill js with toolbar options?
follow this stackoverflow thread.. the end result

(ng)quill problem: the selected value of custom font family/size is not displayed in ql-picker-label

We have added the ng-quill component to our web app build with angularjs. With the code below my developer tried to customize font family and font size picker in the toolbar. It is functional so far but the selected value of the dropdown options is not displayed after selection. "Sans serif" and "normal" keep to be displayed.
Here the code:
(function () {
'use strict';
angular
.module('tu.richtext.editor', ['ngQuill'])
.constant('NG_QUILL_CONFIG', {
modules: {
toolbar: [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block', 'link'],
[{ 'header': 1 }, { 'header': 2 }],
[{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'indent': '-1' }, { 'indent': '+1' }],
[{ 'direction': 'rtl' }],
[{ 'size': [false, '14px', '16px', '18px', '20px'] }],
[{ 'header': [1, 2, 3, 4, 5, false] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'font': ['sans-serif', 'times-new-roman', 'roboto', 'lato', 'oswald', 'montserrat', 'raleway', 'lora', 'nunito', 'prompt'] }],
[{ 'align': [] }],
['clean'],
['link', 'image', 'video']
]
},
theme: 'snow',
placeholder: '',
readonly: false,
bounds: document.body
})
.config(function(ngQuillConfigProvider, NG_QUILL_CONFIG) {
ngQuillConfigProvider.set(NG_QUILL_CONFIG);
// ngQuillConfigProvider.set(null, null, 'custom placeholder');
})
.component('tuRichtextEditor', {
bindings: {
ngModel: '=',
required: '<',
format: '<'
},
controller: RichtextEditorCtrl,
controllerAs: '$ctrl',
templateUrl: 'app-commons/components/tu-richtext-editor/tuRichText.tpl.html'
});
function RichtextEditorCtrl($scope, $timeout, $sce) {
var ctrl = this;
ctrl.loadComplete = false;
ctrl.customOptions = [{
import: 'attributors/style/size',
whitelist: [false, '14px', '16px', '18px', '20px']
}, {
import: 'attributors/class/font',
whitelist: ['sans-serif', 'times-new-roman', 'roboto', 'lato', 'oswald', 'montserrat', 'raleway', 'lora', 'nunito', 'prompt']
}];
$scope.customModules = {
toolbar: [
[{'size': [false, '14', '16', '18', '20']}]
]
};
ctrl.$onInit = function () {
// console.log(Quill);
// console.log(ctrl.ngModel);
ctrl.readOnly = false;
ctrl.required = ctrl.required? 'required' : '';
registerDelegates();
};
function registerDelegates() {
ctrl.editorCreated = function (editor) {
console.log(editor);
console.log(editor.editor);
};
ctrl.contentChanged = function (editor, html, text, content, delta, oldDelta, source) {
ctrl.ngModel = html;
};
ctrl.selectionChanged = function (editor, range, oldRange, source) {
console.log('editor: ', editor, 'range: ', range, 'oldRange:', oldRange, 'source:', source);
};
ctrl.loadComplete = true;
}
}})();
The css classes are changed too regarding to these examples:
.ql-snow .ql-picker.ql-size .ql-picker-item[data-value="14px"]::before {content: '14'; font-size: 14px !important;}
.ql-snow .ql-picker.ql-font .ql-picker-item[data-value="roboto"]::before {content: 'Roboto'; font-family: 'Roboto', sans-serif !important; }
He had given up now and I have not been able to find the bug.
Quill has an example for how to use custom fonts:
https://quilljs.com/playground/#custom-fonts
You can add custom sizes the same way.

categorised dropdown select2

i am using select2 multi select dropdown, and it works perfectly but my problem is, i want to categorise the drop down list of the same. Here is my code
<script src="/static/select2.js"></script>
<input type="hidden" id="test" value=""/>
and js
$(test).select2({
data:data,
multiple: true,
width: "100%",
placeholder:"None Selected",
closeOnSelect:false,
});
This should work:
$(test).select2({
data:
[
{
text: 'GREETINGS',
children:
[
{ 'id': 1, text: 'hai' },
{ 'id': 2, text: 'hellow'},
]
},
{
text: 'QUESTIONS',
children:
[
{ 'id': 3, 'text': 'yes' },
{ 'id': 4, 'text': 'no' }
]
}
],
multiple: true,
width: "100%",
placeholder: "None Selected",
closeOnSelect: false,
});

Kendo Tree Icons

How to have two trees on the same page with diff icons:
.k-treeview .k-minus {
background: url('../images/k-minus.png') center center;
}
.k-treeview .k-plus {
background: url('../images/k-plus.png') center center;
}
Any help would be great.
This question is a little bit unspecified but I'll try to help you.First off all, to display images in treeView you have to options:
Sprites - you provide css class for all images you wanna display. All can be in same image file like here: http://demos.kendoui.com/content/web/treeview/coloricons-sprite.png
Images - you provide url for each image in single file: http://demos.kendoui.com/content/web/treeview/mail.png
Assuming you got two treeViews in you site with diferrent names like TreeView1 and TreeView2. If this treeViews are similar but just need to have different icons, better solution is sprites option, the simplest way is to prepare 2 different images and provide css to display it, like:
#TreeView1 .k-sprite {
background-image: url("../../content/web/treeview/coloricons-sprite.png");
}
#TreeView2 .k-sprite {
background-image: url("../../content/web/treeview/different-sprite.png");
}
.rootfolder { background-position: 0 0; }
.folder { background-position: 0 -16px; }
.pdf { background-position: 0 -32px; }
.html { background-position: 0 -48px; }
.image { background-position: 0 -64px; }
Now you can have 2 identical but name treeViews with different icons, eg:
$("#TreeView1").kendoTreeView({
dataSource: [{
text: "My Documents", expanded: true, spriteCssClass: "rootfolder", items: [
{
text: "Kendo UI Project", expanded: true, spriteCssClass: "folder", items: [
{ text: "about.html", spriteCssClass: "html" },
{ text: "index.html", spriteCssClass: "html" },
{ text: "logo.png", spriteCssClass: "image" }
]
},
]
}]
});
Of course if you prefer images options you just have to describe different url for image in each treeView dataSourve for all items, like that:
$("#TreeView1").kendoTreeView({
dataSource: [
{
text: "Inbox", imageUrl: "../../content/web/treeview/mail.png",
items: [
{ text: "Read Mail", imageUrl: "../../content/web/treeview/readmail.png" }
]
},
{
text: "Drafts", imageUrl: "../../content/web/treeview/edit.png"
},
]
});
$("#TreeView2").kendoTreeView({
dataSource: [
{
text: "Inbox", imageUrl: "../../content/web/treeview/pdf.png",
items: [
{ text: "Read Mail", imageUrl: "../../content/web/treeview/jpg.png" }
]
},
{
text: "Drafts", imageUrl: "../../content/web/treeview/html.png"
},
]
});
I based on this kendoUI demo: http://demos.telerik.com/kendo-ui/treeview/images. I hope it helps.

Resources