Gathering detailed insights and metrics for highlightjs-line-numbers.js
Gathering detailed insights and metrics for highlightjs-line-numbers.js
Gathering detailed insights and metrics for highlightjs-line-numbers.js
Gathering detailed insights and metrics for highlightjs-line-numbers.js
npm install highlightjs-line-numbers.js
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
553 Stars
124 Commits
126 Forks
14 Watching
4 Branches
8 Contributors
Updated on 22 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
40.7%
9,483
Compared to previous day
Last week
33.9%
46,326
Compared to previous week
Last month
8.3%
170,068
Compared to previous month
Last year
-5.5%
2,218,417
Compared to previous year
4
Highlight.js line numbers plugin.
bower install highlightjs-line-numbers.js
npm install highlightjs-line-numbers.js
1<script src="//cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.9.0/highlightjs-line-numbers.min.js"></script>
1<script src="//cdn.jsdelivr.net/npm/highlightjs-line-numbers.js@2.9.0/dist/highlightjs-line-numbers.min.js"></script>
highlightjs-line-numbers.js 2.8.0 is known to work with highlight.js 11.3.1.
Download plugin and include file after highlight.js:
1<script src="path/to/highlight.min.js"></script> 2 3<script src="path/to/highlightjs-line-numbers.min.js"></script>
Initialize plugin after highlight.js:
1hljs.highlightAll(); 2 3hljs.initLineNumbersOnLoad();
Here’s an equivalent way to calling initLineNumbersOnLoad
using jQuery:
1$(document).ready(function() { 2 $('code.hljs').each(function(i, block) { 3 hljs.lineNumbersBlock(block); 4 }); 5});
If your needs cool style, add styles by taste:
1/* for block of numbers */ 2.hljs-ln-numbers { 3 -webkit-touch-callout: none; 4 -webkit-user-select: none; 5 -khtml-user-select: none; 6 -moz-user-select: none; 7 -ms-user-select: none; 8 user-select: none; 9 10 text-align: center; 11 color: #ccc; 12 border-right: 1px solid #CCC; 13 vertical-align: top; 14 padding-right: 5px; 15 16 /* your custom style here */ 17} 18 19/* for block of code */ 20.hljs-ln-code { 21 padding-left: 10px; 22}
After version 2.1 plugin has optional parameter options
- for custom setup.
version | name | type | default value | description |
---|---|---|---|---|
v2.1 | singleLine | boolean | false | enable plugin for code block with one line |
v2.8 | startFrom | int | 1 | Start numbering from a custom value |
1hljs.initLineNumbersOnLoad({ 2 singleLine: true 3});
1hljs.lineNumbersBlock(myCodeBlock, myOptions);
1hljs.lineNumbersBlockSync(myCodeBlock, myOptions);
1hljs.lineNumbersValue(myCodeBlock, myOptions);
If you want numbering to start from some other value than 1
, you can specify a numbering offset, in one of the following ways:
hljs.lineNumbersBlock()
call, as in:1hljs.lineNumbersBlock(myCodeBlock, {
2 startFrom: 10
3});
data-ln-start-from
attribute of code
element, as in:1<pre> 2 <code data-ln-start-from="10"> 3 ... 4 </code> 5</pre>
In both cases numbering offset will be 10
, meaning that the numbering will start from 10
.
(Applies to hljs.initLineNumbersOnLoad()
initialization only.)
If you want to skip some of your code
blocks (to leave them unnumbered), you can mark them with .nohljsln
class.
You may need to select some lines of code after rendering. For instance, you may want to highlight a range of lines, selected by users, by changing their background color. The CSS selectors below can be used to perform these selection operations.
CSS selector | description |
---|---|
.hljs-ln-line | Select all lines, including line numbers |
.hljs-ln-numbers | Select all line numbers, excluding lines of code |
.hljs-ln-code | Select all lines of code, excluding line numbers |
.hljs-ln-line[data-line-number="i"] | Select the ith line, including line number |
.hljs-ln-numbers[data-line-number="i"] | Select the ith line number, excluding the line of code |
.hljs-ln-code[data-line-number="i"] | Select the ith line of code, excluding the line number |
© 2024 Yauheni Pakala and Community | MIT License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
8 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 6
Reason
Found 2/9 approved changesets -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More