Skip to content

Bugfix #177 Match list item block IDs in $cleantext according to Obsidian spec#178

Merged
GamerGirlandCo merged 1 commit into
blacksmithgu:masterfrom
aaandreeew:bug/list-item-cleantext-block-id-parsing
Jun 22, 2026
Merged

Bugfix #177 Match list item block IDs in $cleantext according to Obsidian spec#178
GamerGirlandCo merged 1 commit into
blacksmithgu:masterfrom
aaandreeew:bug/list-item-cleantext-block-id-parsing

Conversation

@aaandreeew

Copy link
Copy Markdown
Contributor

Fix to #177. Fixed how list item $cleantext matches block IDs, as block links within a list item text were erroneously culled.

Block IDs at the end of lines need leading whitespace, no trailing whitespace, and contain only Latin letters, numbers, or hyphens 1. I also split the cleaning operation between removing the block ID and removing everything after and including the first inline field.

I also changed the flags used in the regex patterns. Previous pattern used /gm, which I removed:

  • Don't need /m, especially since $text is only one line, but if multiline list items were to be supported by Datacore in the future, we would only want to match block IDs at the end of the block, not at the end of a line.
  • Don't need /g, since the block ID can only match once anyways and using /g inside split() is redundant.

I added the /u flag for Unicode support, since we can expect Unicode input. Ideally we could use the /v flag but we have to target ES2024 or higher for that. The /v flag supersedes /u and makes some breaking changes to how special characters in character classes are handled 2. Basically, they have to be escaped whereas this ambiguity was allowed before. I made these patterns future compatible if we do upgrade and adopt the /v flag in the future.

The pattern for inline fields is flawed, but that will be a lot of work beyond this bug fix. I am keeping this PR small for now.

Footnotes

  1. https://obsidian.md/help/links#Link+to+a+block+in+a+note

  2. https://github.com/tc39/proposal-regexp-v-flag#how-is-the-v-flag-different-from-the-u-flag

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.
@aaandreeew aaandreeew changed the title Bug 177 Match block IDs according to Obsidian spec Bugfix #177 Match block IDs according to Obsidian spec Jun 22, 2026
@aaandreeew aaandreeew changed the title Bugfix #177 Match block IDs according to Obsidian spec Bugfix #177 Match list item block IDs in $cleantext according to Obsidian spec Jun 22, 2026
@GamerGirlandCo GamerGirlandCo merged commit 1a83c5b into blacksmithgu:master Jun 22, 2026
1 check passed
@aaandreeew aaandreeew deleted the bug/list-item-cleantext-block-id-parsing branch June 23, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants