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
editor: add block-id on nodes inside callout
Abdullah Atta1a2ce6ba7238
diff --git a/packages/editor/src/extensions/block-id/block-id.ts b/packages/editor/src/extensions/block-id/block-id.tsindex 1838438a8..986027dfc 100644--- a/packages/editor/src/extensions/block-id/block-id.ts+++ b/packages/editor/src/extensions/block-id/block-id.ts@@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import { Extension, NodeWithPos } from "@tiptap/core";import { Plugin } from "@tiptap/pm/state";import { nanoid } from "nanoid";+import { Callout } from "../callout";const BLOCK_ID_TYPES = ["paragraph",@@ -74,13 +75,16 @@ export const BlockId = Extension.create({if (!isDocChanged) return null;const blocksWithoutBlockId: NodeWithPos[] = [];- newState.tr.doc.forEach((n, offset) => {+ newState.tr.doc.forEach(function addBlocks(n, offset) {if (n.isBlock &&BLOCK_ID_TYPES.includes(n.type.name) &&!n.attrs.blockId)blocksWithoutBlockId.push({ node: n, pos: offset });++ if (n.type.name === Callout.name)+ n.forEach((n, pos) => addBlocks(n, offset + pos + 1));});if (blocksWithoutBlockId.length > 0) {const { tr } = newState;diff --git a/packages/editor/src/utils/toc.ts b/packages/editor/src/utils/toc.tsindex f465d1726..38b42d37a 100644--- a/packages/editor/src/utils/toc.ts+++ b/packages/editor/src/utils/toc.ts@@ -25,14 +25,14 @@ export type TOCItem = {};export function getTableOfContents(content: HTMLElement) {- const headings = content.querySelectorAll("h1, h2, h3, h4, h5, h6");const tableOfContents: TOCItem[] = [];- for (let i = 0; i < headings.length; i++) {- const heading = headings[i];+ for (const heading of content.querySelectorAll<HTMLHeadingElement>(+ "h1, h2, h3, h4, h5, h6"+ )) {const level = parseInt(heading.tagName[1]);const title = heading.textContent;- const id = heading.getAttribute("data-block-id");+ const id = heading.dataset.blockId;if (!id || !title) continue;tableOfContents.push({