diff --git a/README.md b/README.md index 375fce4..3c3d431 100644 --- a/README.md +++ b/README.md @@ -6,27 +6,32 @@ Highlight.js line numbers plugin. ## Install -#### Bower +### Bower + ``` bower install highlightjs-line-numbers.js ``` -#### Npm +### Npm + ``` npm install highlightjs-line-numbers.js ``` #### Getting the library from CDN + ```html - + ``` + ```html - + ``` ## Usage Download plugin and include file after highlight.js: + ```html @@ -34,6 +39,7 @@ Download plugin and include file after highlight.js: ``` Initialize plugin after highlight.js: + ```js hljs.initHighlightingOnLoad(); @@ -41,6 +47,7 @@ hljs.initLineNumbersOnLoad(); ``` Here’s an equivalent way to calling `initLineNumbersOnLoad` using jQuery: + ```js $(document).ready(function() { $('code.hljs').each(function(i, block) { @@ -50,6 +57,7 @@ $(document).ready(function() { ``` If your needs cool style, add styles by taste: + ```css /* for block of numbers */ .hljs-ln-numbers { @@ -79,11 +87,12 @@ If your needs cool style, add styles by taste: After version 2.1 plugin has optional parameter `options` - for custom setup. -name | type | default value | description ------------|---------|---------------|----------------------- -singleLine | boolean | false | enable plugin for code block with one line +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](startFrom) -#### Examples of using +### Examples of using ```js hljs.initLineNumbersOnLoad({ @@ -95,6 +104,40 @@ hljs.initLineNumbersOnLoad({ hljs.lineNumbersBlock(myCodeBlock, myOptions); ``` +```js +hljs.lineNumbersValue(myCodeBlock, myOptions); +``` + +### startFrom + +If you want numbering to start from some other value than `1`, you can specify a _numbering offset_, in one of the following ways: + +- Specifying desired offset in `hljs.lineNumbersBlock()` call, as in: + +```js +hljs.lineNumbersBlock(myCodeBlock, { + startFrom: 10 +}); +``` + +- Specifying the desired offset in `data-ln-start-from` attribute of `code` element, as in: + +```html +
+
+ ...
+
+
+```
+
+In both cases numbering offset will be `10`, meaning that the numbering will start from `10`.
+
+## Skipping some blocks
+
+(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.
+
## CSS selectors
You may need to select some lines of code after rendering. For instance, you may want
@@ -110,4 +153,4 @@ CSS selector | description
`.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
---
-© 2018 Yauheni Pakala | MIT License
+© 2020 Yauheni Pakala and [Community](https://github.com/wcoder/highlightjs-line-numbers.js/graphs/contributors) | MIT License
diff --git a/bower.json b/bower.json
index 37be8fe..440708d 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "highlightjs-line-numbers.js",
- "version": "2.7.0",
+ "version": "2.8.0",
"homepage": "https://github.com/wcoder/highlightjs-line-numbers.js",
"authors": [
"Yauheni Pakala