diff --git a/resources/js/wysiwyg/config.js b/resources/js/wysiwyg/config.js index 83d4fefb7..49d2add77 100644 --- a/resources/js/wysiwyg/config.js +++ b/resources/js/wysiwyg/config.js @@ -235,7 +235,7 @@ export function build(options) { "-doc-root[doc-root|#text]", "-li[details]", "+code-block[pre]", - "+doc-root[code-block]" + "+doc-root[p|h1|h2|h3|h4|h5|h6|blockquote|code-block|div]" ].join(','), plugins: gatherPlugins(options), contextmenu: false, diff --git a/resources/js/wysiwyg/plugins-details.js b/resources/js/wysiwyg/plugins-details.js index 7d089e54f..44a0a35ab 100644 --- a/resources/js/wysiwyg/plugins-details.js +++ b/resources/js/wysiwyg/plugins-details.js @@ -2,6 +2,7 @@ * @param {Editor} editor * @param {String} url */ +import {blockElementTypes} from "./util"; function register(editor, url) { @@ -217,14 +218,26 @@ function ensureDetailsWrappedInEditable(detailsEl) { unwrapDetailsEditable(detailsEl); detailsEl.attr('contenteditable', 'false'); - const wrap = tinymce.html.Node.create('doc-root', {contenteditable: 'true'}); + const rootWrap = tinymce.html.Node.create('doc-root', {contenteditable: 'true'}); + let previousBlockWrap = null; + for (const child of detailsEl.children()) { - if (child.name !== 'summary') { - wrap.append(child); + if (child.name === 'summary') continue; + const isBlock = blockElementTypes.includes(child.name); + + if (!isBlock) { + if (!previousBlockWrap) { + previousBlockWrap = tinymce.html.Node.create('p'); + rootWrap.append(previousBlockWrap); + } + previousBlockWrap.append(child); + } else { + rootWrap.append(child); + previousBlockWrap = null; } } - detailsEl.append(wrap); + detailsEl.append(rootWrap); } /** diff --git a/resources/js/wysiwyg/util.js b/resources/js/wysiwyg/util.js new file mode 100644 index 000000000..1f63b6529 --- /dev/null +++ b/resources/js/wysiwyg/util.js @@ -0,0 +1,19 @@ + + +export const blockElementTypes = [ + 'p', + 'h1', + 'h2', + 'h3', + 'h4', + 'h5', + 'h6', + 'div', + 'blockquote', + 'pre', + 'code-block', + 'details', + 'ul', + 'ol', + 'table' +]; \ No newline at end of file