Colour markdown, which is the one language that is not tokens
The token scanner asks what a character is; markdown's meaning is where it sits, so a `#` opens a heading at the start of a line and is an ordinary character three words in. `MarkdownSyntax.kt` reads structure a line at a time and then each line's prose left to right, and `spansOf` is the one entry point that hides which of the two scanners a language got. Conservative wherever a guess would be invisible: emphasis needs a closer on the same line with no space beside either marker, so the `*p = *q` of a C fragment opens nothing; an underscore may not start or end inside a word; and an indented code block is left plain, since four spaces after a blank line and four after a bullet are the same line. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a401e6a7e3
commit
68c5180260
8 files changed
+476
-12
No files matched your search
@@ -270,6 +270,27 @@ printf 'def main():\n # a comment\n print("hello")\n' >"$FILES/main.py"
|
||||
printf '#!/bin/sh\n# a comment\necho hello\n' >"$FILES/run.sh"
|
||||
chmod +x "$FILES/run.sh"
|
||||
printf '{"a": 1, "b": [true, null]}\n' >"$FILES/data.json"
|
||||
# Markdown's scanner is line-structured rather than tokens, so the fixture holds one of each
|
||||
# thing it decides by position: a heading, a fence, a list, a quote, a link and a rule.
|
||||
cat >"$FILES/notes.md" <<'MARKDOWN'
|
||||
# Notes
|
||||
|
||||
A paragraph with `code`, **bold** and a [link](PLAN.md).
|
||||
Not emphasis: a * b * c, and snake_case_name.
|
||||
|
||||
## A list
|
||||
|
||||
- one
|
||||
- two
|
||||
|
||||
> quoted
|
||||
|
||||
```rust
|
||||
fn main() { println!("hello"); }
|
||||
```
|
||||
|
||||
---
|
||||
MARKDOWN
|
||||
# Not UTF-8, so it reads as binary rather than as mojibake.
|
||||
printf '\377\376\000\001binary\n' >"$FILES/picture.bin"
|
||||
# Over FILE_LIMIT (1 MiB), so the read refuses before anything transfers.
|
||||
|
||||
Reference in new issue
Block a user