Skip to content

Highlighting for HQL, and for a cell in any language - #12

Merged
ewiger merged 2 commits into
mainfrom
feat/fence-highlighting
Nov 25, 2026
Merged

ewiger merged 2 commits into
mainfrom
feat/fence-highlighting

Conversation

@ewiger

@ewiger ewiger commented Nov 25, 2026

Copy link
Copy Markdown
Owner

What changes

  • HQL is a language of the extension. A .hql file is coloured, and so is the body of an hql fence in a card. The token rules follow the scanner and parser of HQL 0.8.0.
  • A cell in any language is coloured as that language. python#eval id=plot was shown in one colour, because the Markdown grammar does not read a language name followed by #. The extension now has its own fence rules.
  • Fences know the languages GitHub knows. The rules are generated by syntaxes/fences.mjs from two tables: the languages VS Code ships a grammar for, and the 770 languages of GitHub Linguist 9.7.0 that have a TextMate scope. A fence in a language with no installed grammar has its opening line coloured and its body left plain.
  • The opening line of a cell and the hql:output markers have their own colours: the language, the mode, each attribute.
  • examples/highlighting is a vault to look at in the editor, opened with npm run example:highlighting.

How it was checked

  • The extension's tests and type check pass, with 17 new grammar tests. They check structure; no tokenizer runs in the suite.
  • The grammars were run through VS Code's TextMate tokenizer outside the editor, on the example vault.
  • The example vault was opened in a development host.
  • The cells of examples/highlighting/cells.hmd were run with hql render, and queries/catalog.hql with hql run.

Known gaps, each a row in the extension's tracker

  • A fence nested in a list item or a block quote is still read by the Markdown grammar.
  • A link inside a sentence gets its HyperMarkDown colour from the language server, and not from the grammar.
  • The extension carries no grammar for D2.

HQL is a language of the extension: a `.hql` file is coloured, and so is
the body of an `hql` fence in a card. The token rules follow the scanner
and parser of HQL 0.8.0.

A fence with a cell suffix, such as `python#eval id=plot`, is coloured as
that language. The Markdown grammar does not read a language name followed
by `#`, so the extension has its own fence rules, generated by
`syntaxes/fences.mjs` from two tables: the languages VS Code ships a
grammar for, and the 770 languages of GitHub Linguist 9.7.0 that have a
TextMate scope. A fence in a language with no installed grammar has its
opening line coloured and its body left plain. The mode, the attributes,
and the `hql:output` markers have their own colours.

`examples/highlighting` is a vault to look at in the editor: HQL cells
with their saved output, fences in many languages, two standalone `.hql`
files, and the forms of a fence the rules do not reach yet.
@ewiger
ewiger merged commit 0389d0b into main Nov 25, 2026
12 checks passed
@ewiger
ewiger deleted the feat/fence-highlighting branch November 25, 2026 18:48
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.

1 participant