131 lines
3.3 KiB
JavaScript
131 lines
3.3 KiB
JavaScript
|
Prism.languages.markup = {
|
||
|
'comment': /<!--[\s\S]*?-->/,
|
||
|
'prolog': /<\?[\s\S]+?\?>/,
|
||
|
'doctype': {
|
||
|
// https://www.w3.org/TR/xml/#NT-doctypedecl
|
||
|
pattern: /<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,
|
||
|
greedy: true,
|
||
|
inside: {
|
||
|
'internal-subset': {
|
||
|
pattern: /(\[)[\s\S]+(?=\]>$)/,
|
||
|
lookbehind: true,
|
||
|
greedy: true,
|
||
|
inside: null // see below
|
||
|
},
|
||
|
'string': {
|
||
|
pattern: /"[^"]*"|'[^']*'/,
|
||
|
greedy: true
|
||
|
},
|
||
|
'punctuation': /^<!|>$|[[\]]/,
|
||
|
'doctype-tag': /^DOCTYPE/,
|
||
|
'name': /[^\s<>'"]+/
|
||
|
}
|
||
|
},
|
||
|
'cdata': /<!\[CDATA\[[\s\S]*?]]>/i,
|
||
|
'tag': {
|
||
|
pattern: /<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,
|
||
|
greedy: true,
|
||
|
inside: {
|
||
|
'tag': {
|
||
|
pattern: /^<\/?[^\s>\/]+/,
|
||
|
inside: {
|
||
|
'punctuation': /^<\/?/,
|
||
|
'namespace': /^[^\s>\/:]+:/
|
||
|
}
|
||
|
},
|
||
|
'attr-value': {
|
||
|
pattern: /=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,
|
||
|
inside: {
|
||
|
'punctuation': [
|
||
|
{
|
||
|
pattern: /^=/,
|
||
|
alias: 'attr-equals'
|
||
|
},
|
||
|
/"|'/
|
||
|
]
|
||
|
}
|
||
|
},
|
||
|
'punctuation': /\/?>/,
|
||
|
'attr-name': {
|
||
|
pattern: /[^\s>\/]+/,
|
||
|
inside: {
|
||
|
'namespace': /^[^\s>\/:]+:/
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
},
|
||
|
'entity': [
|
||
|
{
|
||
|
pattern: /&[\da-z]{1,8};/i,
|
||
|
alias: 'named-entity'
|
||
|
},
|
||
|
/&#x?[\da-f]{1,8};/i
|
||
|
]
|
||
|
};
|
||
|
|
||
|
Prism.languages.markup['tag'].inside['attr-value'].inside['entity'] =
|
||
|
Prism.languages.markup['entity'];
|
||
|
Prism.languages.markup['doctype'].inside['internal-subset'].inside = Prism.languages.markup;
|
||
|
|
||
|
// Plugin to make entity title show the real entity, idea by Roman Komarov
|
||
|
Prism.hooks.add('wrap', function (env) {
|
||
|
|
||
|
if (env.type === 'entity') {
|
||
|
env.attributes['title'] = env.content.replace(/&/, '&');
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Object.defineProperty(Prism.languages.markup.tag, 'addInlined', {
|
||
|
/**
|
||
|
* Adds an inlined language to markup.
|
||
|
*
|
||
|
* An example of an inlined language is CSS with `<style>` tags.
|
||
|
*
|
||
|
* @param {string} tagName The name of the tag that contains the inlined language. This name will be treated as
|
||
|
* case insensitive.
|
||
|
* @param {string} lang The language key.
|
||
|
* @example
|
||
|
* addInlined('style', 'css');
|
||
|
*/
|
||
|
value: function addInlined(tagName, lang) {
|
||
|
var includedCdataInside = {};
|
||
|
includedCdataInside['language-' + lang] = {
|
||
|
pattern: /(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,
|
||
|
lookbehind: true,
|
||
|
inside: Prism.languages[lang]
|
||
|
};
|
||
|
includedCdataInside['cdata'] = /^<!\[CDATA\[|\]\]>$/i;
|
||
|
|
||
|
var inside = {
|
||
|
'included-cdata': {
|
||
|
pattern: /<!\[CDATA\[[\s\S]*?\]\]>/i,
|
||
|
inside: includedCdataInside
|
||
|
}
|
||
|
};
|
||
|
inside['language-' + lang] = {
|
||
|
pattern: /[\s\S]+/,
|
||
|
inside: Prism.languages[lang]
|
||
|
};
|
||
|
|
||
|
var def = {};
|
||
|
def[tagName] = {
|
||
|
pattern: RegExp(/(<__[\s\S]*?>)(?:<!\[CDATA\[(?:[^\]]|\](?!\]>))*\]\]>|(?!<!\[CDATA\[)[\s\S])*?(?=<\/__>)/.source.replace(/__/g, function () { return tagName; }), 'i'),
|
||
|
lookbehind: true,
|
||
|
greedy: true,
|
||
|
inside: inside
|
||
|
};
|
||
|
|
||
|
Prism.languages.insertBefore('markup', 'cdata', def);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Prism.languages.html = Prism.languages.markup;
|
||
|
Prism.languages.mathml = Prism.languages.markup;
|
||
|
Prism.languages.svg = Prism.languages.markup;
|
||
|
|
||
|
Prism.languages.xml = Prism.languages.extend('markup', {});
|
||
|
Prism.languages.ssml = Prism.languages.xml;
|
||
|
Prism.languages.atom = Prism.languages.xml;
|
||
|
Prism.languages.rss = Prism.languages.xml;
|