fix(highlight): complete markdown syntax highlighting with injections

Fix markdown code block highlighting to properly support both markdown
structure (headings, frontmatter) and language injection (rust, bash).

The key fix uses `#set! injection.include-children` in the injection
query to override tree-sitter-md's internal tokenization, enabling
proper highlighting of embedded languages within code fences.

Changes:
- Use crate's HIGHLIGHT_QUERY_BLOCK for base markdown highlighting
- Add custom injection query with include-children directive
- Add YAML/TOML frontmatter and HTML block injection rules
- Add text.* highlight names (title, literal, uri, reference)
- Add string.escape highlight name
- Add CSS styles for new highlight classes
- Remove unused custom md-highlights.scm
This commit is contained in:
Timothy DeHerrera
2026-01-31 17:24:27 -07:00
parent 352b3c1941
commit 905897b3c4
4 changed files with 52 additions and 37 deletions

View File

@@ -25,9 +25,14 @@ const HIGHLIGHT_NAMES: &[&str] = &[
"punctuation.delimiter",
"punctuation.special",
"string",
"string.escape",
"string.special",
"string.special.path",
"string.special.uri",
"text.literal",
"text.reference",
"text.title",
"text.uri",
"type",
"type.builtin",
"variable",
@@ -57,9 +62,14 @@ const HTML_ATTRS: &[&[u8]] = &[
b" class=\"hl-punctuation-delimiter\"",
b" class=\"hl-punctuation-special\"",
b" class=\"hl-string\"",
b" class=\"hl-string-escape\"",
b" class=\"hl-string-special\"",
b" class=\"hl-string-special-path\"",
b" class=\"hl-string-special-uri\"",
b" class=\"hl-text-literal\"",
b" class=\"hl-text-reference\"",
b" class=\"hl-text-title\"",
b" class=\"hl-text-uri\"",
b" class=\"hl-type\"",
b" class=\"hl-type-builtin\"",
b" class=\"hl-variable\"",
@@ -189,7 +199,7 @@ static MARKDOWN_CONFIG: LazyLock<HighlightConfiguration> = LazyLock::new(|| {
make_config(
tree_sitter_md::LANGUAGE.into(),
"markdown",
include_str!("../queries/md-highlights.scm"),
tree_sitter_md::HIGHLIGHT_QUERY_BLOCK,
include_str!("../queries/md-injections.scm"),
)
});