Repository navigation
feat: infer language for untagged code blocks - #60
Merged
Merged
Conversation
Untagged fences get syntax highlighting when a high-precision rule matches: shebang interpreter, `$ ` prompt, valid JSON, HTML (doctype or a basic lowercase tag, excluding JSX), Go package clause, Python def/import, Rust fn/use, or a TOML table. Anything else stays plain so trees, logs, and output are not miscolored. The inferred language drives highlighting only; the block title still shows just the author's tag.
Startup benchmark (
|
| build | mean | ratio | verdict |
|---|---|---|---|
| baseline (main@714aff7) | 294.0ms ± 5.7ms | — | |
| PR | 300.6ms ± 13.5ms | 1.02× | ✅ ok |
Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.
First-frame (large.md, runs=10)
| metric | baseline (main@714aff7) | PR | ratio | verdict |
|---|---|---|---|---|
| first-frame | 213.0ms | 226.1ms | 1.06× | ✅ ok |
Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.
Scroll (large.md)
| metric | baseline (main@714aff7) | PR | ratio | verdict |
|---|---|---|---|---|
| full_mount | 10338.0ms | 10594.0ms | 1.02× | ✅ ok |
| step_p50 | 27.0ms | 27.4ms | 1.01× | ✅ ok |
| step_search_p50 | 28.4ms | 28.5ms | 1.01× | ✅ ok |
| stepMatch_p50 | 21.3ms | 21.5ms | 1.01× | ✅ ok |
| commit | 129.0ms | 130.8ms | 1.01× | ✅ ok |
Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Untagged fenced code blocks get syntax highlighting when their content clearly matches a bundled grammar. Blocks that match no rule stay plain.
Key Changes
detectLangmodule checks block content against high-precision rules. The first match wins, and no match returnsundefined.$shell prompt, valid JSON, HTML, Go, Python, Rust, and TOML.={(a JSX expression attribute) are excluded.inferredLang. It is set only when the fence has no info string (the text after the opening backticks).--render) preloads the inferred grammar too.test/lang-detection.mdlists detected, plain, and tagged cases. Each heading states the expected result.The following prior art was investigated, but rejected for various reasons:
highlightAutoevaluated and rejected. Short snippets came back as nix, applescript, and mipsasm.