1 /*! `handlebars` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar
= (function () {
8 Author: Robin Ward <robin.ward@gmail.com>
9 Description: Matcher for Handlebars as well as EmberJS additions.
10 Website: https://handlebarsjs.com
14 function handlebars(hljs
) {
15 const regex
= hljs
.regex
;
61 // as defined in https://handlebarsjs.com/guide/expressions.html#literal-segments
62 // this regex matches literal segments like ' abc ' or [ abc ] as well as helpers and paths
63 // like a/b, ./abc/cde, and abc.bcd
65 const DOUBLE_QUOTED_ID_REGEX
= /""|"[^"]+"/;
66 const SINGLE_QUOTED_ID_REGEX
= /''|'[^']+'/;
67 const BRACKET_QUOTED_ID_REGEX
= /\[\]|\[[^\]]+\]/;
68 const PLAIN_ID_REGEX
= /[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+/;
69 const PATH_DELIMITER_REGEX
= /(\.|\/)/;
70 const ANY_ID
= regex
.either(
71 DOUBLE_QUOTED_ID_REGEX
,
72 SINGLE_QUOTED_ID_REGEX
,
73 BRACKET_QUOTED_ID_REGEX
,
77 const IDENTIFIER_REGEX
= regex
.concat(
78 regex
.optional(/\.|\.\/|\//), // relative or absolute path
80 regex
.anyNumberOfTimes(regex
.concat(
86 // identifier followed by a equal-sign (without the equal sign)
87 const HASH_PARAM_REGEX
= regex
.concat(
89 BRACKET_QUOTED_ID_REGEX
, '|',
94 const HELPER_NAME_OR_PATH_EXPRESSION
= { begin: IDENTIFIER_REGEX
};
96 const HELPER_PARAMETER
= hljs
.inherit(HELPER_NAME_OR_PATH_EXPRESSION
, { keywords: LITERALS
});
98 const SUB_EXPRESSION
= {
101 // the "contains" is added below when all necessary sub-modes are defined
105 // fka "attribute-assignment", parameters of the form 'key=value'
107 begin: HASH_PARAM_REGEX
,
112 starts: { contains: [
114 hljs
.QUOTE_STRING_MODE
,
115 hljs
.APOS_STRING_MODE
,
122 const BLOCK_PARAMS
= {
123 // parameters of the form '{{#with x as | y |}}...{{/with}}'
125 keywords: { keyword: 'as' },
129 // define sub-mode in order to prevent highlighting of block-parameter named "as"
134 const HELPER_PARAMETERS
= {
137 hljs
.QUOTE_STRING_MODE
,
138 hljs
.APOS_STRING_MODE
,
145 // the property "end" is defined through inheritance when the mode is used. If depends
146 // on the surrounding mode, but "endsWithParent" does not work here (i.e. it includes the
147 // end-token of the surrounding mode)
150 const SUB_EXPRESSION_CONTENTS
= hljs
.inherit(HELPER_NAME_OR_PATH_EXPRESSION
, {
153 starts: hljs
.inherit(HELPER_PARAMETERS
, { end: /\)/ })
156 SUB_EXPRESSION
.contains
= [ SUB_EXPRESSION_CONTENTS
];
158 const OPENING_BLOCK_MUSTACHE_CONTENTS
= hljs
.inherit(HELPER_NAME_OR_PATH_EXPRESSION
, {
161 starts: hljs
.inherit(HELPER_PARAMETERS
, { end: /\}\}/ })
164 const CLOSING_BLOCK_MUSTACHE_CONTENTS
= hljs
.inherit(HELPER_NAME_OR_PATH_EXPRESSION
, {
169 const BASIC_MUSTACHE_CONTENTS
= hljs
.inherit(HELPER_NAME_OR_PATH_EXPRESSION
, {
172 starts: hljs
.inherit(HELPER_PARAMETERS
, { end: /\}\}/ })
175 const ESCAPE_MUSTACHE_WITH_PRECEEDING_BACKSLASH
= {
179 const PREVENT_ESCAPE_WITH_ANOTHER_PRECEEDING_BACKSLASH
= {
180 begin: /\\\\(?=\{\{)/,
192 case_insensitive: true,
195 ESCAPE_MUSTACHE_WITH_PRECEEDING_BACKSLASH
,
196 PREVENT_ESCAPE_WITH_ANOTHER_PRECEEDING_BACKSLASH
,
197 hljs
.COMMENT(/\{\{!--/, /--\}\}/),
198 hljs
.COMMENT(/\{\{!/, /\}\}/),
200 // open raw block "{{{{raw}}}} content not evaluated {{{{/raw}}}}"
201 className: 'template-tag',
202 begin: /\{\{\{\{(?!\/)/,
204 contains: [ OPENING_BLOCK_MUSTACHE_CONTENTS
],
213 className: 'template-tag',
216 contains: [ CLOSING_BLOCK_MUSTACHE_CONTENTS
]
219 // open block statement
220 className: 'template-tag',
223 contains: [ OPENING_BLOCK_MUSTACHE_CONTENTS
]
226 className: 'template-tag',
227 begin: /\{\{(?=else\}\})/,
232 className: 'template-tag',
233 begin: /\{\{(?=else if)/,
238 // closing block statement
239 className: 'template-tag',
242 contains: [ CLOSING_BLOCK_MUSTACHE_CONTENTS
]
245 // template variable or helper-call that is NOT html-escaped
246 className: 'template-variable',
249 contains: [ BASIC_MUSTACHE_CONTENTS
]
252 // template variable or helper-call that is html-escaped
253 className: 'template-variable',
256 contains: [ BASIC_MUSTACHE_CONTENTS
]
266 export default hljsGrammar
;