The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

822 line
23KB

  1. /*
  2. Syntax highlighting with language autodetection.
  3. https://highlightjs.org/
  4. */
  5. (function(factory) {
  6. // Find the global object for export to both the browser and web workers.
  7. var globalObject = typeof window === 'object' && window ||
  8. typeof self === 'object' && self;
  9. // Setup highlight.js for different environments. First is Node.js or
  10. // CommonJS.
  11. if(typeof exports !== 'undefined') {
  12. factory(exports);
  13. } else if(globalObject) {
  14. // Export hljs globally even when using AMD for cases when this script
  15. // is loaded with others that may still expect a global hljs.
  16. globalObject.hljs = factory({});
  17. // Finally register the global hljs with AMD.
  18. if(typeof define === 'function' && define.amd) {
  19. define([], function() {
  20. return globalObject.hljs;
  21. });
  22. }
  23. }
  24. }(function(hljs) {
  25. // Convenience variables for build-in objects
  26. var ArrayProto = [],
  27. objectKeys = Object.keys;
  28. // Global internal variables used within the highlight.js library.
  29. var languages = {},
  30. aliases = {};
  31. // Regular expressions used throughout the highlight.js library.
  32. var noHighlightRe = /^(no-?highlight|plain|text)$/i,
  33. languagePrefixRe = /\blang(?:uage)?-([\w-]+)\b/i,
  34. fixMarkupRe = /((^(<[^>]+>|\t|)+|(?:\n)))/gm;
  35. var spanEndTag = '</span>';
  36. // Global options used when within external APIs. This is modified when
  37. // calling the `hljs.configure` function.
  38. var options = {
  39. classPrefix: 'hljs-',
  40. tabReplace: null,
  41. useBR: false,
  42. languages: undefined
  43. };
  44. // Object map that is used to escape some common HTML characters.
  45. var escapeRegexMap = {
  46. '&': '&amp;',
  47. '<': '&lt;',
  48. '>': '&gt;'
  49. };
  50. /* Utility functions */
  51. function escape(value) {
  52. return value.replace(/[&<>]/gm, function(character) {
  53. return escapeRegexMap[character];
  54. });
  55. }
  56. function tag(node) {
  57. return node.nodeName.toLowerCase();
  58. }
  59. function testRe(re, lexeme) {
  60. var match = re && re.exec(lexeme);
  61. return match && match.index === 0;
  62. }
  63. function isNotHighlighted(language) {
  64. return noHighlightRe.test(language);
  65. }
  66. function blockLanguage(block) {
  67. var i, match, length, _class;
  68. var classes = block.className + ' ';
  69. classes += block.parentNode ? block.parentNode.className : '';
  70. // language-* takes precedence over non-prefixed class names.
  71. match = languagePrefixRe.exec(classes);
  72. if (match) {
  73. return getLanguage(match[1]) ? match[1] : 'no-highlight';
  74. }
  75. classes = classes.split(/\s+/);
  76. for (i = 0, length = classes.length; i < length; i++) {
  77. _class = classes[i]
  78. if (isNotHighlighted(_class) || getLanguage(_class)) {
  79. return _class;
  80. }
  81. }
  82. }
  83. function inherit(parent, obj) {
  84. var key;
  85. var result = {};
  86. for (key in parent)
  87. result[key] = parent[key];
  88. if (obj)
  89. for (key in obj)
  90. result[key] = obj[key];
  91. return result;
  92. }
  93. /* Stream merging */
  94. function nodeStream(node) {
  95. var result = [];
  96. (function _nodeStream(node, offset) {
  97. for (var child = node.firstChild; child; child = child.nextSibling) {
  98. if (child.nodeType === 3)
  99. offset += child.nodeValue.length;
  100. else if (child.nodeType === 1) {
  101. result.push({
  102. event: 'start',
  103. offset: offset,
  104. node: child
  105. });
  106. offset = _nodeStream(child, offset);
  107. // Prevent void elements from having an end tag that would actually
  108. // double them in the output. There are more void elements in HTML
  109. // but we list only those realistically expected in code display.
  110. if (!tag(child).match(/br|hr|img|input/)) {
  111. result.push({
  112. event: 'stop',
  113. offset: offset,
  114. node: child
  115. });
  116. }
  117. }
  118. }
  119. return offset;
  120. })(node, 0);
  121. return result;
  122. }
  123. function mergeStreams(original, highlighted, value) {
  124. var processed = 0;
  125. var result = '';
  126. var nodeStack = [];
  127. function selectStream() {
  128. if (!original.length || !highlighted.length) {
  129. return original.length ? original : highlighted;
  130. }
  131. if (original[0].offset !== highlighted[0].offset) {
  132. return (original[0].offset < highlighted[0].offset) ? original : highlighted;
  133. }
  134. /*
  135. To avoid starting the stream just before it should stop the order is
  136. ensured that original always starts first and closes last:
  137. if (event1 == 'start' && event2 == 'start')
  138. return original;
  139. if (event1 == 'start' && event2 == 'stop')
  140. return highlighted;
  141. if (event1 == 'stop' && event2 == 'start')
  142. return original;
  143. if (event1 == 'stop' && event2 == 'stop')
  144. return highlighted;
  145. ... which is collapsed to:
  146. */
  147. return highlighted[0].event === 'start' ? original : highlighted;
  148. }
  149. function open(node) {
  150. function attr_str(a) {return ' ' + a.nodeName + '="' + escape(a.value) + '"';}
  151. result += '<' + tag(node) + ArrayProto.map.call(node.attributes, attr_str).join('') + '>';
  152. }
  153. function close(node) {
  154. result += '</' + tag(node) + '>';
  155. }
  156. function render(event) {
  157. (event.event === 'start' ? open : close)(event.node);
  158. }
  159. while (original.length || highlighted.length) {
  160. var stream = selectStream();
  161. result += escape(value.substring(processed, stream[0].offset));
  162. processed = stream[0].offset;
  163. if (stream === original) {
  164. /*
  165. On any opening or closing tag of the original markup we first close
  166. the entire highlighted node stack, then render the original tag along
  167. with all the following original tags at the same offset and then
  168. reopen all the tags on the highlighted stack.
  169. */
  170. nodeStack.reverse().forEach(close);
  171. do {
  172. render(stream.splice(0, 1)[0]);
  173. stream = selectStream();
  174. } while (stream === original && stream.length && stream[0].offset === processed);
  175. nodeStack.reverse().forEach(open);
  176. } else {
  177. if (stream[0].event === 'start') {
  178. nodeStack.push(stream[0].node);
  179. } else {
  180. nodeStack.pop();
  181. }
  182. render(stream.splice(0, 1)[0]);
  183. }
  184. }
  185. return result + escape(value.substr(processed));
  186. }
  187. /* Initialization */
  188. function compileLanguage(language) {
  189. function reStr(re) {
  190. return (re && re.source) || re;
  191. }
  192. function langRe(value, global) {
  193. return new RegExp(
  194. reStr(value),
  195. 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '')
  196. );
  197. }
  198. function compileMode(mode, parent) {
  199. if (mode.compiled)
  200. return;
  201. mode.compiled = true;
  202. mode.keywords = mode.keywords || mode.beginKeywords;
  203. if (mode.keywords) {
  204. var compiled_keywords = {};
  205. var flatten = function(className, str) {
  206. if (language.case_insensitive) {
  207. str = str.toLowerCase();
  208. }
  209. str.split(' ').forEach(function(kw) {
  210. var pair = kw.split('|');
  211. compiled_keywords[pair[0]] = [className, pair[1] ? Number(pair[1]) : 1];
  212. });
  213. };
  214. if (typeof mode.keywords === 'string') { // string
  215. flatten('keyword', mode.keywords);
  216. } else {
  217. objectKeys(mode.keywords).forEach(function (className) {
  218. flatten(className, mode.keywords[className]);
  219. });
  220. }
  221. mode.keywords = compiled_keywords;
  222. }
  223. mode.lexemesRe = langRe(mode.lexemes || /\w+/, true);
  224. if (parent) {
  225. if (mode.beginKeywords) {
  226. mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')\\b';
  227. }
  228. if (!mode.begin)
  229. mode.begin = /\B|\b/;
  230. mode.beginRe = langRe(mode.begin);
  231. if (!mode.end && !mode.endsWithParent)
  232. mode.end = /\B|\b/;
  233. if (mode.end)
  234. mode.endRe = langRe(mode.end);
  235. mode.terminator_end = reStr(mode.end) || '';
  236. if (mode.endsWithParent && parent.terminator_end)
  237. mode.terminator_end += (mode.end ? '|' : '') + parent.terminator_end;
  238. }
  239. if (mode.illegal)
  240. mode.illegalRe = langRe(mode.illegal);
  241. if (mode.relevance == null)
  242. mode.relevance = 1;
  243. if (!mode.contains) {
  244. mode.contains = [];
  245. }
  246. var expanded_contains = [];
  247. mode.contains.forEach(function(c) {
  248. if (c.variants) {
  249. c.variants.forEach(function(v) {expanded_contains.push(inherit(c, v));});
  250. } else {
  251. expanded_contains.push(c === 'self' ? mode : c);
  252. }
  253. });
  254. mode.contains = expanded_contains;
  255. mode.contains.forEach(function(c) {compileMode(c, mode);});
  256. if (mode.starts) {
  257. compileMode(mode.starts, parent);
  258. }
  259. var terminators =
  260. mode.contains.map(function(c) {
  261. return c.beginKeywords ? '\\.?(' + c.begin + ')\\.?' : c.begin;
  262. })
  263. .concat([mode.terminator_end, mode.illegal])
  264. .map(reStr)
  265. .filter(Boolean);
  266. mode.terminators = terminators.length ? langRe(terminators.join('|'), true) : {exec: function(/*s*/) {return null;}};
  267. }
  268. compileMode(language);
  269. }
  270. /*
  271. Core highlighting function. Accepts a language name, or an alias, and a
  272. string with the code to highlight. Returns an object with the following
  273. properties:
  274. - relevance (int)
  275. - value (an HTML string with highlighting markup)
  276. */
  277. function highlight(name, value, ignore_illegals, continuation) {
  278. function subMode(lexeme, mode) {
  279. var i, length;
  280. for (i = 0, length = mode.contains.length; i < length; i++) {
  281. if (testRe(mode.contains[i].beginRe, lexeme)) {
  282. return mode.contains[i];
  283. }
  284. }
  285. }
  286. function endOfMode(mode, lexeme) {
  287. if (testRe(mode.endRe, lexeme)) {
  288. while (mode.endsParent && mode.parent) {
  289. mode = mode.parent;
  290. }
  291. return mode;
  292. }
  293. if (mode.endsWithParent) {
  294. return endOfMode(mode.parent, lexeme);
  295. }
  296. }
  297. function isIllegal(lexeme, mode) {
  298. return !ignore_illegals && testRe(mode.illegalRe, lexeme);
  299. }
  300. function keywordMatch(mode, match) {
  301. var match_str = language.case_insensitive ? match[0].toLowerCase() : match[0];
  302. return mode.keywords.hasOwnProperty(match_str) && mode.keywords[match_str];
  303. }
  304. function buildSpan(classname, insideSpan, leaveOpen, noPrefix) {
  305. var classPrefix = noPrefix ? '' : options.classPrefix,
  306. openSpan = '<span class="' + classPrefix,
  307. closeSpan = leaveOpen ? '' : spanEndTag
  308. openSpan += classname + '">';
  309. return openSpan + insideSpan + closeSpan;
  310. }
  311. function processKeywords() {
  312. var keyword_match, last_index, match, result;
  313. if (!top.keywords)
  314. return escape(mode_buffer);
  315. result = '';
  316. last_index = 0;
  317. top.lexemesRe.lastIndex = 0;
  318. match = top.lexemesRe.exec(mode_buffer);
  319. while (match) {
  320. result += escape(mode_buffer.substring(last_index, match.index));
  321. keyword_match = keywordMatch(top, match);
  322. if (keyword_match) {
  323. relevance += keyword_match[1];
  324. result += buildSpan(keyword_match[0], escape(match[0]));
  325. } else {
  326. result += escape(match[0]);
  327. }
  328. last_index = top.lexemesRe.lastIndex;
  329. match = top.lexemesRe.exec(mode_buffer);
  330. }
  331. return result + escape(mode_buffer.substr(last_index));
  332. }
  333. function processSubLanguage() {
  334. var explicit = typeof top.subLanguage === 'string';
  335. if (explicit && !languages[top.subLanguage]) {
  336. return escape(mode_buffer);
  337. }
  338. var result = explicit ?
  339. highlight(top.subLanguage, mode_buffer, true, continuations[top.subLanguage]) :
  340. highlightAuto(mode_buffer, top.subLanguage.length ? top.subLanguage : undefined);
  341. // Counting embedded language score towards the host language may be disabled
  342. // with zeroing the containing mode relevance. Usecase in point is Markdown that
  343. // allows XML everywhere and makes every XML snippet to have a much larger Markdown
  344. // score.
  345. if (top.relevance > 0) {
  346. relevance += result.relevance;
  347. }
  348. if (explicit) {
  349. continuations[top.subLanguage] = result.top;
  350. }
  351. return buildSpan(result.language, result.value, false, true);
  352. }
  353. function processBuffer() {
  354. result += (top.subLanguage != null ? processSubLanguage() : processKeywords());
  355. mode_buffer = '';
  356. }
  357. function startNewMode(mode) {
  358. result += mode.className? buildSpan(mode.className, '', true): '';
  359. top = Object.create(mode, {parent: {value: top}});
  360. }
  361. function processLexeme(buffer, lexeme) {
  362. mode_buffer += buffer;
  363. if (lexeme == null) {
  364. processBuffer();
  365. return 0;
  366. }
  367. var new_mode = subMode(lexeme, top);
  368. if (new_mode) {
  369. if (new_mode.skip) {
  370. mode_buffer += lexeme;
  371. } else {
  372. if (new_mode.excludeBegin) {
  373. mode_buffer += lexeme;
  374. }
  375. processBuffer();
  376. if (!new_mode.returnBegin && !new_mode.excludeBegin) {
  377. mode_buffer = lexeme;
  378. }
  379. }
  380. startNewMode(new_mode, lexeme);
  381. return new_mode.returnBegin ? 0 : lexeme.length;
  382. }
  383. var end_mode = endOfMode(top, lexeme);
  384. if (end_mode) {
  385. var origin = top;
  386. if (origin.skip) {
  387. mode_buffer += lexeme;
  388. } else {
  389. if (!(origin.returnEnd || origin.excludeEnd)) {
  390. mode_buffer += lexeme;
  391. }
  392. processBuffer();
  393. if (origin.excludeEnd) {
  394. mode_buffer = lexeme;
  395. }
  396. }
  397. do {
  398. if (top.className) {
  399. result += spanEndTag;
  400. }
  401. if (!top.skip) {
  402. relevance += top.relevance;
  403. }
  404. top = top.parent;
  405. } while (top !== end_mode.parent);
  406. if (end_mode.starts) {
  407. startNewMode(end_mode.starts, '');
  408. }
  409. return origin.returnEnd ? 0 : lexeme.length;
  410. }
  411. if (isIllegal(lexeme, top))
  412. throw new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.className || '<unnamed>') + '"');
  413. /*
  414. Parser should not reach this point as all types of lexemes should be caught
  415. earlier, but if it does due to some bug make sure it advances at least one
  416. character forward to prevent infinite looping.
  417. */
  418. mode_buffer += lexeme;
  419. return lexeme.length || 1;
  420. }
  421. var language = getLanguage(name);
  422. if (!language) {
  423. throw new Error('Unknown language: "' + name + '"');
  424. }
  425. compileLanguage(language);
  426. var top = continuation || language;
  427. var continuations = {}; // keep continuations for sub-languages
  428. var result = '', current;
  429. for(current = top; current !== language; current = current.parent) {
  430. if (current.className) {
  431. result = buildSpan(current.className, '', true) + result;
  432. }
  433. }
  434. var mode_buffer = '';
  435. var relevance = 0;
  436. try {
  437. var match, count, index = 0;
  438. while (true) {
  439. top.terminators.lastIndex = index;
  440. match = top.terminators.exec(value);
  441. if (!match)
  442. break;
  443. count = processLexeme(value.substring(index, match.index), match[0]);
  444. index = match.index + count;
  445. }
  446. processLexeme(value.substr(index));
  447. for(current = top; current.parent; current = current.parent) { // close dangling modes
  448. if (current.className) {
  449. result += spanEndTag;
  450. }
  451. }
  452. return {
  453. relevance: relevance,
  454. value: result,
  455. language: name,
  456. top: top
  457. };
  458. } catch (e) {
  459. if (e.message && e.message.indexOf('Illegal') !== -1) {
  460. return {
  461. relevance: 0,
  462. value: escape(value)
  463. };
  464. } else {
  465. throw e;
  466. }
  467. }
  468. }
  469. /*
  470. Highlighting with language detection. Accepts a string with the code to
  471. highlight. Returns an object with the following properties:
  472. - language (detected language)
  473. - relevance (int)
  474. - value (an HTML string with highlighting markup)
  475. - second_best (object with the same structure for second-best heuristically
  476. detected language, may be absent)
  477. */
  478. function highlightAuto(text, languageSubset) {
  479. languageSubset = languageSubset || options.languages || objectKeys(languages);
  480. var result = {
  481. relevance: 0,
  482. value: escape(text)
  483. };
  484. var second_best = result;
  485. languageSubset.filter(getLanguage).forEach(function(name) {
  486. var current = highlight(name, text, false);
  487. current.language = name;
  488. if (current.relevance > second_best.relevance) {
  489. second_best = current;
  490. }
  491. if (current.relevance > result.relevance) {
  492. second_best = result;
  493. result = current;
  494. }
  495. });
  496. if (second_best.language) {
  497. result.second_best = second_best;
  498. }
  499. return result;
  500. }
  501. /*
  502. Post-processing of the highlighted markup:
  503. - replace TABs with something more useful
  504. - replace real line-breaks with '<br>' for non-pre containers
  505. */
  506. function fixMarkup(value) {
  507. return !(options.tabReplace || options.useBR)
  508. ? value
  509. : value.replace(fixMarkupRe, function(match, p1) {
  510. if (options.useBR && match === '\n') {
  511. return '<br>';
  512. } else if (options.tabReplace) {
  513. return p1.replace(/\t/g, options.tabReplace);
  514. }
  515. else{
  516. return p1;
  517. }
  518. });
  519. }
  520. function buildClassName(prevClassName, currentLang, resultLang) {
  521. var language = currentLang ? aliases[currentLang] : resultLang,
  522. result = [prevClassName.trim()];
  523. if (!prevClassName.match(/\bhljs\b/)) {
  524. result.push('hljs');
  525. }
  526. if (prevClassName.indexOf(language) === -1) {
  527. result.push(language);
  528. }
  529. return result.join(' ').trim();
  530. }
  531. /*
  532. Applies highlighting to a DOM node containing code. Accepts a DOM node and
  533. two optional parameters for fixMarkup.
  534. */
  535. function highlightBlock(block) {
  536. var node, originalStream, result, resultNode, text;
  537. var language = blockLanguage(block);
  538. if (isNotHighlighted(language))
  539. return;
  540. if (options.useBR) {
  541. node = document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
  542. node.innerHTML = block.innerHTML.replace(/\n/g, '').replace(/<br[ \/]*>/g, '\n');
  543. } else {
  544. node = block;
  545. }
  546. text = node.textContent;
  547. result = language ? highlight(language, text, true) : highlightAuto(text);
  548. originalStream = nodeStream(node);
  549. if (originalStream.length) {
  550. resultNode = document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
  551. resultNode.innerHTML = result.value;
  552. result.value = mergeStreams(originalStream, nodeStream(resultNode), text);
  553. }
  554. result.value = fixMarkup(result.value);
  555. block.innerHTML = result.value;
  556. block.className = buildClassName(block.className, language, result.language);
  557. block.result = {
  558. language: result.language,
  559. re: result.relevance
  560. };
  561. if (result.second_best) {
  562. block.second_best = {
  563. language: result.second_best.language,
  564. re: result.second_best.relevance
  565. };
  566. }
  567. }
  568. /*
  569. Updates highlight.js global options with values passed in the form of an object.
  570. */
  571. function configure(user_options) {
  572. options = inherit(options, user_options);
  573. }
  574. /*
  575. Applies highlighting to all <pre><code>..</code></pre> blocks on a page.
  576. */
  577. function initHighlighting() {
  578. if (initHighlighting.called)
  579. return;
  580. initHighlighting.called = true;
  581. var blocks = document.querySelectorAll('pre code');
  582. ArrayProto.forEach.call(blocks, highlightBlock);
  583. }
  584. /*
  585. Attaches highlighting to the page load event.
  586. */
  587. function initHighlightingOnLoad() {
  588. addEventListener('DOMContentLoaded', initHighlighting, false);
  589. addEventListener('load', initHighlighting, false);
  590. }
  591. function registerLanguage(name, language) {
  592. var lang = languages[name] = language(hljs);
  593. if (lang.aliases) {
  594. lang.aliases.forEach(function(alias) {aliases[alias] = name;});
  595. }
  596. }
  597. function listLanguages() {
  598. return objectKeys(languages);
  599. }
  600. function getLanguage(name) {
  601. name = (name || '').toLowerCase();
  602. return languages[name] || languages[aliases[name]];
  603. }
  604. /* Interface definition */
  605. hljs.highlight = highlight;
  606. hljs.highlightAuto = highlightAuto;
  607. hljs.fixMarkup = fixMarkup;
  608. hljs.highlightBlock = highlightBlock;
  609. hljs.configure = configure;
  610. hljs.initHighlighting = initHighlighting;
  611. hljs.initHighlightingOnLoad = initHighlightingOnLoad;
  612. hljs.registerLanguage = registerLanguage;
  613. hljs.listLanguages = listLanguages;
  614. hljs.getLanguage = getLanguage;
  615. hljs.inherit = inherit;
  616. // Common regexps
  617. hljs.IDENT_RE = '[a-zA-Z]\\w*';
  618. hljs.UNDERSCORE_IDENT_RE = '[a-zA-Z_]\\w*';
  619. hljs.NUMBER_RE = '\\b\\d+(\\.\\d+)?';
  620. hljs.C_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)'; // 0x..., 0..., decimal, float
  621. hljs.BINARY_NUMBER_RE = '\\b(0b[01]+)'; // 0b...
  622. hljs.RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~';
  623. // Common modes
  624. hljs.BACKSLASH_ESCAPE = {
  625. begin: '\\\\[\\s\\S]', relevance: 0
  626. };
  627. hljs.APOS_STRING_MODE = {
  628. className: 'string',
  629. begin: '\'', end: '\'',
  630. illegal: '\\n',
  631. contains: [hljs.BACKSLASH_ESCAPE]
  632. };
  633. hljs.QUOTE_STRING_MODE = {
  634. className: 'string',
  635. begin: '"', end: '"',
  636. illegal: '\\n',
  637. contains: [hljs.BACKSLASH_ESCAPE]
  638. };
  639. hljs.PHRASAL_WORDS_MODE = {
  640. begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|like)\b/
  641. };
  642. hljs.COMMENT = function (begin, end, inherits) {
  643. var mode = hljs.inherit(
  644. {
  645. className: 'comment',
  646. begin: begin, end: end,
  647. contains: []
  648. },
  649. inherits || {}
  650. );
  651. mode.contains.push(hljs.PHRASAL_WORDS_MODE);
  652. mode.contains.push({
  653. className: 'doctag',
  654. begin: '(?:TODO|FIXME|NOTE|BUG|XXX):',
  655. relevance: 0
  656. });
  657. return mode;
  658. };
  659. hljs.C_LINE_COMMENT_MODE = hljs.COMMENT('//', '$');
  660. hljs.C_BLOCK_COMMENT_MODE = hljs.COMMENT('/\\*', '\\*/');
  661. hljs.HASH_COMMENT_MODE = hljs.COMMENT('#', '$');
  662. hljs.NUMBER_MODE = {
  663. className: 'number',
  664. begin: hljs.NUMBER_RE,
  665. relevance: 0
  666. };
  667. hljs.C_NUMBER_MODE = {
  668. className: 'number',
  669. begin: hljs.C_NUMBER_RE,
  670. relevance: 0
  671. };
  672. hljs.BINARY_NUMBER_MODE = {
  673. className: 'number',
  674. begin: hljs.BINARY_NUMBER_RE,
  675. relevance: 0
  676. };
  677. hljs.CSS_NUMBER_MODE = {
  678. className: 'number',
  679. begin: hljs.NUMBER_RE + '(' +
  680. '%|em|ex|ch|rem' +
  681. '|vw|vh|vmin|vmax' +
  682. '|cm|mm|in|pt|pc|px' +
  683. '|deg|grad|rad|turn' +
  684. '|s|ms' +
  685. '|Hz|kHz' +
  686. '|dpi|dpcm|dppx' +
  687. ')?',
  688. relevance: 0
  689. };
  690. hljs.REGEXP_MODE = {
  691. className: 'regexp',
  692. begin: /\//, end: /\/[gimuy]*/,
  693. illegal: /\n/,
  694. contains: [
  695. hljs.BACKSLASH_ESCAPE,
  696. {
  697. begin: /\[/, end: /\]/,
  698. relevance: 0,
  699. contains: [hljs.BACKSLASH_ESCAPE]
  700. }
  701. ]
  702. };
  703. hljs.TITLE_MODE = {
  704. className: 'title',
  705. begin: hljs.IDENT_RE,
  706. relevance: 0
  707. };
  708. hljs.UNDERSCORE_TITLE_MODE = {
  709. className: 'title',
  710. begin: hljs.UNDERSCORE_IDENT_RE,
  711. relevance: 0
  712. };
  713. hljs.METHOD_GUARD = {
  714. // excludes method names from keyword processing
  715. begin: '\\.\\s*' + hljs.UNDERSCORE_IDENT_RE,
  716. relevance: 0
  717. };
  718. return hljs;
  719. }));