// Obsidian's charset for author-typed block ids: letters, digits and dashes. const BLOCK_ID = "[A-Za-z0-9][A-Za-z0-9-]*"; // "some text ^my-id" — the marker closing a block. export const TRAILING_BLOCK_ID_RE = new RegExp(`\\s\\^(${BLOCK_ID})$`); // "^my-id" alone on the line after a block. export const STANDALONE_BLOCK_ID_RE = new RegExp(`^\\^(${BLOCK_ID})$`); const BLOCK_ID_RE = new RegExp(`^${BLOCK_ID}$`); // The anchor keeps the caret: toSlug eats it, so no heading anchor can ever collide // with a block id. Browsers percent-decode a fragment before matching ids, so `#^id` // still finds `id="^id"`. export function blockAnchor(id: string): string | null { return BLOCK_ID_RE.test(id) ? `^${id}` : null; }