Skip to content

Add custom pair colorization and highlighting for divs#973

Open
vezwork wants to merge 1 commit intomainfrom
feat/div-pair-colorization-and-highlight
Open

Add custom pair colorization and highlighting for divs#973
vezwork wants to merge 1 commit intomainfrom
feat/div-pair-colorization-and-highlight

Conversation

@vezwork
Copy link
Copy Markdown
Member

@vezwork vezwork commented May 7, 2026

Fixes #670 (except "Navigation"? What does that mean? Do we want divs in the outline?)

Screenshot 2026-05-07 at 3 47 08 PM

Adds colorization to pairs of opening and closing div syntax. It is a custom decorator. I don't believe we can use VSCode's builtin pair colorizer because it relies on opening and closing brackets being preset and distinct, whereas Quarto fenced divs can have any number of colons >2 in them and the closing and opening brackets are the same (other than the trailing class/attribute syntax {} on the opening bracket).

Also fixes the parsing of opening syntax for divs where the class/attribute syntax is empty i.e. exactly ::: {}. This was previously not parsed as opening a div (it was parsed as an inline), the regex expected at least one character inside {}. As a result, folding also works better now.

@posit-snyk-bot
Copy link
Copy Markdown
Contributor

posit-snyk-bot commented May 7, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@vezwork vezwork requested a review from juliasilge May 7, 2026 19:53
Copy link
Copy Markdown
Collaborator

@juliasilge juliasilge left a comment

Choose a reason for hiding this comment

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

This is looking great!

Image

Can we add some basic tests for this, in case we find a change we need to make later? I would think something like a new divs.test.ts that is similar to codeBlocks.test.ts, opening a .qmd and confirming the parser finds a Div token. Pretty cheap to test through MarkdownEngine! If you are motivated to go a little further, you could extract the logic for the depth calculation and getDivMarkerRange regex from activateDivBracketDecorations into a pure function to unit test, but that might not be worth it.

/*
* div-brackets.ts
*
* Copyright (C) 2025 by Posit Software, PBC
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Copyright (C) 2025 by Posit Software, PBC
* Copyright (C) 2026 by Posit Software, PBC


// Update decorations when document changes
context.subscriptions.push(
vscode.workspace.onDidChangeTextDocument(event => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we debounce this the same way we do the highlighting decorations in background.ts?

const parser = markdownitParser();

// Cache for parsed tokens
const parseCache = new Map<string, {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we add another listener in here so that we delete this cache at onDidCloseTextDocument?

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.

Add visual support (like folding, colorisation of matching open-close, navigation, ...) for div syntax (:::)

3 participants