diff --git a/packages/core/migrations.js b/packages/core/migrations.js
index bf4d191a5..57fc5df4e 100644
--- a/packages/core/migrations.js
+++ b/packages/core/migrations.js
@@ -1,5 +1,5 @@
import { parseHTML } from "./utils/html-parser";
-import { decodeHTML5, encodeHTML5 } from "entities";
+import { decodeHTML5 } from "entities";
export const migrations = {
5.0: {},
@@ -94,18 +94,24 @@ function decodeWrappedTableHtml(html) {
});
}
-const NEWLINE_TOKEN = "[[%NN_NEWLINE_IN_PRE%]]";
-const NEWLINE_TOKEN_REGEX = /\[\[%NN_NEWLINE_IN_PRE%\]\]/gm;
const NEWLINE_REPLACEMENT_REGEX = /\n|
|
/gm;
-const PREBLOCK_REGEX = /
/gm;
+const PREBLOCK_REGEX = /()(.*?)(<\/pre>)/gm;
+const SPAN_REGEX = /(.*?)<\/span>/gm;
export function tinyToTiptap(html) {
if (typeof html !== "string") return html;
// Preserve newlines in pre blocks
- html = html.replace(PREBLOCK_REGEX, (pre) => {
- return pre.replace(NEWLINE_REPLACEMENT_REGEX, NEWLINE_TOKEN);
- });
+ html = html
+ .replace(/\n/gm, "
")
+ .replace(PREBLOCK_REGEX, (_pre, start, inner, end) => {
+ let codeblock = start;
+ codeblock += inner
+ .replace(NEWLINE_REPLACEMENT_REGEX, "
")
+ .replace(SPAN_REGEX, (_span, inner) => inner);
+ codeblock += end;
+ return codeblock;
+ });
const document = parseHTML(html);
@@ -125,14 +131,6 @@ export function tinyToTiptap(html) {
image.parentElement.replaceWith(image.cloneNode());
}
- const codeblocks = document.querySelectorAll("pre");
- for (const pre of codeblocks) {
- pre.innerHTML = encodeHTML5(pre.innerText).replace(
- NEWLINE_TOKEN_REGEX,
- "
"
- );
- }
-
const bogus = document.querySelectorAll("[data-mce-bogus]");
for (const element of bogus) {
element.remove();