Open rav88 opened 2 years ago
Seems that you are using React and so do I currently so while I had created one custom button to insert table, adding this to the configuration helped me deal with the problem
const config = {
cleanHTML: {
replaceNBSP : false,
fillEmptyParagraph : false,
}, ....other}
this is where config is used
<JoditEditor
value={tinyMceStore.editorContent}
config={config}
ref={editorRef}
onBlur={newContent => tinyMceStore.setEditorContent(newContent,page)}
onChange={newContent => {}}
/>
and function to insert a table using custom button is as
insertTable = (editorRef: any, rows: number, cols: number) => {
const editorInstance = editorRef.current?.component;
if (!editorInstance) {
return;
}
const newTable = this.generateHtmlTable(rows, cols, editorInstance);
editorInstance.selection.insertNode(newTable);
editorInstance.selection.setCursorAfter(newTable)
}
generateHtmlTable = (rows: number, columns: number, editor: any) => {
const table = editor.createInside.element('table');
table.style.width = '100%'
table.style.borderCollapse = 'collapse'
const cellWidth = `${100 / columns}%`
for (let i = 0; i < rows; i++) {
const tr = editor.createInside.element('tr')
for (let j = 0; j < columns; j++) {
const td = editor.createInside.element('td')
td.style.width = cellWidth
td.innerHTML = ' '
tr.appendChild(td)
}
table.appendChild(tr)
}
return table;
}
Hope this helps
Jodit-React Version: 1.3.11
Browser: Chrome OS: Windows 10 Is React App: True
Code
Expected behavior: When i use the configuration of "new line" feature, when a new line is represented by a paragraph
<p>
, I want to have a table rendered directly below the text. When i use the configuration of "new line" feature, when a new line is represented by<br />
or<div></div>
i want for the cursor to not return back / act normallyActual behavior: When i use the configuration of "new line" feature, when a new line is represented by a paragraph (P), I want to have a table rendered below the text. Now it is rendering an extra
<p><br /><p>
entry, that can not be easily deleted. When i use the configuration of "new line" feature, when a new line is represented by a BR or DIV tag, I want for the cursor to behave normaly, but for now it goes back, leaving one of the letters behind.