GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - highlightjs-plugins/highlightjs-lang.js: Display language of syntax highlighting

BranchesTags
Open more actions menu

Latest commit

 

History

30 Commits
30 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
dist
dist
 
 
src
src
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
bower.json
bower.json
 
 
gulpfile.js
gulpfile.js
 
 
index.html
index.html
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 

Repository files navigation

highlightjs-lang.js npm npm

Highlight.js plugin for display language of syntax highlight.

DEMO

Install

Npm

npm i highlightjs-lang.js

Getting the library from CDN

<script src="https://cdn.jsdelivr.net/npm/highlightjs-lang.js@latest/dist/highlightjs-lang.min.js"></script>

highlightjs-lang.js 1.1.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>

<!-- Load plugin: -->
<script src="path/to/highlightjs-lang.min.js"></script>

Add styles:

.hljs-lang {
    background: #333;
    text-align: center;
    color: #fff;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

Initialize plugin after highlight.js:

hljs.highlightAll();

hljs.initLangOnLoad();  //  <-- init plugin

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

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

Options

After version 1.1.0 plugin has optional parameter options - for custom setup:

version name type default value description
v1.1.0 overrideNames object {} Override the default language names
v1.1.1 fallback func(str): str (lang) => lang Fallback to convert unknown names

Examples of using

Options can be used in these calls:

hljs.initLangOnLoad(myOptions);
hljs.initLangBlock(myCodeBlock, myOptions);

overrideNames

If you want to override the default language name, you can specify a overridden language names, in one of the following ways:

  • Specifying the desired value in js code, as in:
var myOptions = {
    // ...
    overrideNames: {
        cs: 'C#',
    },
    // ...
};
  • Specifying the desired value in data-lang-name attribute of code element, as in:
<pre>
    <code class="cs" data-lang-name="C#">
    ...
    </code>
</pre>

In both cases language name will be C#.

List of default language names

fallback

Specifying the desired format for undeclared language names:

var myOptions = {
  // ...
  fallback: function (lang) {
    return '~~' + lang;
  },
  // ...
};

Convert all undeclared language names to names with ~~ prefix:

xyz -> ~~xyz

Skipping some blocks

(Applies to hljs.initLangOnLoad() initialization only.)

If you want to skip some of your code blocks (to leave them unnumbered), you can mark them with .nohljslang class.

More plugins

  • highlightjs-line-numbers.js — Line numbering plugin.

© 2015 Yauheni Pakala | MIT License

About

Display language of syntax highlighting

wcoder.github.io/highlightjs-lang.js/

Topics

code-highlighthighlighthighlight-jsjavascriptvanilla-javascript

Resources

Readme
MIT license
Activity
Custom properties

Stars

5 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.