1 | (function () {
|
---|
2 |
|
---|
3 | if (typeof Prism === 'undefined') {
|
---|
4 | return;
|
---|
5 | }
|
---|
6 |
|
---|
7 | if (Prism.languages.css) {
|
---|
8 | // check whether the selector is an advanced pattern before extending it
|
---|
9 | if (Prism.languages.css.selector.pattern) {
|
---|
10 | Prism.languages.css.selector.inside['pseudo-class'] = /:[\w-]+/;
|
---|
11 | Prism.languages.css.selector.inside['pseudo-element'] = /::[\w-]+/;
|
---|
12 | } else {
|
---|
13 | Prism.languages.css.selector = {
|
---|
14 | pattern: Prism.languages.css.selector,
|
---|
15 | inside: {
|
---|
16 | 'pseudo-class': /:[\w-]+/,
|
---|
17 | 'pseudo-element': /::[\w-]+/
|
---|
18 | }
|
---|
19 | };
|
---|
20 | }
|
---|
21 | }
|
---|
22 |
|
---|
23 | if (Prism.languages.markup) {
|
---|
24 | Prism.languages.markup.tag.inside.tag.inside['tag-id'] = /[\w-]+/;
|
---|
25 |
|
---|
26 | var Tags = {
|
---|
27 | HTML: {
|
---|
28 | 'a': 1, 'abbr': 1, 'acronym': 1, 'b': 1, 'basefont': 1, 'bdo': 1, 'big': 1, 'blink': 1, 'cite': 1, 'code': 1, 'dfn': 1, 'em': 1, 'kbd': 1, 'i': 1,
|
---|
29 | 'rp': 1, 'rt': 1, 'ruby': 1, 's': 1, 'samp': 1, 'small': 1, 'spacer': 1, 'strike': 1, 'strong': 1, 'sub': 1, 'sup': 1, 'time': 1, 'tt': 1, 'u': 1,
|
---|
30 | 'var': 1, 'wbr': 1, 'noframes': 1, 'summary': 1, 'command': 1, 'dt': 1, 'dd': 1, 'figure': 1, 'figcaption': 1, 'center': 1, 'section': 1, 'nav': 1,
|
---|
31 | 'article': 1, 'aside': 1, 'hgroup': 1, 'header': 1, 'footer': 1, 'address': 1, 'noscript': 1, 'isIndex': 1, 'main': 1, 'mark': 1, 'marquee': 1,
|
---|
32 | 'meter': 1, 'menu': 1
|
---|
33 | },
|
---|
34 | SVG: {
|
---|
35 | 'animateColor': 1, 'animateMotion': 1, 'animateTransform': 1, 'glyph': 1, 'feBlend': 1, 'feColorMatrix': 1, 'feComponentTransfer': 1,
|
---|
36 | 'feFuncR': 1, 'feFuncG': 1, 'feFuncB': 1, 'feFuncA': 1, 'feComposite': 1, 'feConvolveMatrix': 1, 'feDiffuseLighting': 1, 'feDisplacementMap': 1,
|
---|
37 | 'feFlood': 1, 'feGaussianBlur': 1, 'feImage': 1, 'feMerge': 1, 'feMergeNode': 1, 'feMorphology': 1, 'feOffset': 1, 'feSpecularLighting': 1,
|
---|
38 | 'feTile': 1, 'feTurbulence': 1, 'feDistantLight': 1, 'fePointLight': 1, 'feSpotLight': 1, 'linearGradient': 1, 'radialGradient': 1, 'altGlyph': 1,
|
---|
39 | 'textPath': 1, 'tref': 1, 'altglyph': 1, 'textpath': 1, 'altglyphdef': 1, 'altglyphitem': 1, 'clipPath': 1, 'color-profile': 1, 'cursor': 1,
|
---|
40 | 'font-face': 1, 'font-face-format': 1, 'font-face-name': 1, 'font-face-src': 1, 'font-face-uri': 1, 'foreignObject': 1, 'glyphRef': 1,
|
---|
41 | 'hkern': 1, 'vkern': 1
|
---|
42 | },
|
---|
43 | MathML: {}
|
---|
44 | };
|
---|
45 | }
|
---|
46 |
|
---|
47 | var language;
|
---|
48 |
|
---|
49 | Prism.hooks.add('wrap', function (env) {
|
---|
50 | if ((env.type == 'tag-id'
|
---|
51 | || (env.type == 'property' && env.content.indexOf('-') != 0)
|
---|
52 | || (env.type == 'rule' && env.content.indexOf('@-') != 0)
|
---|
53 | || (env.type == 'pseudo-class' && env.content.indexOf(':-') != 0)
|
---|
54 | || (env.type == 'pseudo-element' && env.content.indexOf('::-') != 0)
|
---|
55 | || (env.type == 'attr-name' && env.content.indexOf('data-') != 0)
|
---|
56 | ) && env.content.indexOf('<') === -1
|
---|
57 | ) {
|
---|
58 | if (env.language == 'css'
|
---|
59 | || env.language == 'scss'
|
---|
60 | || env.language == 'markup'
|
---|
61 | ) {
|
---|
62 | var href = 'https://webplatform.github.io/docs/';
|
---|
63 | var content = env.content;
|
---|
64 |
|
---|
65 | if (env.language == 'css' || env.language == 'scss') {
|
---|
66 | href += 'css/';
|
---|
67 |
|
---|
68 | if (env.type == 'property') {
|
---|
69 | href += 'properties/';
|
---|
70 | } else if (env.type == 'rule') {
|
---|
71 | href += 'atrules/';
|
---|
72 | content = content.substring(1);
|
---|
73 | } else if (env.type == 'pseudo-class') {
|
---|
74 | href += 'selectors/pseudo-classes/';
|
---|
75 | content = content.substring(1);
|
---|
76 | } else if (env.type == 'pseudo-element') {
|
---|
77 | href += 'selectors/pseudo-elements/';
|
---|
78 | content = content.substring(2);
|
---|
79 | }
|
---|
80 | } else if (env.language == 'markup') {
|
---|
81 | if (env.type == 'tag-id') {
|
---|
82 | // Check language
|
---|
83 | language = getLanguage(env.content) || language;
|
---|
84 |
|
---|
85 | if (language) {
|
---|
86 | href += language + '/elements/';
|
---|
87 | } else {
|
---|
88 | return; // Abort
|
---|
89 | }
|
---|
90 | } else if (env.type == 'attr-name') {
|
---|
91 | if (language) {
|
---|
92 | href += language + '/attributes/';
|
---|
93 | } else {
|
---|
94 | return; // Abort
|
---|
95 | }
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | href += content;
|
---|
100 | env.tag = 'a';
|
---|
101 | env.attributes.href = href;
|
---|
102 | env.attributes.target = '_blank';
|
---|
103 | }
|
---|
104 | }
|
---|
105 | });
|
---|
106 |
|
---|
107 | function getLanguage(tag) {
|
---|
108 | var tagL = tag.toLowerCase();
|
---|
109 |
|
---|
110 | if (Tags.HTML[tagL]) {
|
---|
111 | return 'html';
|
---|
112 | } else if (Tags.SVG[tag]) {
|
---|
113 | return 'svg';
|
---|
114 | } else if (Tags.MathML[tag]) {
|
---|
115 | return 'mathml';
|
---|
116 | }
|
---|
117 |
|
---|
118 | // Not in dictionary, perform check
|
---|
119 | if (Tags.HTML[tagL] !== 0 && typeof document !== 'undefined') {
|
---|
120 | var htmlInterface = (document.createElement(tag).toString().match(/\[object HTML(.+)Element\]/) || [])[1];
|
---|
121 |
|
---|
122 | if (htmlInterface && htmlInterface != 'Unknown') {
|
---|
123 | Tags.HTML[tagL] = 1;
|
---|
124 | return 'html';
|
---|
125 | }
|
---|
126 | }
|
---|
127 |
|
---|
128 | Tags.HTML[tagL] = 0;
|
---|
129 |
|
---|
130 | if (Tags.SVG[tag] !== 0 && typeof document !== 'undefined') {
|
---|
131 | var svgInterface = (document.createElementNS('http://www.w3.org/2000/svg', tag).toString().match(/\[object SVG(.+)Element\]/) || [])[1];
|
---|
132 |
|
---|
133 | if (svgInterface && svgInterface != 'Unknown') {
|
---|
134 | Tags.SVG[tag] = 1;
|
---|
135 | return 'svg';
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | Tags.SVG[tag] = 0;
|
---|
140 |
|
---|
141 | // Lame way to detect MathML, but browsers don’t expose interface names there :(
|
---|
142 | if (Tags.MathML[tag] !== 0) {
|
---|
143 | if (tag.indexOf('m') === 0) {
|
---|
144 | Tags.MathML[tag] = 1;
|
---|
145 | return 'mathml';
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 | Tags.MathML[tag] = 0;
|
---|
150 |
|
---|
151 | return null;
|
---|
152 | }
|
---|
153 |
|
---|
154 | }());
|
---|