- Notifications
You must be signed in to change notification settings - Fork1
Display language of syntax highlighting
License
highlightjs-plugins/highlightjs-lang.js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Highlight.js plugin for display language of syntax highlight.
npm i highlightjs-lang.js
<scriptsrc="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+
Download plugin and include file after highlight.js:
<scriptsrc="path/to/highlight.min.js"></script><!-- Load plugin: --><scriptsrc="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 callinginitLangBlock
using jQuery:
$(document).ready(function(){$('code.hljs').each(function(i,block){hljs.initLangBlock(block);});});
After version 1.1.0 plugin has optional parameteroptions
- 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 |
Options can be used in these calls:
hljs.initLangOnLoad(myOptions);
hljs.initLangBlock(myCodeBlock,myOptions);
If you want to override the default language name, you can specify aoverridden language names, in one of the following ways:
- Specifying the desired value in js code, as in:
varmyOptions={// ...overrideNames:{cs:'C#',},// ...};
- Specifying the desired value in
data-lang-name
attribute ofcode
element, as in:
<pre><codeclass="cs"data-lang-name="C#"> ...</code></pre>
In both cases language name will beC#
.
Specifying the desired format for undeclared language names:
varmyOptions={// ...fallback:function(lang){return'~~'+lang;},// ...};
Convert all undeclared language names to names with~~
prefix:
xyz -> ~~xyz
(Applies tohljs.initLangOnLoad()
initialization only.)
If you want to skip some of yourcode
blocks (to leave them unnumbered), you can mark them with.nohljslang
class.
- highlightjs-line-numbers.js — Line numbering plugin.
© 2015 Yauheni Pakala | MIT License
About
Display language of syntax highlighting
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.