Skip to content

Commit 76af420

Browse files
authored
Update the line numbering example in readme
Closes GH-36. Reviewed-by: Titus Wormer <[email protected]>
1 parent 4d20320 commit 76af420

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

readme.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,16 @@ console.log(String(file))
362362
You can add support for line numbers and line highlighting with a separate
363363
plugin, [`rehype-highlight-code-lines`][rehype-highlight-code-lines].
364364
365+
`rehype-highlight-code-lines` runs on `<code>` elements with directives
366+
like `showLineNumbers` and range number in curly braces like `{2-4, 8}`.
367+
That directives can be passed as a word in markdown
368+
(` ```ts showLineNumbers {2-4,8} `) or as a class and attribute in HTML
369+
(`<code class="language-ts show-line-numbers" data-highlight-lines="2-4,8">`).
370+
365371
For example, with `example.html`:
366372

367373
```html
368-
<pre><code class="language-js">console.log("Hi!")</code></pre>
374+
<pre><code class="language-js show-line-numbers">console.log("Hi!")</code></pre>
369375
```
370376

371377
…and `example.js`:
@@ -379,10 +385,7 @@ import {read} from 'to-vfile'
379385
const file = await rehype()
380386
.data('settings', {fragment: true})
381387
.use(rehypeHighlight)
382-
.use(rehypeHighlightCodeLines, {
383-
showLineNumbers: true,
384-
lineContainerTagName: 'div'
385-
})
388+
.use(rehypeHighlightCodeLines)
386389
.process(await read('example.html'))
387390
388391
console.log(String(file))
@@ -391,7 +394,7 @@ console.log(String(file))
391394
…then running that yields:
392395

393396
```html
394-
<pre><code class="hljs language-js"><div class="code-line numbered-code-line" data-line-number="1"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">"Hi!"</span>)</div></code></pre>
397+
<pre><code class="hljs language-js"><span class="code-line numbered-code-line" data-line-number="1"><span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">"Hi!"</span>)</span></code></pre>
395398
```
396399

397400
## Types

0 commit comments

Comments
 (0)