UNPKG

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