• Stars
    star
    539
  • Rank 82,402 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Line numbering plugin for Highlight.js

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

More Repositories

1

open-source-xamarin-apps

๐Ÿ“ฑ Collaborative List of Open Source Xamarin & MAUI Apps
458
star
2

life-calendar

๐Ÿ“† Online calendar of your Life in Weeks.
JavaScript
94
star
3

Xamarin.Plugin.DeviceOrientation

Cross-platform plugin to work with screen orientation of mobile device.
C#
61
star
4

share-buttons

๐Ÿ‘ Simple, powerful, customizable and super lightweight social buttons for your site
JavaScript
47
star
5

Xamarin.PeriodicBackgroundService

Simple implementation of periodic background service with Xamarin.
C#
36
star
6

FB2Library

Cross-Platform .NET library for read .FB2 ebook files.
C#
29
star
7

awesome-xamarin-bookmarks

๐Ÿš€ ๐Ÿ“– A collection of interesting links for Xamarin developers
28
star
8

Xamarin.BlurView

Dynamic iOS-like blur of underlying Views for Android.
C#
28
star
9

ShortcutBadger

Xamarin.Android library supports badge notification like iOS in Samsung, LG, Sony and HTC launchers. Port of
C#
27
star
10

IP-Scanner

Simple IP subset scanner on .NET. Available for Windows, Linux and macOS.
C#
16
star
11

AndroidAboutPage

Port of https://github.com/medyo/android-about-page
C#
15
star
12

MaterialChipView

Material Chip View can be used as tags for categories, contacts or creating text clouds. Port of
C#
13
star
13

MvvmCrossStarterKit

The starter project to develop apps with Xamarin + MvvmCross
C#
11
star
14

xamarin-embedding-starter-kit

.NET Embedding starter kit for mobile development.
C#
4
star
15

highlightjs-lang.js

Display language of syntax highlighting
HTML
4
star
16

node-mysql-connect

Simple wrapper with additional functionality over node-mysql.
JavaScript
3
star
17

Scalpel

A surgical debugging tool to uncover the layers under your app.
C#
2
star
18

paint.web

Simple paint with HTML5 canvas and javascript
JavaScript
2
star
19

TwitterFeed

Simple app for demonstration of the power of universal apps Windows 10.
C#
2
star
20

node-rocketsms

Modern RocketSMS SMS-gateway API.
JavaScript
2
star
21

xamarin-snake-game

Xamarin iOS application + SpriteKit game engine
C#
2
star
22

basic-pdf.js

PDF.js for using on site
JavaScript
2
star
23

AndroidDynamicTheme

Xamarin.Android sample of changing theme on runtime.
C#
2
star
24

wcoder.github.io

๐Ÿ‘จโ€๐Ÿ’ป My tech blog
HTML
2
star
25

redactorjs-charmap

Plugin for Redactor (WYSIWYG html editor)
JavaScript
2
star
26

AppInsightsForms

Demo project for using ApplicationInsights-Xamarin
C#
1
star
27

jarvis

The speech recognition program and executing commands
Shell
1
star
28

PHPj

Simple MVC framework on PHP
PHP
1
star
29

maui-playground

C#
1
star
30

Yandex.SpeechKit.Xamarin

Yandex SpeechKit Mobile SDK for Xamarin
C#
1
star
31

android-draggedview

Simple implementation of Drag and Drop on Android
Java
1
star
32

XForms.Controls

Controls for Xamarin Forms
C#
1
star
33

SimpleImageViewer

Simple Xamarin.Android ImageViewer (sliding gallery, pinch-zoom, caching, infinite scroll, huge images)
C#
1
star
34

sdate.js

Controls for selection date.
JavaScript
1
star
35

XPusher

Mobile applications for test sending of push notifications.
C#
1
star
36

MasterHamburger

Sample MasterDetails app with Xamarin.Forms and FreshMvvm
C#
1
star
37

BothsSides

Example of adding Navigation view on both left and right side. Port of https://github.com/GunaseelanArumaikkannu/NavigationViewOnBothsSides
C#
1
star
38

PocHttpClientFactory

Simple console app for working with HttpClientFactory + Refit + Polly
C#
1
star
39

typesetter.js

Simple and extensible typesetter with JavaScript
JavaScript
1
star
40

SignInWithApple.Sample

C#
1
star
41

MuPDF-for-Xamarin-iOS

My attempt to make port of native-C MuPDF.iOS library for Xamarin iOS
C#
1
star
42

XamarinStatus

[WIP] Simple Xamarin app for display Xamarin Runtime status
C#
1
star
43

itsharkpro-citymap-flutter

Materials for IT Shark Meetup #2 - Flutter.io
Dart
1
star
44

flutter-playground

Dart
1
star
45

AloeStackViewXamarin

A simple class for laying out a collection of views with a convenient API, while leveraging the power of Auto Layout. Port of
C#
1
star
46

Forms.SampleSignInFlow

Sample navigation flow for Sign In with Xamarin.Forms
C#
1
star
47

Xamarin.UCE-Handler

Convenient Uncaught-Exception Handler Library For Testers and Developers. Copy, Share, Email, Save crash logs easily.
C#
1
star
48

YPSamples.SimpleOCR

Simple Console app on .NET Core for recognizing phone numbers from the image.
C#
1
star
49

ZeroTab

Empty New Tab Page | Google Chrome Extension
JavaScript
1
star