TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/angezid/advanced-mark.js/llms.txt
Use this file to discover all available pages before exploring further.
markLines option changes the behavior of markRanges() so that it works with line numbers instead of character offsets. Instead of specifying a byte position and character count, you specify a starting line number and a count of lines to highlight. This makes it especially useful inside <pre> elements and code blocks, where each line of content is a distinct logical unit.
How markLines works
WhenmarkLines: true is set, the start property of each range object becomes a 1-based line number, and length becomes the number of lines to highlight from that starting line.
- The library correctly handles
<br>elements as line separators in addition to newline characters, so it works both in<pre>blocks and in HTML content that uses<br>for formatting. - The option can be combined with
wrapAllRanges: trueto highlight nested or overlapping line ranges, for example to independently layer a background highlight over a selection that is already highlighted. - It can be used in non-
<pre>elements as long as the HTML page is not minified or uses<br>elements for line formatting.
The minimum line number is 1. This differs from text ranges used without
markLines, where start can be 0.Highlight a single line
To highlight exactly one line, pass a range withlength: 1 and set markLines: true:
<pre> element. The generated <mark> element wraps all text content on that line.
Scroll to a highlighted line
A common pattern is to highlight a specific line and then scroll it into view. Use theeach callback to capture the first mark element of the match (identified by info.matchStart), then scroll to it in the done callback:
info.matchStart flag is true only for the first <mark> element created for a given range, which is the one you want to scroll to. The className assignment applies a custom CSS class to every mark element that belongs to the highlighted line.
Multiple line ranges
You can pass multiple range objects to highlight several lines or ranges of lines in a single call. For example, to highlight lines 5 through 10 (six lines total):Combining with wrapAllRanges
AddingwrapAllRanges: true lets you highlight overlapping or nested line ranges without one range cancelling out another. This is useful when you need to apply multiple independent highlight layers to the same lines — for example, a background highlight for “selected” lines and a separate highlight for “changed” lines that partially overlap: