1 | 'use strict'
|
---|
2 | var refractorMarkupTemplating = require('./markup-templating.js')
|
---|
3 | module.exports = handlebars
|
---|
4 | handlebars.displayName = 'handlebars'
|
---|
5 | handlebars.aliases = ['hbs']
|
---|
6 | function handlebars(Prism) {
|
---|
7 | Prism.register(refractorMarkupTemplating)
|
---|
8 | ;(function (Prism) {
|
---|
9 | Prism.languages.handlebars = {
|
---|
10 | comment: /\{\{![\s\S]*?\}\}/,
|
---|
11 | delimiter: {
|
---|
12 | pattern: /^\{\{\{?|\}\}\}?$/,
|
---|
13 | alias: 'punctuation'
|
---|
14 | },
|
---|
15 | string: /(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,
|
---|
16 | number: /\b0x[\dA-Fa-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[Ee][+-]?\d+)?/,
|
---|
17 | boolean: /\b(?:false|true)\b/,
|
---|
18 | block: {
|
---|
19 | pattern: /^(\s*(?:~\s*)?)[#\/]\S+?(?=\s*(?:~\s*)?$|\s)/,
|
---|
20 | lookbehind: true,
|
---|
21 | alias: 'keyword'
|
---|
22 | },
|
---|
23 | brackets: {
|
---|
24 | pattern: /\[[^\]]+\]/,
|
---|
25 | inside: {
|
---|
26 | punctuation: /\[|\]/,
|
---|
27 | variable: /[\s\S]+/
|
---|
28 | }
|
---|
29 | },
|
---|
30 | punctuation: /[!"#%&':()*+,.\/;<=>@\[\\\]^`{|}~]/,
|
---|
31 | variable: /[^!"#%&'()*+,\/;<=>@\[\\\]^`{|}~\s]+/
|
---|
32 | }
|
---|
33 | Prism.hooks.add('before-tokenize', function (env) {
|
---|
34 | var handlebarsPattern = /\{\{\{[\s\S]+?\}\}\}|\{\{[\s\S]+?\}\}/g
|
---|
35 | Prism.languages['markup-templating'].buildPlaceholders(
|
---|
36 | env,
|
---|
37 | 'handlebars',
|
---|
38 | handlebarsPattern
|
---|
39 | )
|
---|
40 | })
|
---|
41 | Prism.hooks.add('after-tokenize', function (env) {
|
---|
42 | Prism.languages['markup-templating'].tokenizePlaceholders(
|
---|
43 | env,
|
---|
44 | 'handlebars'
|
---|
45 | )
|
---|
46 | })
|
---|
47 | Prism.languages.hbs = Prism.languages.handlebars
|
---|
48 | })(Prism)
|
---|
49 | }
|
---|