Line and token highlighting
Drawing attention to the lines or words that matter inside a block, with ranges and quoted tokens.
- #authoring
- #code
- #shiki
A snippet is usually shown for two or three of its lines, and the rest is there so those lines make sense. Highlighting says which is which, and saves a paragraph that would otherwise have to count the lines out for the reader.
Line ranges
Put the lines in curly braces on the fence. Single lines and ranges can be mixed:
Highlighting half a block highlights nothing. If most lines matter, the block is too long rather than under-marked.
Tokens
Quote a word on the fence and every occurrence of it is marked, wherever it
appears. This is the better tool when the subject is an identifier rather than a
place. A reader following useCallback through a file does not care which line
it sits on:
Both at once
Ranges and tokens combine, and the two marks look different. The range tints the line, and the token outlines the word.
Highlighting is decoration to a screen reader, so the prose around the block still has to name what was marked. The marks make that prose quicker to follow, and do not replace it.
Related entries
Code panels
What every fenced block becomes, which is a titled panel with a file icon, line numbers, soft wrap, copy and collapse.
Terminals and diffs
Shell blocks that read as a session, and diff blocks whose header reports the shape of the change.
CodeBlock component
The JSX form of a code panel, for the cases where a fence cannot carry the props.