All Projects → wcoder → Highlightjs Line Numbers.js

wcoder / Highlightjs Line Numbers.js

Licence: mit
Line numbering plugin for Highlight.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Highlightjs Line Numbers.js

Drone Cache
A Drone plugin for caching current workspace files between builds to reduce your build times
Stars: ✭ 194 (-39.94%)
Mutual labels:  hacktoberfest, plugin
reveal-code-focus
A Reveal.js plugin that allows focusing on specific lines of code blocks.
Stars: ✭ 108 (-66.56%)
Mutual labels:  code, highlight
Netlify Cms
A Git-based CMS for Static Site Generators
Stars: ✭ 14,776 (+4474.61%)
Mutual labels:  hacktoberfest, npm-package
Vue Morphling
Vue filters and directives collection.
Stars: ✭ 179 (-44.58%)
Mutual labels:  hacktoberfest, highlight
Motrix Webextension
A chrome extension for the Motrix Download Manager
Stars: ✭ 253 (-21.67%)
Mutual labels:  hacktoberfest, plugin
Vue Highlight.js
📜 Highlight.js syntax highlighter component for Vue.
Stars: ✭ 180 (-44.27%)
Mutual labels:  hacktoberfest, highlight
Node Virtualbox
A JavaScript Library for Interacting with VirtualBox
Stars: ✭ 231 (-28.48%)
Mutual labels:  hacktoberfest, npm-package
Strapi Middleware Cache
🔌 A cache middleware for https://strapi.io
Stars: ✭ 146 (-54.8%)
Mutual labels:  hacktoberfest, plugin
Ngx Smart Modal
Modal/Dialog component crafted for Angular
Stars: ✭ 256 (-20.74%)
Mutual labels:  hacktoberfest, npm-package
laravel-markdown
A highly configurable markdown renderer and Blade component for Laravel
Stars: ✭ 159 (-50.77%)
Mutual labels:  code, highlight
Standup Raven
A Mattermost plugin for communicating daily standups across teams
Stars: ✭ 161 (-50.15%)
Mutual labels:  hacktoberfest, plugin
Hashids.js
A small JavaScript library to generate YouTube-like ids from numbers.
Stars: ✭ 3,525 (+991.33%)
Mutual labels:  hacktoberfest, npm-package
Waifu Motivator Plugin
OSS Waifu Motivator Plugin for Jetbrains to help boost your motivation while coding!
Stars: ✭ 160 (-50.46%)
Mutual labels:  hacktoberfest, plugin
V Chart Plugin
Easily bind a chart to the data stored in your Vue.js components.
Stars: ✭ 188 (-41.8%)
Mutual labels:  hacktoberfest, plugin
Inspirational Quotes
💡 A simple NPM Package which returns random Inspirational Quotes. Get your daily quote and stay motivated! ✌️ 🌸
Stars: ✭ 150 (-53.56%)
Mutual labels:  hacktoberfest, npm-package
Bookmarks.dev
Bookmarks and Code Snippets Manager for Developers & Co
Stars: ✭ 218 (-32.51%)
Mutual labels:  hacktoberfest, code
Nucleus
The Ultimate Essentials Plugin for Sponge.
Stars: ✭ 144 (-55.42%)
Mutual labels:  hacktoberfest, plugin
Geshi 1.0
Original version of Generic Syntax Highlighter for PHP
Stars: ✭ 149 (-53.87%)
Mutual labels:  hacktoberfest, highlight
CodeEditorView
Code Editor UITextView
Stars: ✭ 20 (-93.81%)
Mutual labels:  code, highlight
Protein
💊 Protein is an IntelliJ Plugin to generate Kotlin code for Retrofit 2 and RxJava 2 based on a Swagger definition
Stars: ✭ 273 (-15.48%)
Mutual labels:  hacktoberfest, plugin

highlightjs-line-numbers.js npm npm

Highlight.js line numbers plugin.

DEMO | SСREENSHOTS

Install

Bower

bower install highlightjs-line-numbers.js

Npm

npm install highlightjs-line-numbers.js

Getting the library from CDN

<script src="//cdnjs.cloudflare.com/ajax/libs/highlightjs-line-numbers.js/2.8.0/highlightjs-line-numbers.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/highlightjs-line-numbers.min.js"></script>

Usage

Download plugin and include file after highlight.js:

<script src="path/to/highlight.min.js"></script>

<script src="path/to/highlightjs-line-numbers.min.js"></script>

Initialize plugin after highlight.js:

hljs.initHighlightingOnLoad();

hljs.initLineNumbersOnLoad();

Here’s an equivalent way to calling initLineNumbersOnLoad using jQuery:

$(document).ready(function() {
    $('code.hljs').each(function(i, block) {
        hljs.lineNumbersBlock(block);
    });
});

If your needs cool style, add styles by taste:

/* for block of numbers */
.hljs-ln-numbers {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;

    text-align: center;
    color: #ccc;
    border-right: 1px solid #CCC;
    vertical-align: top;
    padding-right: 5px;

    /* your custom style here */
}

/* for block of code */
.hljs-ln-code {
    padding-left: 10px;
}

Options

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

Examples of using

hljs.initLineNumbersOnLoad({
    singleLine: true
});
hljs.lineNumbersBlock(myCodeBlock, myOptions);
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:
hljs.lineNumbersBlock(myCodeBlock, {
    startFrom: 10
});
  • Specifying the desired offset in data-ln-start-from attribute of code element, as in:
<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 .nohljsln class.

CSS selectors

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

© 2020 Yauheni Pakala and Community | MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].