npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

highlightjs-line-numbers3.js

v0.0.1

Published

Highlight.js line numbers plugin.

Downloads

3

Readme

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>

highlightjs-line-numbers.js 2.8.0 is known to work with highlight.js 11.3.1.

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.highlightAll();

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

More plugins


© 2023 Yauheni Pakala and Community | MIT License