diff --git a/package.json b/package.json index b5d8e9e..1fd1a50 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "addonRef": "BetterNotes", "prefsPrefix": "extensions.zotero.Knowledge4Zotero", "addonInstance": "BetterNotes", + "dataSchemaVersion": "8", "releasepage": "https://github.com/windingwind/zotero-better-notes/releases/latest/download/zotero-better-notes.xpi", "updaterdf": "https://raw.githubusercontent.com/windingwind/zotero-better-notes/master/update.json" }, diff --git a/src/modules/createNote.ts b/src/modules/createNote.ts index 7eed6d1..3aca0e5 100644 --- a/src/modules/createNote.ts +++ b/src/modules/createNote.ts @@ -1,4 +1,5 @@ import { getString } from "../utils/locale"; +import { config } from "../../package.json"; export { createWorkspaceNote, createNoteFromTemplate }; @@ -25,7 +26,9 @@ async function createWorkspaceNote() { ); const noteID = await ZoteroPane.newNote(); const noteItem = Zotero.Items.get(noteID); - noteItem.setNote(`

${header}

\n
`); + noteItem.setNote( + `

${header}

\n
` + ); await noteItem.saveTx(); addon.hooks.onSetWorkspaceNote(noteID, "main"); if ( diff --git a/src/modules/import/markdown.ts b/src/modules/import/markdown.ts index 25bf9a3..7a0c3cf 100644 --- a/src/modules/import/markdown.ts +++ b/src/modules/import/markdown.ts @@ -1,4 +1,5 @@ import { addLineToNote } from "../../utils/note"; +import { config } from "../../../package.json"; export async function fromMD( filepath: string, @@ -34,7 +35,7 @@ export async function fromMD( const noteStatus = noteItem ? addon.api.sync.getNoteStatus(noteItem.id) : { - meta: '
', + meta: `
`, content: "", tail: "
", }; diff --git a/src/modules/sync/api.ts b/src/modules/sync/api.ts index 3889c03..dba90a1 100644 --- a/src/modules/sync/api.ts +++ b/src/modules/sync/api.ts @@ -1,6 +1,7 @@ import YAML = require("yamljs"); import { clearPref, getPref, setPref } from "../../utils/prefs"; import { getNoteLinkParams } from "../../utils/link"; +import { config } from "../../../package.json"; export { getRelatedNoteIds, @@ -91,7 +92,7 @@ function getNoteStatus(noteId: number) { const metaRegex = /"?data-schema-version"?="[0-9]*">/; const match = fullContent?.match(metaRegex); if (!match || match.length == 0) { - ret.meta = '
'; + ret.meta = `
`; ret.content = fullContent || ""; return ret; } diff --git a/src/utils/note.ts b/src/utils/note.ts index e520099..7443623 100644 --- a/src/utils/note.ts +++ b/src/utils/note.ts @@ -3,6 +3,7 @@ import katex from "katex"; import { getEditorInstance, getPositionAtLine, insert } from "./editor"; import { getItemDataURL } from "./str"; import { showHint } from "./hint"; +import { config } from "../../package.json"; export { renderNoteHTML, @@ -19,12 +20,10 @@ export { }; function parseHTMLLines(html: string): string[] { - let containerIndex = html.search(/data-schema-version="[0-9]*">/g); - if (containerIndex != -1) { - html = html.substring( - containerIndex + 'data-schema-version="8">'.length, - html.length - "
".length - ); + // Remove container with one of the attrs named data-schema-version if exists + if (html.includes("data-schema-version")) { + html = html.replace(/]*data-schema-version[^>]*>/, ""); + html = html.replace(/<\/div>/, ""); } let noteLines = html.split("\n").filter((e) => e); @@ -125,11 +124,17 @@ async function setLinesToNote(note: Zotero.Item, lines: string[]) { let noteText: string = note.getNote(); let containerIndex = noteText.search(/data-schema-version="[0-9]*/g); if (containerIndex === -1) { - note.setNote(`
${lines.join("\n")}
`); + note.setNote( + `
${lines.join( + "\n" + )}
` + ); } else { let noteHead = noteText.substring(0, containerIndex); note.setNote( - `${noteHead}data-schema-version="8">${lines.join("\n")}
` + `${noteHead}data-schema-version="${ + config.dataSchemaVersion + }">${lines.join("\n")}
` ); }