Skip to content

Enhance frontmatter highlighting with error decoration#844

Open
krataratha wants to merge 7 commits into
refactoringhq:mainfrom
krataratha:patch-2
Open

Enhance frontmatter highlighting with error decoration#844
krataratha wants to merge 7 commits into
refactoringhq:mainfrom
krataratha:patch-2

Conversation

@krataratha

Copy link
Copy Markdown

Added frontmatterError decoration for invalid YAML syntax highlighting.

Added frontmatterError decoration for invalid YAML syntax highlighting.
Copilot AI review requested due to automatic review settings June 9, 2026 04:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the CodeMirror frontmatter highlighter to support richer YAML-like highlighting (keys, values, errors) and adds theme styling for these decorations.

Changes:

  • Added an error decoration/class for invalid YAML frontmatter lines.
  • Expanded decorateFrontmatterLine to handle comments/blank lines, nested keys, values, and YAML bullets.
  • Added/updated CodeMirror plugin + base theme mappings for the new decoration classes.

Comment on lines +84 to 95
export function frontmatterHighlightTheme() {
return EditorView.baseTheme({
'.cm-frontmatter-delimiter': { color: 'var(--syntax-frontmatter-key)', fontWeight: '600' },
'.cm-frontmatter-key': { color: 'var(--syntax-frontmatter-key)' },
'.cm-frontmatter-value': { color: 'var(--syntax-frontmatter-value)' },
'.cm-frontmatter-error': { backgroundColor: 'rgba(255, 0, 0, 0.15)', textDecoration: 'underline wavy red' },
})
}
text: string,
isDelimiter: boolean,
): void {
if (text.length === 0) return
Comment on lines +75 to +79
update(update: { docChanged: boolean; viewportChanged: boolean; view: EditorView }) {
if (update.docChanged) {
this.decorations = buildDecorations(update.view)
}
}
Comment on lines +47 to +63
const colonIdx = text.indexOf(':')

if (colonIdx > 0) {
// Highlights keys (including indented nested YAML keys)
const keyStart = text.length - text.trimStart().length
builder.add(from + keyStart, from + colonIdx, frontmatterKey)

const valuePart = text.slice(colonIdx + 1).trimStart()
if (valuePart.length > 0) {
const valueOffset = text.indexOf(valuePart, colonIdx + 1)
builder.add(from + valueOffset, from + text.length, frontmatterValue)
}
} else if (trimmed.startsWith('- ')) {
// Feature: Highlight YAML array/bullet items cleanly as values
const dashOffset = text.indexOf('-')
builder.add(from + dashOffset + 2, from + text.length, frontmatterValue)
} else {
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