-
Notifications
You must be signed in to change notification settings - Fork 127
New release 2.8 #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
New release 2.8 #76
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
aa6a8ac
Implementing line number offset.
peske f80a5b1
Merge pull request #65 from peske/master
wcoder 46e938b
Rework startFrom to options
wcoder bfd1586
Actualize README
wcoder c59234a
Update sample
wcoder 562cea5
Fixes after self-review
wcoder dcf3fc0
Upgrade packages
wcoder aa4e697
Fix future js
wcoder 27411d1
Update min
wcoder af95595
Update version
wcoder b39dba5
Update sampe
wcoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,41 +6,48 @@ 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 | ||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.7.0/highlightjs-line-numbers.min.js"></script> | ||
``` | ||
|
||
```html | ||
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/highlightjs-line-numbers.min.js"></script> | ||
``` | ||
|
||
## Usage | ||
|
||
Download plugin and include file after highlight.js: | ||
|
||
```html | ||
<script src="path/to/highlight.min.js"></script> | ||
|
||
<script src="path/to/highlightjs-line-numbers.min.js"></script> | ||
``` | ||
|
||
Initialize plugin after highlight.js: | ||
|
||
```js | ||
hljs.initHighlightingOnLoad(); | ||
|
||
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 | ||
<pre> | ||
<code data-ln-start-from="10"> | ||
... | ||
</code> | ||
</pre> | ||
``` | ||
|
||
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 `.nohljs-ln` 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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.