A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: newline artifacts during codeblock migration
thecodrrd17e7f384e87
diff --git a/packages/core/migrations.js b/packages/core/migrations.jsindex 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|<br>|<br\/>/gm;-const PREBLOCK_REGEX = /<pre.*<\/pre>/gm;+const PREBLOCK_REGEX = /(<pre.*?>)(.*?)(<\/pre>)/gm;+const SPAN_REGEX = /<span class=.*?>(.*?)<\/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, "<br/>")+ .replace(PREBLOCK_REGEX, (_pre, start, inner, end) => {+ let codeblock = start;+ codeblock += inner+ .replace(NEWLINE_REPLACEMENT_REGEX, "<br/>")+ .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,- "<br/>"- );- }-const bogus = document.querySelectorAll("[data-mce-bogus]");for (const element of bogus) {element.remove();