« Highlight.js » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 82 : | Ligne 82 : | ||
* [http://highlightjs.readthedocs.io/en/latest/css-classes-reference.html CSS classes reference] | * [http://highlightjs.readthedocs.io/en/latest/css-classes-reference.html CSS classes reference] | ||
== Pre-defined modes and regular expressions == | |||
<filebox fn='src/lib/modes.js' collapsed> | |||
export const IDENT_RE = '[a-zA-Z]\\w*'; | |||
export const UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\w*'; | |||
export const NUMBER_RE = '\\b\\d+(\\.\\d+)?'; | |||
export const C_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)'; // 0x..., 0..., decimal, float | |||
export const BINARY_NUMBER_RE = '\\b(0b[01]+)'; // 0b... | |||
export const C_LINE_COMMENT_MODE = COMMENT('//', '$'); | |||
export const C_BLOCK_COMMENT_MODE = COMMENT('/\\*', '\\*/'); | |||
export const HASH_COMMENT_MODE = COMMENT('#', '$'); | |||
</filebox> | |||
== Category == | == Category == |
Version du 4 avril 2023 à 20:02
Liens
- highlight.js
- demo
- developer documentation
- GitHub
- Language contributor checklist
- Language names and aliases
Build
git clone https://github.com/isagalaev/highlight.js cd highlight.js/ # installation des dépendances dans ./node_modules # npm i utilise le fichier package.json npm i # création du dossier build et de ses fichiers node tools/build.js -t browser -n :common csharp cpp # -t browser, target (browser, cdn, node, all) # -n, Disable compression # :common, langages de base # csharp cpp, les langages c# et c++ # the build result is in the build/ directory. |
Test
Après avoir buildé
- build/demo/index.html
- tools/developer.html
# run unit test cd test npm test |
Ajouter un nouveau langage
test/detect/[nouveau langage]/default.txt |
Code de démo |
src/languages/[nouveau langage].js |
/* * Language: [nouveau langage] * Requires: xml.js, csharp.js * Author: Moi <moi@domaine.fr> * Category: common */ function(hljs) { var KEYWORDS = { $pattern: /-[a-z]+/, keyword: 'abc def', literal: 'null false true', type: '', built_in: '' }; var comment = hljs.COMMENT( '//', // tout ce qui commence par // '$' // jusqu'à la fin de la ligne ); return { aliases: ['name1', 'name2'], keywords: KEYWORDS, illegal: /::/, contains: [ // Sub-modes comment, hljs.HASH_COMMENT_MODE // already defined comment pattern ] }; } |
Pre-defined modes and regular expressions
src/lib/modes.js |
export const IDENT_RE = '[a-zA-Z]\\w*'; export const UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\w*'; export const NUMBER_RE = '\\b\\d+(\\.\\d+)?'; export const C_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)'; // 0x..., 0..., decimal, float export const BINARY_NUMBER_RE = '\\b(0b[01]+)'; // 0b... export const C_LINE_COMMENT_MODE = COMMENT('//', '$'); export const C_BLOCK_COMMENT_MODE = COMMENT('/\\*', '\\*/'); export const HASH_COMMENT_MODE = COMMENT('#', '$'); |
Category
assembler | common | config | css |
enterprise | functional | graphics | lisp |
markup | protocols | scientific | scripting |
system | template |
Installation
npm install -g highlight.js # highlight.js → /usr/lib/node_modules/highlight.js/lib/ # languages → /usr/lib/node_modules/highlight.js/lib/languages # css → /usr/lib/node_modules/highlight.js/styles/ |