fix: note sync format

This commit is contained in:
xiangyu 2022-12-04 17:10:45 +08:00
parent 239fd2e787
commit 083c24b6ae
2 changed files with 27 additions and 3 deletions

View File

@ -746,7 +746,7 @@ class NoteParse extends AddonBase {
noteItem.libraryID,
this._Addon.NoteExport._exportPath,
options.skipSavingImages,
true,
false,
NodeMode.direct
);
console.log("rehype", rehype);
@ -852,6 +852,9 @@ class NoteParse extends AddonBase {
// }
// }
// Check if image already belongs to note
this._Addon.SyncUtils.processM2NRehypeMetaImageNodes(
this._Addon.SyncUtils.getM2NRehypeImageNodes(rehype)
);
this._Addon.SyncUtils.processM2NRehypeHighlightNodes(
this._Addon.SyncUtils.getM2NRehypeHighlightNodes(rehype)

View File

@ -910,8 +910,9 @@ class SyncUtils extends AddonBase {
const newChild = h("span");
this.replace(newChild, node);
newChild.properties.ztype = "zimage";
const newNode = h("zimage", [newChild]);
this.replace(node, newNode);
// const newNode = h("zimage", [newChild]);
// this.replace(node, newNode);
node.properties.alt = toHtml(newChild);
}
console.log("zimage", node);
}
@ -973,6 +974,26 @@ class SyncUtils extends AddonBase {
return nodes;
}
processM2NRehypeMetaImageNodes(nodes) {
if (!nodes.length) {
return;
}
console.log("processing M2N meta images", nodes);
for (const node of nodes) {
if (/zimage/.test(node.properties.alt)) {
const newNode: any = unified()
.use(remarkGfm)
.use(remarkMath)
.use(rehypeParse, { fragment: true })
.parse(node.properties.alt);
console.log(newNode);
newNode.properties.src = node.properties.src;
this.replace(node, newNode);
}
}
}
processM2NRehypeHighlightNodes(nodes) {
if (!nodes.length) {
return;