MCPcopy Create free account
hub / github.com/churichard/notabase / getBlockReferenceFromNote

Function getBlockReferenceFromNote

editor/backlinks/useBlockReference.ts:68–87  ·  view source on GitHub ↗
(blockId: string, note: Note)

Source from the content-addressed store, hash-verified

66 blockId: string
67): BlockReference | null => {
68 for (const note of Object.values(notes)) {
69 const blockRef = getBlockReferenceFromNote(blockId, note);
70 if (blockRef) {
71 return blockRef;
72 }
73 }
74 return null;
75};
76
77const getBlockReferenceFromNote = (blockId: string, note: Note) => {
78 const editor = createEditor();
79 editor.children = note.content;
80
81 // Find element that matches the block id
82 const matchingElements = Editor.nodes<Element>(editor, {
83 at: [],
84 match: (n) =>
85 Element.isElement(n) &&
86 Editor.isBlock(editor, n) &&
87 isReferenceableBlockElement(n) &&
88 n.id === blockId,
89 });
90

Callers 2

useBlockReferenceFunction · 0.85
computeBlockReferenceFunction · 0.85

Calls 1

Tested by

no test coverage detected