Skip to content

fix: skip inline code spans and YAML front matter in attribute diagnostics#342

Merged
mcanouil merged 3 commits into
mainfrom
fix/inline-code-span-attribute-detection
May 6, 2026
Merged

fix: skip inline code spans and YAML front matter in attribute diagnostics#342
mcanouil merged 3 commits into
mainfrom
fix/inline-code-span-attribute-detection

Conversation

@mcanouil
Copy link
Copy Markdown
Owner

@mcanouil mcanouil commented May 6, 2026

The inline attribute diagnostics provider extracted any {...} match in the document and ran syntax-level checks on it. Two cases produced false-positive diagnostics:

Documenting Pandoc attribute syntax in prose with backticks, for example `{key = "value"}`, was treated as a real attribute and the spaces around = were flagged.

YAML literal block scalars containing curly braces, for example Typst code under include-before-body, spanned the closing brace across newlines and the let text = it.text() body fired the spaces-around-= diagnostic.

Detect CommonMark inline backtick code spans and the YAML front matter region with two new TextRange helpers in src/utils/yamlPosition.ts, and exclude attribute matches whose endpoints fall inside either region. Fence-header attributes that contain quoted backticks in their info string remain unaffected.

mcanouil added 2 commits May 6, 2026 14:50
Pandoc attribute syntax wrapped in backticks (for example, while
documenting `{key="value"}` rules in prose) was treated as a real
attribute block.  When the example used spaces around `=` the
inline attribute diagnostic falsely reported "Remove spaces around
\"=\" in attribute assignment".

Detect CommonMark inline code spans by matching backtick runs of
equal length and exclude attribute matches whose start lies inside
such a span.  Fence-header attributes that contain quoted backticks
in their info string remain unaffected.
Curly braces inside literal block scalars (for example, Typst code
under `include-before-body`) were extracted by the attribute regex
and triggered the spaces-around-`=` diagnostic on the body of the
scalar.

Detect the YAML front-matter region with a dedicated TextRange
helper and treat it as an additional fenced exclusion in
`extractBlocks`, alongside fenced code blocks and inline code spans.
@mcanouil mcanouil added the Type: Bug 🐛 Issues related to bugs, errors, or mistakes label May 6, 2026
@mcanouil mcanouil self-assigned this May 6, 2026
Replace `text.split("\n")` with `indexOf("\n")` walks to avoid
allocating an intermediate line array on every `extractBlocks`
invocation.  The function is called per validation (debounced) and
per code-action request, alongside `getCodeBlockRanges` which also
splits, so the redundancy compounded on each call.

Behaviour and test coverage are unchanged.
@mcanouil mcanouil merged commit adbbb03 into main May 6, 2026
10 of 11 checks passed
@mcanouil mcanouil deleted the fix/inline-code-span-attribute-detection branch May 6, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug 🐛 Issues related to bugs, errors, or mistakes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant