You can highlight specific lines or text within a code block using markers.
Line Markers
- Targeting lines: Use
{line1, line2, start-end} syntax after the language identifier. - Marker types: Use
del={lines} for deletions, ins={lines} for insertions, and {lines} for neutral marking. - Labels: You can add labels to markers using the syntax
{"label": line_number} or by providing long labels on their own lines using {"label": start-end}.
Text Markers
- String matching: Use
"text" to highlight specific text within lines. - Regex: Use
/pattern/ to highlight text matching a regular expression. - Inline marker types: You can specify marker types for text matches using
ins="text" or del="text".
Diff Syntax
Use the diff language identifier for standard diff-style highlighting (+ for insertions, - for deletions). You can also combine diff with syntax highlighting using diff lang="js".
// Line 1 is targeted
// Line 2
// Line 3
// Line 4 is targeted
function demo() {
console.log('this line is marked as deleted')
// This line and the next one are marked as inserted
console.log('this is the second inserted line')
return 'this line uses the neutral default marker type'
}
function thisIsJavaScript() {
- console.log('Old code to be removed')
+ console.log('New and shiny code!')
}
console.log('The words yes and yep will be marked.')