UNPKG

2.72 kBJavaScriptView Raw
1Prism.languages.markup = {
2 'comment': /<!--[\s\S]*?-->/,
3 'prolog': /<\?[\s\S]+?\?>/,
4 'doctype': {
5 pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:(?!<!--)[^"'\]]|"[^"]*"|'[^']*'|<!--[\s\S]*?-->)*\]\s*)?>/i,
6 greedy: true
7 },
8 'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
9 'tag': {
10 pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/i,
11 greedy: true,
12 inside: {
13 'tag': {
14 pattern: /^<\/?[^\s>\/]+/i,
15 inside: {
16 'punctuation': /^<\/?/,
17 'namespace': /^[^\s>\/:]+:/
18 }
19 },
20 'attr-value': {
21 pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/i,
22 inside: {
23 'punctuation': [
24 /^=/,
25 {
26 pattern: /^(\s*)["']|["']$/,
27 lookbehind: true
28 }
29 ]
30 }
31 },
32 'punctuation': /\/?>/,
33 'attr-name': {
34 pattern: /[^\s>\/]+/,
35 inside: {
36 'namespace': /^[^\s>\/:]+:/
37 }
38 }
39
40 }
41 },
42 'entity': /&#?[\da-z]{1,8};/i
43};
44
45Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
46 Prism.languages.markup['entity'];
47
48// Plugin to make entity title show the real entity, idea by Roman Komarov
49Prism.hooks.add('wrap', function(env) {
50
51 if (env.type === 'entity') {
52 env.attributes['title'] = env.content.replace(/&amp;/, '&');
53 }
54});
55
56Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
57 /**
58 * Adds an inlined language to markup.
59 *
60 * An example of an inlined language is CSS with `<style>` tags.
61 *
62 * @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
63 * case insensitive.
64 * @param {string} lang The language key.
65 * @example
66 * addInlined('style', 'css');
67 */
68 value: function addInlined(tagName, lang) {
69 var includedCdataInside = {};
70 includedCdataInside['language-' + lang] = {
71 pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
72 lookbehind: true,
73 inside: Prism.languages[lang]
74 };
75 includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
76
77 var inside = {
78 'included-cdata': {
79 pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
80 inside: includedCdataInside
81 }
82 };
83 inside['language-' + lang] = {
84 pattern: /[\s\S]+/,
85 inside: Prism.languages[lang]
86 };
87
88 var def = {};
89 def[tagName] = {
90 pattern: RegExp(/(<__[\s\S]*?>)(?:<!\[CDATA\[[\s\S]*?\]\]>\s*|[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
91 lookbehind: true,
92 greedy: true,
93 inside: inside
94 };
95
96 Prism.languages.insertBefore('markup', 'cdata', def);
97 }
98});
99
100Prism.languages.xml = Prism.languages.extend('markup', {});
101Prism.languages.html = Prism.languages.markup;
102Prism.languages.mathml = Prism.languages.markup;
103Prism.languages.svg = Prism.languages.markup;