From e71c9f0165a06fe41753eb4ce8ec12a3a91a1f1a Mon Sep 17 00:00:00 2001 From: aaandreeew <114206308+aaandreeew@users.noreply.github.com> Date: Sun, 21 Jun 2026 23:02:30 +1000 Subject: [PATCH] Match block IDs according to Obsidian spec Block IDs at the end of lines need leading whitespace, no trailing whitespace, and contain only Latin letters, numbers, or hyphens. I also split the cleaning operation between removing the block ID and removing everything after and including the first inline field. --- src/index/types/markdown.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/index/types/markdown.ts b/src/index/types/markdown.ts index 5b509dfa5..ec0d95699 100644 --- a/src/index/types/markdown.ts +++ b/src/index/types/markdown.ts @@ -664,12 +664,10 @@ export class MarkdownListItem implements Indexable, Linkbearing, Taggable, Field return ( this.$text - // Capture three groups: - // 1) all characters up until group 2 or 3 is encountered - // 2) zero or more inline fields - // 3) zero or one id, - // and replace it with just group 1 - .replace(/(.*?)([\[\(][^:(\[]+::\s*.*?[\]\)]\s*)*(\^.+){0,1}$/gm, "$1") + // Remove any valid block ID, keeping preceding whitespace. + .replace(/(\s)\^[a-zA-Z0-9\-]+$/u, "$1") + // Keep everything before the first inline field, or everything if there isn't one. + .split(/[\[\(][^:\(\[]+::\s*.*?[\]\)]/u)[0] // Trim whitespace. .trim() );