Jelajahi Sumber

preserve notes when formatting the page

Former-commit-id: 045ac53ce3bf927c39a0a86dca71f625e1690897
Gildas 6 tahun lalu
induk
melakukan
efb11f29af
1 mengubah file dengan 3 tambahan dan 1 penghapusan
  1. 3 1
      extension/ui/content/content-ui-editor-web.js

+ 3 - 1
extension/ui/content/content-ui-editor-web.js

@@ -875,13 +875,15 @@ table {
 			document.body.contentEditable = true;
 		}
 		if (message.method == "formatPage") {
-			document.querySelectorAll(NOTE_TAGNAME).forEach(containerElement => containerElement.remove());
+			const shadowRoots = {};
+			document.querySelectorAll(NOTE_TAGNAME).forEach(containerElement => shadowRoots[containerElement.dataset.noteId] = containerElement.shadowRoot);
 			const article = new Readability(document, { classesToPreserve: ["single-file-highlight", "single-file-highlight-yellow", "single-file-highlight-green", "single-file-highlight-pink", "single-file-highlight-blue"] }).parse();
 			document.body.innerHTML = "";
 			const domParser = new DOMParser();
 			const doc = domParser.parseFromString(article.content, "text/html");
 			const contentEditable = document.body.contentEditable;
 			document.documentElement.replaceChild(doc.body, document.body);
+			document.querySelectorAll(NOTE_TAGNAME).forEach(containerElement => containerElement.shadowRoot = shadowRoots[containerElement.dataset.noteId]);
 			document.body.contentEditable = contentEditable;
 			document.head.querySelectorAll("style").forEach(styleElement => styleElement.remove());
 			const styleElement = document.createElement("style");