puppet-validator 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/README.md +39 -104
- data/bin/puppet-validator +38 -1
- data/config.ru +0 -2
- data/lib/puppet-validator.rb +181 -136
- data/lib/puppet-validator/helpers.rb +40 -0
- data/lib/puppet-validator/validators.rb +5 -0
- data/lib/puppet-validator/validators/lint.rb +46 -0
- data/lib/puppet-validator/validators/rspec.rb +90 -0
- data/lib/puppet-validator/validators/syntax.rb +96 -0
- data/public/font-awesome-4.7.0/css/font-awesome.css +2337 -0
- data/public/font-awesome-4.7.0/css/font-awesome.min.css +4 -0
- data/public/font-awesome-4.7.0/fonts/FontAwesome.otf +0 -0
- data/public/font-awesome-4.7.0/fonts/fontawesome-webfont.eot +0 -0
- data/public/font-awesome-4.7.0/fonts/fontawesome-webfont.svg +2671 -0
- data/public/font-awesome-4.7.0/fonts/fontawesome-webfont.ttf +0 -0
- data/public/font-awesome-4.7.0/fonts/fontawesome-webfont.woff +0 -0
- data/public/font-awesome-4.7.0/fonts/fontawesome-webfont.woff2 +0 -0
- data/public/scripts.js +203 -35
- data/public/styles.css +85 -54
- data/public/validation.js +95 -0
- data/views/index.erb +29 -7
- data/views/result.erb +23 -27
- metadata +33 -43
- data/bin/grapher +0 -44
- data/public/info.png +0 -0
- data/public/prism-default.css +0 -227
- data/public/prism.js +0 -961
data/public/info.png
DELETED
Binary file
|
data/public/prism-default.css
DELETED
@@ -1,227 +0,0 @@
|
|
1
|
-
/* http://prismjs.com/download.html?themes=prism&languages=puppet&plugins=line-highlight+line-numbers */
|
2
|
-
/**
|
3
|
-
* prism.js default theme for JavaScript, CSS and HTML
|
4
|
-
* Based on dabblet (http://dabblet.com)
|
5
|
-
* @author Lea Verou
|
6
|
-
*/
|
7
|
-
|
8
|
-
code[class*="language-"],
|
9
|
-
pre[class*="language-"] {
|
10
|
-
color: black;
|
11
|
-
background: none;
|
12
|
-
text-shadow: 0 1px white;
|
13
|
-
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
|
14
|
-
direction: ltr;
|
15
|
-
text-align: left;
|
16
|
-
white-space: pre;
|
17
|
-
word-spacing: normal;
|
18
|
-
word-break: normal;
|
19
|
-
word-wrap: normal;
|
20
|
-
line-height: 1.5;
|
21
|
-
|
22
|
-
-moz-tab-size: 4;
|
23
|
-
-o-tab-size: 4;
|
24
|
-
tab-size: 4;
|
25
|
-
|
26
|
-
-webkit-hyphens: none;
|
27
|
-
-moz-hyphens: none;
|
28
|
-
-ms-hyphens: none;
|
29
|
-
hyphens: none;
|
30
|
-
}
|
31
|
-
|
32
|
-
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
|
33
|
-
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
|
34
|
-
text-shadow: none;
|
35
|
-
background: #b3d4fc;
|
36
|
-
}
|
37
|
-
|
38
|
-
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
|
39
|
-
code[class*="language-"]::selection, code[class*="language-"] ::selection {
|
40
|
-
text-shadow: none;
|
41
|
-
background: #b3d4fc;
|
42
|
-
}
|
43
|
-
|
44
|
-
@media print {
|
45
|
-
code[class*="language-"],
|
46
|
-
pre[class*="language-"] {
|
47
|
-
text-shadow: none;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
|
51
|
-
/* Code blocks */
|
52
|
-
pre[class*="language-"] {
|
53
|
-
padding: 1em;
|
54
|
-
margin: .5em 0;
|
55
|
-
overflow: auto;
|
56
|
-
}
|
57
|
-
|
58
|
-
:not(pre) > code[class*="language-"],
|
59
|
-
pre[class*="language-"] {
|
60
|
-
background: #f5f2f0;
|
61
|
-
}
|
62
|
-
|
63
|
-
/* Inline code */
|
64
|
-
:not(pre) > code[class*="language-"] {
|
65
|
-
padding: .1em;
|
66
|
-
border-radius: .3em;
|
67
|
-
white-space: normal;
|
68
|
-
}
|
69
|
-
|
70
|
-
.token.comment,
|
71
|
-
.token.prolog,
|
72
|
-
.token.doctype,
|
73
|
-
.token.cdata {
|
74
|
-
color: slategray;
|
75
|
-
}
|
76
|
-
|
77
|
-
.token.punctuation {
|
78
|
-
color: #999;
|
79
|
-
}
|
80
|
-
|
81
|
-
.namespace {
|
82
|
-
opacity: .7;
|
83
|
-
}
|
84
|
-
|
85
|
-
.token.property,
|
86
|
-
.token.tag,
|
87
|
-
.token.boolean,
|
88
|
-
.token.number,
|
89
|
-
.token.constant,
|
90
|
-
.token.symbol,
|
91
|
-
.token.deleted {
|
92
|
-
color: #905;
|
93
|
-
}
|
94
|
-
|
95
|
-
.token.selector,
|
96
|
-
.token.attr-name,
|
97
|
-
.token.string,
|
98
|
-
.token.char,
|
99
|
-
.token.builtin,
|
100
|
-
.token.inserted {
|
101
|
-
color: #690;
|
102
|
-
}
|
103
|
-
|
104
|
-
.token.operator,
|
105
|
-
.token.entity,
|
106
|
-
.token.url,
|
107
|
-
.language-css .token.string,
|
108
|
-
.style .token.string {
|
109
|
-
color: #a67f59;
|
110
|
-
background: hsla(0, 0%, 100%, .5);
|
111
|
-
}
|
112
|
-
|
113
|
-
.token.atrule,
|
114
|
-
.token.attr-value,
|
115
|
-
.token.keyword {
|
116
|
-
color: #07a;
|
117
|
-
}
|
118
|
-
|
119
|
-
.token.function {
|
120
|
-
color: #DD4A68;
|
121
|
-
}
|
122
|
-
|
123
|
-
.token.regex,
|
124
|
-
.token.important,
|
125
|
-
.token.variable {
|
126
|
-
color: #e90;
|
127
|
-
}
|
128
|
-
|
129
|
-
.token.important,
|
130
|
-
.token.bold {
|
131
|
-
font-weight: bold;
|
132
|
-
}
|
133
|
-
.token.italic {
|
134
|
-
font-style: italic;
|
135
|
-
}
|
136
|
-
|
137
|
-
.token.entity {
|
138
|
-
cursor: help;
|
139
|
-
}
|
140
|
-
|
141
|
-
pre[data-line] {
|
142
|
-
position: relative;
|
143
|
-
padding: 1em 0 1em 3em;
|
144
|
-
}
|
145
|
-
|
146
|
-
.line-highlight {
|
147
|
-
position: absolute;
|
148
|
-
left: 0;
|
149
|
-
right: 0;
|
150
|
-
padding: inherit 0;
|
151
|
-
margin-top: 1em; /* Same as .prism’s padding-top */
|
152
|
-
|
153
|
-
background: hsla(24, 20%, 50%,.08);
|
154
|
-
background: -moz-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
|
155
|
-
background: -webkit-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
|
156
|
-
background: -o-linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
|
157
|
-
background: linear-gradient(left, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
|
158
|
-
|
159
|
-
pointer-events: none;
|
160
|
-
|
161
|
-
line-height: inherit;
|
162
|
-
white-space: pre;
|
163
|
-
}
|
164
|
-
|
165
|
-
.line-highlight:before,
|
166
|
-
.line-highlight[data-end]:after {
|
167
|
-
content: attr(data-start);
|
168
|
-
position: absolute;
|
169
|
-
top: .4em;
|
170
|
-
left: .6em;
|
171
|
-
min-width: 1em;
|
172
|
-
padding: 0 .5em;
|
173
|
-
background-color: hsla(24, 20%, 50%,.4);
|
174
|
-
color: hsl(24, 20%, 95%);
|
175
|
-
font: bold 65%/1.5 sans-serif;
|
176
|
-
text-align: center;
|
177
|
-
vertical-align: .3em;
|
178
|
-
border-radius: 999px;
|
179
|
-
text-shadow: none;
|
180
|
-
box-shadow: 0 1px white;
|
181
|
-
}
|
182
|
-
|
183
|
-
.line-highlight[data-end]:after {
|
184
|
-
content: attr(data-end);
|
185
|
-
top: auto;
|
186
|
-
bottom: .4em;
|
187
|
-
}
|
188
|
-
pre.line-numbers {
|
189
|
-
position: relative;
|
190
|
-
padding-left: 3.8em;
|
191
|
-
counter-reset: linenumber;
|
192
|
-
}
|
193
|
-
|
194
|
-
pre.line-numbers > code {
|
195
|
-
position: relative;
|
196
|
-
}
|
197
|
-
|
198
|
-
.line-numbers .line-numbers-rows {
|
199
|
-
position: absolute;
|
200
|
-
pointer-events: none;
|
201
|
-
top: 0;
|
202
|
-
font-size: 100%;
|
203
|
-
left: -3.8em;
|
204
|
-
width: 3em; /* works for line-numbers below 1000 lines */
|
205
|
-
letter-spacing: -1px;
|
206
|
-
border-right: 1px solid #999;
|
207
|
-
|
208
|
-
-webkit-user-select: none;
|
209
|
-
-moz-user-select: none;
|
210
|
-
-ms-user-select: none;
|
211
|
-
user-select: none;
|
212
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
.line-numbers-rows > span {
|
216
|
-
pointer-events: none;
|
217
|
-
display: block;
|
218
|
-
counter-increment: linenumber;
|
219
|
-
}
|
220
|
-
|
221
|
-
.line-numbers-rows > span:before {
|
222
|
-
content: counter(linenumber);
|
223
|
-
color: #999;
|
224
|
-
display: block;
|
225
|
-
padding-right: 0.8em;
|
226
|
-
text-align: right;
|
227
|
-
}
|
data/public/prism.js
DELETED
@@ -1,961 +0,0 @@
|
|
1
|
-
/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+puppet&plugins=line-highlight+line-numbers */
|
2
|
-
var _self = (typeof window !== 'undefined')
|
3
|
-
? window // if in browser
|
4
|
-
: (
|
5
|
-
(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
|
6
|
-
? self // if in worker
|
7
|
-
: {} // if in node js
|
8
|
-
);
|
9
|
-
|
10
|
-
/**
|
11
|
-
* Prism: Lightweight, robust, elegant syntax highlighting
|
12
|
-
* MIT license http://www.opensource.org/licenses/mit-license.php/
|
13
|
-
* @author Lea Verou http://lea.verou.me
|
14
|
-
*/
|
15
|
-
|
16
|
-
var Prism = (function(){
|
17
|
-
|
18
|
-
// Private helper vars
|
19
|
-
var lang = /\blang(?:uage)?-(\w+)\b/i;
|
20
|
-
var uniqueId = 0;
|
21
|
-
|
22
|
-
var _ = _self.Prism = {
|
23
|
-
util: {
|
24
|
-
encode: function (tokens) {
|
25
|
-
if (tokens instanceof Token) {
|
26
|
-
return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
|
27
|
-
} else if (_.util.type(tokens) === 'Array') {
|
28
|
-
return tokens.map(_.util.encode);
|
29
|
-
} else {
|
30
|
-
return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
|
31
|
-
}
|
32
|
-
},
|
33
|
-
|
34
|
-
type: function (o) {
|
35
|
-
return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
|
36
|
-
},
|
37
|
-
|
38
|
-
objId: function (obj) {
|
39
|
-
if (!obj['__id']) {
|
40
|
-
Object.defineProperty(obj, '__id', { value: ++uniqueId });
|
41
|
-
}
|
42
|
-
return obj['__id'];
|
43
|
-
},
|
44
|
-
|
45
|
-
// Deep clone a language definition (e.g. to extend it)
|
46
|
-
clone: function (o) {
|
47
|
-
var type = _.util.type(o);
|
48
|
-
|
49
|
-
switch (type) {
|
50
|
-
case 'Object':
|
51
|
-
var clone = {};
|
52
|
-
|
53
|
-
for (var key in o) {
|
54
|
-
if (o.hasOwnProperty(key)) {
|
55
|
-
clone[key] = _.util.clone(o[key]);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
|
59
|
-
return clone;
|
60
|
-
|
61
|
-
case 'Array':
|
62
|
-
// Check for existence for IE8
|
63
|
-
return o.map && o.map(function(v) { return _.util.clone(v); });
|
64
|
-
}
|
65
|
-
|
66
|
-
return o;
|
67
|
-
}
|
68
|
-
},
|
69
|
-
|
70
|
-
languages: {
|
71
|
-
extend: function (id, redef) {
|
72
|
-
var lang = _.util.clone(_.languages[id]);
|
73
|
-
|
74
|
-
for (var key in redef) {
|
75
|
-
lang[key] = redef[key];
|
76
|
-
}
|
77
|
-
|
78
|
-
return lang;
|
79
|
-
},
|
80
|
-
|
81
|
-
/**
|
82
|
-
* Insert a token before another token in a language literal
|
83
|
-
* As this needs to recreate the object (we cannot actually insert before keys in object literals),
|
84
|
-
* we cannot just provide an object, we need anobject and a key.
|
85
|
-
* @param inside The key (or language id) of the parent
|
86
|
-
* @param before The key to insert before. If not provided, the function appends instead.
|
87
|
-
* @param insert Object with the key/value pairs to insert
|
88
|
-
* @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
|
89
|
-
*/
|
90
|
-
insertBefore: function (inside, before, insert, root) {
|
91
|
-
root = root || _.languages;
|
92
|
-
var grammar = root[inside];
|
93
|
-
|
94
|
-
if (arguments.length == 2) {
|
95
|
-
insert = arguments[1];
|
96
|
-
|
97
|
-
for (var newToken in insert) {
|
98
|
-
if (insert.hasOwnProperty(newToken)) {
|
99
|
-
grammar[newToken] = insert[newToken];
|
100
|
-
}
|
101
|
-
}
|
102
|
-
|
103
|
-
return grammar;
|
104
|
-
}
|
105
|
-
|
106
|
-
var ret = {};
|
107
|
-
|
108
|
-
for (var token in grammar) {
|
109
|
-
|
110
|
-
if (grammar.hasOwnProperty(token)) {
|
111
|
-
|
112
|
-
if (token == before) {
|
113
|
-
|
114
|
-
for (var newToken in insert) {
|
115
|
-
|
116
|
-
if (insert.hasOwnProperty(newToken)) {
|
117
|
-
ret[newToken] = insert[newToken];
|
118
|
-
}
|
119
|
-
}
|
120
|
-
}
|
121
|
-
|
122
|
-
ret[token] = grammar[token];
|
123
|
-
}
|
124
|
-
}
|
125
|
-
|
126
|
-
// Update references in other language definitions
|
127
|
-
_.languages.DFS(_.languages, function(key, value) {
|
128
|
-
if (value === root[inside] && key != inside) {
|
129
|
-
this[key] = ret;
|
130
|
-
}
|
131
|
-
});
|
132
|
-
|
133
|
-
return root[inside] = ret;
|
134
|
-
},
|
135
|
-
|
136
|
-
// Traverse a language definition with Depth First Search
|
137
|
-
DFS: function(o, callback, type, visited) {
|
138
|
-
visited = visited || {};
|
139
|
-
for (var i in o) {
|
140
|
-
if (o.hasOwnProperty(i)) {
|
141
|
-
callback.call(o, i, o[i], type || i);
|
142
|
-
|
143
|
-
if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
|
144
|
-
visited[_.util.objId(o[i])] = true;
|
145
|
-
_.languages.DFS(o[i], callback, null, visited);
|
146
|
-
}
|
147
|
-
else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
|
148
|
-
visited[_.util.objId(o[i])] = true;
|
149
|
-
_.languages.DFS(o[i], callback, i, visited);
|
150
|
-
}
|
151
|
-
}
|
152
|
-
}
|
153
|
-
}
|
154
|
-
},
|
155
|
-
plugins: {},
|
156
|
-
|
157
|
-
highlightAll: function(async, callback) {
|
158
|
-
var elements = document.querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');
|
159
|
-
|
160
|
-
for (var i=0, element; element = elements[i++];) {
|
161
|
-
_.highlightElement(element, async === true, callback);
|
162
|
-
}
|
163
|
-
},
|
164
|
-
|
165
|
-
highlightElement: function(element, async, callback) {
|
166
|
-
// Find language
|
167
|
-
var language, grammar, parent = element;
|
168
|
-
|
169
|
-
while (parent && !lang.test(parent.className)) {
|
170
|
-
parent = parent.parentNode;
|
171
|
-
}
|
172
|
-
|
173
|
-
if (parent) {
|
174
|
-
language = (parent.className.match(lang) || [,''])[1];
|
175
|
-
grammar = _.languages[language];
|
176
|
-
}
|
177
|
-
|
178
|
-
// Set language on the element, if not present
|
179
|
-
element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
|
180
|
-
|
181
|
-
// Set language on the parent, for styling
|
182
|
-
parent = element.parentNode;
|
183
|
-
|
184
|
-
if (/pre/i.test(parent.nodeName)) {
|
185
|
-
parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
|
186
|
-
}
|
187
|
-
|
188
|
-
var code = element.textContent;
|
189
|
-
|
190
|
-
var env = {
|
191
|
-
element: element,
|
192
|
-
language: language,
|
193
|
-
grammar: grammar,
|
194
|
-
code: code
|
195
|
-
};
|
196
|
-
|
197
|
-
if (!code || !grammar) {
|
198
|
-
_.hooks.run('complete', env);
|
199
|
-
return;
|
200
|
-
}
|
201
|
-
|
202
|
-
_.hooks.run('before-highlight', env);
|
203
|
-
|
204
|
-
if (async && _self.Worker) {
|
205
|
-
var worker = new Worker(_.filename);
|
206
|
-
|
207
|
-
worker.onmessage = function(evt) {
|
208
|
-
env.highlightedCode = evt.data;
|
209
|
-
|
210
|
-
_.hooks.run('before-insert', env);
|
211
|
-
|
212
|
-
env.element.innerHTML = env.highlightedCode;
|
213
|
-
|
214
|
-
callback && callback.call(env.element);
|
215
|
-
_.hooks.run('after-highlight', env);
|
216
|
-
_.hooks.run('complete', env);
|
217
|
-
};
|
218
|
-
|
219
|
-
worker.postMessage(JSON.stringify({
|
220
|
-
language: env.language,
|
221
|
-
code: env.code,
|
222
|
-
immediateClose: true
|
223
|
-
}));
|
224
|
-
}
|
225
|
-
else {
|
226
|
-
env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
|
227
|
-
|
228
|
-
_.hooks.run('before-insert', env);
|
229
|
-
|
230
|
-
env.element.innerHTML = env.highlightedCode;
|
231
|
-
|
232
|
-
callback && callback.call(element);
|
233
|
-
|
234
|
-
_.hooks.run('after-highlight', env);
|
235
|
-
_.hooks.run('complete', env);
|
236
|
-
}
|
237
|
-
},
|
238
|
-
|
239
|
-
highlight: function (text, grammar, language) {
|
240
|
-
var tokens = _.tokenize(text, grammar);
|
241
|
-
return Token.stringify(_.util.encode(tokens), language);
|
242
|
-
},
|
243
|
-
|
244
|
-
tokenize: function(text, grammar, language) {
|
245
|
-
var Token = _.Token;
|
246
|
-
|
247
|
-
var strarr = [text];
|
248
|
-
|
249
|
-
var rest = grammar.rest;
|
250
|
-
|
251
|
-
if (rest) {
|
252
|
-
for (var token in rest) {
|
253
|
-
grammar[token] = rest[token];
|
254
|
-
}
|
255
|
-
|
256
|
-
delete grammar.rest;
|
257
|
-
}
|
258
|
-
|
259
|
-
tokenloop: for (var token in grammar) {
|
260
|
-
if(!grammar.hasOwnProperty(token) || !grammar[token]) {
|
261
|
-
continue;
|
262
|
-
}
|
263
|
-
|
264
|
-
var patterns = grammar[token];
|
265
|
-
patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
|
266
|
-
|
267
|
-
for (var j = 0; j < patterns.length; ++j) {
|
268
|
-
var pattern = patterns[j],
|
269
|
-
inside = pattern.inside,
|
270
|
-
lookbehind = !!pattern.lookbehind,
|
271
|
-
lookbehindLength = 0,
|
272
|
-
alias = pattern.alias;
|
273
|
-
|
274
|
-
pattern = pattern.pattern || pattern;
|
275
|
-
|
276
|
-
for (var i=0; i<strarr.length; i++) { // Don’t cache length as it changes during the loop
|
277
|
-
|
278
|
-
var str = strarr[i];
|
279
|
-
|
280
|
-
if (strarr.length > text.length) {
|
281
|
-
// Something went terribly wrong, ABORT, ABORT!
|
282
|
-
break tokenloop;
|
283
|
-
}
|
284
|
-
|
285
|
-
if (str instanceof Token) {
|
286
|
-
continue;
|
287
|
-
}
|
288
|
-
|
289
|
-
pattern.lastIndex = 0;
|
290
|
-
|
291
|
-
var match = pattern.exec(str);
|
292
|
-
|
293
|
-
if (match) {
|
294
|
-
if(lookbehind) {
|
295
|
-
lookbehindLength = match[1].length;
|
296
|
-
}
|
297
|
-
|
298
|
-
var from = match.index - 1 + lookbehindLength,
|
299
|
-
match = match[0].slice(lookbehindLength),
|
300
|
-
len = match.length,
|
301
|
-
to = from + len,
|
302
|
-
before = str.slice(0, from + 1),
|
303
|
-
after = str.slice(to + 1);
|
304
|
-
|
305
|
-
var args = [i, 1];
|
306
|
-
|
307
|
-
if (before) {
|
308
|
-
args.push(before);
|
309
|
-
}
|
310
|
-
|
311
|
-
var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias);
|
312
|
-
|
313
|
-
args.push(wrapped);
|
314
|
-
|
315
|
-
if (after) {
|
316
|
-
args.push(after);
|
317
|
-
}
|
318
|
-
|
319
|
-
Array.prototype.splice.apply(strarr, args);
|
320
|
-
}
|
321
|
-
}
|
322
|
-
}
|
323
|
-
}
|
324
|
-
|
325
|
-
return strarr;
|
326
|
-
},
|
327
|
-
|
328
|
-
hooks: {
|
329
|
-
all: {},
|
330
|
-
|
331
|
-
add: function (name, callback) {
|
332
|
-
var hooks = _.hooks.all;
|
333
|
-
|
334
|
-
hooks[name] = hooks[name] || [];
|
335
|
-
|
336
|
-
hooks[name].push(callback);
|
337
|
-
},
|
338
|
-
|
339
|
-
run: function (name, env) {
|
340
|
-
var callbacks = _.hooks.all[name];
|
341
|
-
|
342
|
-
if (!callbacks || !callbacks.length) {
|
343
|
-
return;
|
344
|
-
}
|
345
|
-
|
346
|
-
for (var i=0, callback; callback = callbacks[i++];) {
|
347
|
-
callback(env);
|
348
|
-
}
|
349
|
-
}
|
350
|
-
}
|
351
|
-
};
|
352
|
-
|
353
|
-
var Token = _.Token = function(type, content, alias) {
|
354
|
-
this.type = type;
|
355
|
-
this.content = content;
|
356
|
-
this.alias = alias;
|
357
|
-
};
|
358
|
-
|
359
|
-
Token.stringify = function(o, language, parent) {
|
360
|
-
if (typeof o == 'string') {
|
361
|
-
return o;
|
362
|
-
}
|
363
|
-
|
364
|
-
if (_.util.type(o) === 'Array') {
|
365
|
-
return o.map(function(element) {
|
366
|
-
return Token.stringify(element, language, o);
|
367
|
-
}).join('');
|
368
|
-
}
|
369
|
-
|
370
|
-
var env = {
|
371
|
-
type: o.type,
|
372
|
-
content: Token.stringify(o.content, language, parent),
|
373
|
-
tag: 'span',
|
374
|
-
classes: ['token', o.type],
|
375
|
-
attributes: {},
|
376
|
-
language: language,
|
377
|
-
parent: parent
|
378
|
-
};
|
379
|
-
|
380
|
-
if (env.type == 'comment') {
|
381
|
-
env.attributes['spellcheck'] = 'true';
|
382
|
-
}
|
383
|
-
|
384
|
-
if (o.alias) {
|
385
|
-
var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
|
386
|
-
Array.prototype.push.apply(env.classes, aliases);
|
387
|
-
}
|
388
|
-
|
389
|
-
_.hooks.run('wrap', env);
|
390
|
-
|
391
|
-
var attributes = '';
|
392
|
-
|
393
|
-
for (var name in env.attributes) {
|
394
|
-
attributes += (attributes ? ' ' : '') + name + '="' + (env.attributes[name] || '') + '"';
|
395
|
-
}
|
396
|
-
|
397
|
-
return '<' + env.tag + ' class="' + env.classes.join(' ') + '" ' + attributes + '>' + env.content + '</' + env.tag + '>';
|
398
|
-
|
399
|
-
};
|
400
|
-
|
401
|
-
if (!_self.document) {
|
402
|
-
if (!_self.addEventListener) {
|
403
|
-
// in Node.js
|
404
|
-
return _self.Prism;
|
405
|
-
}
|
406
|
-
// In worker
|
407
|
-
_self.addEventListener('message', function(evt) {
|
408
|
-
var message = JSON.parse(evt.data),
|
409
|
-
lang = message.language,
|
410
|
-
code = message.code,
|
411
|
-
immediateClose = message.immediateClose;
|
412
|
-
|
413
|
-
_self.postMessage(_.highlight(code, _.languages[lang], lang));
|
414
|
-
if (immediateClose) {
|
415
|
-
_self.close();
|
416
|
-
}
|
417
|
-
}, false);
|
418
|
-
|
419
|
-
return _self.Prism;
|
420
|
-
}
|
421
|
-
|
422
|
-
//Get current script and highlight
|
423
|
-
var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
|
424
|
-
|
425
|
-
if (script) {
|
426
|
-
_.filename = script.src;
|
427
|
-
|
428
|
-
if (document.addEventListener && !script.hasAttribute('data-manual')) {
|
429
|
-
document.addEventListener('DOMContentLoaded', _.highlightAll);
|
430
|
-
}
|
431
|
-
}
|
432
|
-
|
433
|
-
return _self.Prism;
|
434
|
-
|
435
|
-
})();
|
436
|
-
|
437
|
-
if (typeof module !== 'undefined' && module.exports) {
|
438
|
-
module.exports = Prism;
|
439
|
-
}
|
440
|
-
|
441
|
-
// hack for components to work correctly in node.js
|
442
|
-
if (typeof global !== 'undefined') {
|
443
|
-
global.Prism = Prism;
|
444
|
-
}
|
445
|
-
;
|
446
|
-
Prism.languages.markup = {
|
447
|
-
'comment': /<!--[\w\W]*?-->/,
|
448
|
-
'prolog': /<\?[\w\W]+?\?>/,
|
449
|
-
'doctype': /<!DOCTYPE[\w\W]+?>/,
|
450
|
-
'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
|
451
|
-
'tag': {
|
452
|
-
pattern: /<\/?(?!\d)[^\s>\/=.$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
|
453
|
-
inside: {
|
454
|
-
'tag': {
|
455
|
-
pattern: /^<\/?[^\s>\/]+/i,
|
456
|
-
inside: {
|
457
|
-
'punctuation': /^<\/?/,
|
458
|
-
'namespace': /^[^\s>\/:]+:/
|
459
|
-
}
|
460
|
-
},
|
461
|
-
'attr-value': {
|
462
|
-
pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
|
463
|
-
inside: {
|
464
|
-
'punctuation': /[=>"']/
|
465
|
-
}
|
466
|
-
},
|
467
|
-
'punctuation': /\/?>/,
|
468
|
-
'attr-name': {
|
469
|
-
pattern: /[^\s>\/]+/,
|
470
|
-
inside: {
|
471
|
-
'namespace': /^[^\s>\/:]+:/
|
472
|
-
}
|
473
|
-
}
|
474
|
-
|
475
|
-
}
|
476
|
-
},
|
477
|
-
'entity': /&#?[\da-z]{1,8};/i
|
478
|
-
};
|
479
|
-
|
480
|
-
// Plugin to make entity title show the real entity, idea by Roman Komarov
|
481
|
-
Prism.hooks.add('wrap', function(env) {
|
482
|
-
|
483
|
-
if (env.type === 'entity') {
|
484
|
-
env.attributes['title'] = env.content.replace(/&/, '&');
|
485
|
-
}
|
486
|
-
});
|
487
|
-
|
488
|
-
Prism.languages.xml = Prism.languages.markup;
|
489
|
-
Prism.languages.html = Prism.languages.markup;
|
490
|
-
Prism.languages.mathml = Prism.languages.markup;
|
491
|
-
Prism.languages.svg = Prism.languages.markup;
|
492
|
-
|
493
|
-
Prism.languages.css = {
|
494
|
-
'comment': /\/\*[\w\W]*?\*\//,
|
495
|
-
'atrule': {
|
496
|
-
pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
|
497
|
-
inside: {
|
498
|
-
'rule': /@[\w-]+/
|
499
|
-
// See rest below
|
500
|
-
}
|
501
|
-
},
|
502
|
-
'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
|
503
|
-
'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
|
504
|
-
'string': /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
|
505
|
-
'property': /(\b|\B)[\w-]+(?=\s*:)/i,
|
506
|
-
'important': /\B!important\b/i,
|
507
|
-
'function': /[-a-z0-9]+(?=\()/i,
|
508
|
-
'punctuation': /[(){};:]/
|
509
|
-
};
|
510
|
-
|
511
|
-
Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
|
512
|
-
|
513
|
-
if (Prism.languages.markup) {
|
514
|
-
Prism.languages.insertBefore('markup', 'tag', {
|
515
|
-
'style': {
|
516
|
-
pattern: /(<style[\w\W]*?>)[\w\W]*?(?=<\/style>)/i,
|
517
|
-
lookbehind: true,
|
518
|
-
inside: Prism.languages.css,
|
519
|
-
alias: 'language-css'
|
520
|
-
}
|
521
|
-
});
|
522
|
-
|
523
|
-
Prism.languages.insertBefore('inside', 'attr-value', {
|
524
|
-
'style-attr': {
|
525
|
-
pattern: /\s*style=("|').*?\1/i,
|
526
|
-
inside: {
|
527
|
-
'attr-name': {
|
528
|
-
pattern: /^\s*style/i,
|
529
|
-
inside: Prism.languages.markup.tag.inside
|
530
|
-
},
|
531
|
-
'punctuation': /^\s*=\s*['"]|['"]\s*$/,
|
532
|
-
'attr-value': {
|
533
|
-
pattern: /.+/i,
|
534
|
-
inside: Prism.languages.css
|
535
|
-
}
|
536
|
-
},
|
537
|
-
alias: 'language-css'
|
538
|
-
}
|
539
|
-
}, Prism.languages.markup.tag);
|
540
|
-
};
|
541
|
-
Prism.languages.clike = {
|
542
|
-
'comment': [
|
543
|
-
{
|
544
|
-
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
|
545
|
-
lookbehind: true
|
546
|
-
},
|
547
|
-
{
|
548
|
-
pattern: /(^|[^\\:])\/\/.*/,
|
549
|
-
lookbehind: true
|
550
|
-
}
|
551
|
-
],
|
552
|
-
'string': /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
553
|
-
'class-name': {
|
554
|
-
pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
|
555
|
-
lookbehind: true,
|
556
|
-
inside: {
|
557
|
-
punctuation: /(\.|\\)/
|
558
|
-
}
|
559
|
-
},
|
560
|
-
'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
|
561
|
-
'boolean': /\b(true|false)\b/,
|
562
|
-
'function': /[a-z0-9_]+(?=\()/i,
|
563
|
-
'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
|
564
|
-
'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
|
565
|
-
'punctuation': /[{}[\];(),.:]/
|
566
|
-
};
|
567
|
-
|
568
|
-
Prism.languages.javascript = Prism.languages.extend('clike', {
|
569
|
-
'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,
|
570
|
-
'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
|
571
|
-
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
572
|
-
'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i
|
573
|
-
});
|
574
|
-
|
575
|
-
Prism.languages.insertBefore('javascript', 'keyword', {
|
576
|
-
'regex': {
|
577
|
-
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
|
578
|
-
lookbehind: true
|
579
|
-
}
|
580
|
-
});
|
581
|
-
|
582
|
-
Prism.languages.insertBefore('javascript', 'class-name', {
|
583
|
-
'template-string': {
|
584
|
-
pattern: /`(?:\\`|\\?[^`])*`/,
|
585
|
-
inside: {
|
586
|
-
'interpolation': {
|
587
|
-
pattern: /\$\{[^}]+\}/,
|
588
|
-
inside: {
|
589
|
-
'interpolation-punctuation': {
|
590
|
-
pattern: /^\$\{|\}$/,
|
591
|
-
alias: 'punctuation'
|
592
|
-
},
|
593
|
-
rest: Prism.languages.javascript
|
594
|
-
}
|
595
|
-
},
|
596
|
-
'string': /[\s\S]+/
|
597
|
-
}
|
598
|
-
}
|
599
|
-
});
|
600
|
-
|
601
|
-
if (Prism.languages.markup) {
|
602
|
-
Prism.languages.insertBefore('markup', 'tag', {
|
603
|
-
'script': {
|
604
|
-
pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
|
605
|
-
lookbehind: true,
|
606
|
-
inside: Prism.languages.javascript,
|
607
|
-
alias: 'language-javascript'
|
608
|
-
}
|
609
|
-
});
|
610
|
-
}
|
611
|
-
|
612
|
-
Prism.languages.js = Prism.languages.javascript;
|
613
|
-
(function (Prism) {
|
614
|
-
Prism.languages.puppet = {
|
615
|
-
'heredoc': [
|
616
|
-
// Matches the content of a quoted heredoc string (subject to interpolation)
|
617
|
-
{
|
618
|
-
pattern: /(@\("([^"\r\n\/):]+)"(?:\/[nrts$uL]*)?\).*(?:\r?\n|\r))(?:.*(?:\r?\n|\r))*?[ \t]*\|?[ \t]*-?[ \t]*\2/,
|
619
|
-
lookbehind: true,
|
620
|
-
alias: 'string',
|
621
|
-
inside: {
|
622
|
-
// Matches the end tag
|
623
|
-
'punctuation': /(?=\S).*\S(?= *$)/
|
624
|
-
// See interpolation below
|
625
|
-
}
|
626
|
-
},
|
627
|
-
// Matches the content of an unquoted heredoc string (no interpolation)
|
628
|
-
{
|
629
|
-
pattern: /(@\(([^"\r\n\/):]+)(?:\/[nrts$uL]*)?\).*(?:\r?\n|\r))(?:.*(?:\r?\n|\r))*?[ \t]*\|?[ \t]*-?[ \t]*\2/,
|
630
|
-
lookbehind: true,
|
631
|
-
alias: 'string',
|
632
|
-
inside: {
|
633
|
-
// Matches the end tag
|
634
|
-
'punctuation': /(?=\S).*\S(?= *$)/
|
635
|
-
}
|
636
|
-
},
|
637
|
-
// Matches the start tag of heredoc strings
|
638
|
-
{
|
639
|
-
pattern: /@\("?(?:[^"\r\n\/):]+)"?(?:\/[nrts$uL]*)?\)/,
|
640
|
-
alias: 'string',
|
641
|
-
inside: {
|
642
|
-
'punctuation': {
|
643
|
-
pattern: /(\().+?(?=\))/,
|
644
|
-
lookbehind: true
|
645
|
-
}
|
646
|
-
}
|
647
|
-
}
|
648
|
-
],
|
649
|
-
'multiline-comment': {
|
650
|
-
pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
|
651
|
-
lookbehind: true,
|
652
|
-
alias: 'comment'
|
653
|
-
},
|
654
|
-
'regex': {
|
655
|
-
// Must be prefixed with the keyword "node" or a non-word char
|
656
|
-
pattern: /((?:\bnode\s+|[^\s\w\\]\s*))\/(?:[^\/\\]|\\[\s\S])+\/(?:[imx]+\b|\B)/,
|
657
|
-
lookbehind: true,
|
658
|
-
inside: {
|
659
|
-
// Extended regexes must have the x flag. They can contain single-line comments.
|
660
|
-
'extended-regex': {
|
661
|
-
pattern: /^\/(?:[^\/\\]|\\[\s\S])+\/[im]*x[im]*$/,
|
662
|
-
inside: {
|
663
|
-
'comment': /#.*/
|
664
|
-
}
|
665
|
-
}
|
666
|
-
}
|
667
|
-
},
|
668
|
-
'comment': {
|
669
|
-
pattern: /(^|[^\\])#.*/,
|
670
|
-
lookbehind: true
|
671
|
-
},
|
672
|
-
'string': {
|
673
|
-
// Allow for one nested level of double quotes inside interpolation
|
674
|
-
pattern: /(["'])(?:\$\{(?:[^'"}]|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}|(?!\1)[^\\]|\\[\s\S])*\1/,
|
675
|
-
inside: {
|
676
|
-
'double-quoted': {
|
677
|
-
pattern: /^"[\s\S]*"$/,
|
678
|
-
inside: {
|
679
|
-
// See interpolation below
|
680
|
-
}
|
681
|
-
}
|
682
|
-
}
|
683
|
-
},
|
684
|
-
'variable': {
|
685
|
-
pattern: /\$(?:::)?\w+(?:::\w+)*/,
|
686
|
-
inside: {
|
687
|
-
'punctuation': /::/
|
688
|
-
}
|
689
|
-
},
|
690
|
-
'attr-name': /(?:\w+|\*)(?=\s*=>)/,
|
691
|
-
'function': [
|
692
|
-
{
|
693
|
-
pattern: /(\.)(?!\d)\w+/,
|
694
|
-
lookbehind: true
|
695
|
-
},
|
696
|
-
/\b(?:contain|debug|err|fail|include|info|notice|realize|require|tag|warning)\b|\b(?!\d)\w+(?=\()/
|
697
|
-
],
|
698
|
-
'number': /\b(?:0x[a-f\d]+|\d+(?:\.\d+)?(?:e-?\d+)?)\b/i,
|
699
|
-
'boolean': /\b(?:true|false)\b/,
|
700
|
-
// Includes words reserved for future use
|
701
|
-
'keyword': /\b(?:application|attr|case|class|consumes|default|define|else|elsif|function|if|import|inherits|node|private|produces|type|undef|unless)\b/,
|
702
|
-
'datatype': {
|
703
|
-
pattern: /\b(?:Any|Array|Boolean|Callable|Catalogentry|Class|Collection|Data|Default|Enum|Float|Hash|Integer|NotUndef|Numeric|Optional|Pattern|Regexp|Resource|Runtime|Scalar|String|Struct|Tuple|Type|Undef|Variant)\b/,
|
704
|
-
alias: 'symbol'
|
705
|
-
},
|
706
|
-
'operator': /=[=~>]?|![=~]?|<(?:<\|?|[=~|-])?|>[>=]?|->?|~>|\|>?>?|[*\/%+?]|\b(?:and|in|or)\b/,
|
707
|
-
'punctuation': /[\[\]{}().,;]|:+/
|
708
|
-
};
|
709
|
-
|
710
|
-
var interpolation = [
|
711
|
-
{
|
712
|
-
// Allow for one nested level of braces inside interpolation
|
713
|
-
pattern: /(^|[^\\])\$\{(?:[^'"{}]|\{[^}]*\}|(["'])(?:(?!\2)[^\\]|\\[\s\S])*\2)+\}/,
|
714
|
-
lookbehind: true,
|
715
|
-
inside: {
|
716
|
-
'short-variable': {
|
717
|
-
// Negative look-ahead prevent wrong highlighting of functions
|
718
|
-
pattern: /(^\$\{)(?!\w+\()(?:::)?\w+(?:::\w+)*/,
|
719
|
-
lookbehind: true,
|
720
|
-
alias: 'variable',
|
721
|
-
inside: {
|
722
|
-
'punctuation': /::/
|
723
|
-
}
|
724
|
-
},
|
725
|
-
'delimiter': {
|
726
|
-
pattern: /^\$/,
|
727
|
-
alias: 'variable'
|
728
|
-
},
|
729
|
-
rest: Prism.util.clone(Prism.languages.puppet)
|
730
|
-
}
|
731
|
-
},
|
732
|
-
{
|
733
|
-
pattern: /(^|[^\\])\$(?:::)?\w+(?:::\w+)*/,
|
734
|
-
lookbehind: true,
|
735
|
-
alias: 'variable',
|
736
|
-
inside: {
|
737
|
-
'punctuation': /::/
|
738
|
-
}
|
739
|
-
}
|
740
|
-
];
|
741
|
-
Prism.languages.puppet['heredoc'][0].inside.interpolation = interpolation;
|
742
|
-
Prism.languages.puppet['string'].inside['double-quoted'].inside.interpolation = interpolation;
|
743
|
-
}(Prism));
|
744
|
-
(function(){
|
745
|
-
|
746
|
-
if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) {
|
747
|
-
return;
|
748
|
-
}
|
749
|
-
|
750
|
-
function $$(expr, con) {
|
751
|
-
return Array.prototype.slice.call((con || document).querySelectorAll(expr));
|
752
|
-
}
|
753
|
-
|
754
|
-
function hasClass(element, className) {
|
755
|
-
className = " " + className + " ";
|
756
|
-
return (" " + element.className + " ").replace(/[\n\t]/g, " ").indexOf(className) > -1
|
757
|
-
}
|
758
|
-
|
759
|
-
// Some browsers round the line-height, others don't.
|
760
|
-
// We need to test for it to position the elements properly.
|
761
|
-
var isLineHeightRounded = (function() {
|
762
|
-
var res;
|
763
|
-
return function() {
|
764
|
-
if(typeof res === 'undefined') {
|
765
|
-
var d = document.createElement('div');
|
766
|
-
d.style.fontSize = '1em';
|
767
|
-
d.style.lineHeight = '1.5';
|
768
|
-
d.style.padding = 0;
|
769
|
-
d.style.border = 0;
|
770
|
-
d.innerHTML = ' <br /> ';
|
771
|
-
document.body.appendChild(d);
|
772
|
-
// Browsers that round the line-height should have offsetHeight === 38
|
773
|
-
// The others should have 39.
|
774
|
-
res = d.offsetHeight === 38;
|
775
|
-
document.body.removeChild(d);
|
776
|
-
}
|
777
|
-
return res;
|
778
|
-
}
|
779
|
-
}());
|
780
|
-
|
781
|
-
function highlightLines(pre, lines, classes) {
|
782
|
-
try {
|
783
|
-
var ranges = JSON.parse(lines);
|
784
|
-
|
785
|
-
// only matches if we pass in a single number
|
786
|
-
if(typeof(ranges) == 'number') {
|
787
|
-
ranges = {}
|
788
|
-
ranges[lines] = null
|
789
|
-
}
|
790
|
-
}
|
791
|
-
catch (err) {
|
792
|
-
// Anything else that's not valid JSON or a single number
|
793
|
-
// Turn the list into a hash with tooltips of null
|
794
|
-
var ranges = lines.replace(/\s+/g, '').split(',')
|
795
|
-
.reduce(function(res, curr) { res[curr] = null; return res }, {});
|
796
|
-
}
|
797
|
-
var offset = +pre.getAttribute('data-line-offset') || 0;
|
798
|
-
|
799
|
-
var parseMethod = isLineHeightRounded() ? parseInt : parseFloat;
|
800
|
-
var lineHeight = parseMethod(getComputedStyle(pre).lineHeight);
|
801
|
-
|
802
|
-
Object.keys(ranges).forEach(function (key) {
|
803
|
-
range = key.split('-');
|
804
|
-
|
805
|
-
var start = +range[0],
|
806
|
-
end = +range[1] || start;
|
807
|
-
|
808
|
-
var line = document.createElement('div');
|
809
|
-
|
810
|
-
line.textContent = Array(end - start + 2).join(' \n');
|
811
|
-
line.className = (classes || '') + ' line-highlight';
|
812
|
-
|
813
|
-
//if the line-numbers plugin is enabled, then there is no reason for this plugin to display the line numbers
|
814
|
-
if(!hasClass(pre, 'line-numbers')) {
|
815
|
-
line.setAttribute('data-start', start);
|
816
|
-
|
817
|
-
if(end > start) {
|
818
|
-
line.setAttribute('data-end', end);
|
819
|
-
}
|
820
|
-
}
|
821
|
-
|
822
|
-
line.style.top = (start - offset - 1) * lineHeight + 'px';
|
823
|
-
|
824
|
-
// append a tooltip element if one is set
|
825
|
-
if(ranges[key]) {
|
826
|
-
var marker = document.createElement('div');
|
827
|
-
marker.className = 'marker';
|
828
|
-
|
829
|
-
var tooltip = document.createElement('div');
|
830
|
-
tooltip.textContent = ranges[key];
|
831
|
-
tooltip.className = 'line-highlight-tooltip';
|
832
|
-
|
833
|
-
line.className = (classes || '') + ' line-highlight with-tooltip';
|
834
|
-
|
835
|
-
line.appendChild(marker);
|
836
|
-
line.appendChild(tooltip);
|
837
|
-
}
|
838
|
-
|
839
|
-
//allow this to play nicely with the line-numbers plugin
|
840
|
-
if(hasClass(pre, 'line-numbers')) {
|
841
|
-
//need to attack to pre as when line-numbers is enabled, the code tag is relatively which screws up the positioning
|
842
|
-
pre.appendChild(line);
|
843
|
-
} else {
|
844
|
-
(pre.querySelector('code') || pre).appendChild(line);
|
845
|
-
}
|
846
|
-
});
|
847
|
-
}
|
848
|
-
|
849
|
-
function applyHash() {
|
850
|
-
var hash = location.hash.slice(1);
|
851
|
-
|
852
|
-
// Remove pre-existing temporary lines
|
853
|
-
$$('.temporary.line-highlight').forEach(function (line) {
|
854
|
-
line.parentNode.removeChild(line);
|
855
|
-
});
|
856
|
-
|
857
|
-
var range = (hash.match(/\.([\d,-]+)$/) || [,''])[1];
|
858
|
-
|
859
|
-
if (!range || document.getElementById(hash)) {
|
860
|
-
return;
|
861
|
-
}
|
862
|
-
|
863
|
-
var id = hash.slice(0, hash.lastIndexOf('.')),
|
864
|
-
pre = document.getElementById(id);
|
865
|
-
|
866
|
-
if (!pre) {
|
867
|
-
return;
|
868
|
-
}
|
869
|
-
|
870
|
-
if (!pre.hasAttribute('data-line')) {
|
871
|
-
pre.setAttribute('data-line', '');
|
872
|
-
}
|
873
|
-
|
874
|
-
highlightLines(pre, range, 'temporary ');
|
875
|
-
|
876
|
-
document.querySelector('.temporary.line-highlight').scrollIntoView();
|
877
|
-
}
|
878
|
-
|
879
|
-
var fakeTimer = 0; // Hack to limit the number of times applyHash() runs
|
880
|
-
|
881
|
-
Prism.hooks.add('complete', function(env) {
|
882
|
-
var pre = env.element.parentNode;
|
883
|
-
var lines = pre && pre.getAttribute('data-line');
|
884
|
-
|
885
|
-
if (!pre || !lines || !/pre/i.test(pre.nodeName)) {
|
886
|
-
return;
|
887
|
-
}
|
888
|
-
|
889
|
-
clearTimeout(fakeTimer);
|
890
|
-
|
891
|
-
$$('.line-highlight', pre).forEach(function (line) {
|
892
|
-
line.parentNode.removeChild(line);
|
893
|
-
});
|
894
|
-
|
895
|
-
highlightLines(pre, lines);
|
896
|
-
|
897
|
-
fakeTimer = setTimeout(applyHash, 1);
|
898
|
-
});
|
899
|
-
|
900
|
-
if(window.addEventListener) {
|
901
|
-
window.addEventListener('hashchange', applyHash);
|
902
|
-
}
|
903
|
-
|
904
|
-
})();
|
905
|
-
|
906
|
-
(function() {
|
907
|
-
|
908
|
-
if (typeof self === 'undefined' || !self.Prism || !self.document) {
|
909
|
-
return;
|
910
|
-
}
|
911
|
-
|
912
|
-
Prism.hooks.add('complete', function (env) {
|
913
|
-
if (!env.code) {
|
914
|
-
return;
|
915
|
-
}
|
916
|
-
|
917
|
-
// works only for <code> wrapped inside <pre> (not inline)
|
918
|
-
var pre = env.element.parentNode;
|
919
|
-
var clsReg = /\s*\bline-numbers\b\s*/;
|
920
|
-
if (
|
921
|
-
!pre || !/pre/i.test(pre.nodeName) ||
|
922
|
-
// Abort only if nor the <pre> nor the <code> have the class
|
923
|
-
(!clsReg.test(pre.className) && !clsReg.test(env.element.className))
|
924
|
-
) {
|
925
|
-
return;
|
926
|
-
}
|
927
|
-
|
928
|
-
if (env.element.querySelector(".line-numbers-rows")) {
|
929
|
-
// Abort if line numbers already exists
|
930
|
-
return;
|
931
|
-
}
|
932
|
-
|
933
|
-
if (clsReg.test(env.element.className)) {
|
934
|
-
// Remove the class "line-numbers" from the <code>
|
935
|
-
env.element.className = env.element.className.replace(clsReg, '');
|
936
|
-
}
|
937
|
-
if (!clsReg.test(pre.className)) {
|
938
|
-
// Add the class "line-numbers" to the <pre>
|
939
|
-
pre.className += ' line-numbers';
|
940
|
-
}
|
941
|
-
|
942
|
-
var match = env.code.match(/\n(?!$)/g);
|
943
|
-
var linesNum = match ? match.length + 1 : 1;
|
944
|
-
var lineNumbersWrapper;
|
945
|
-
|
946
|
-
var lines = new Array(linesNum + 1);
|
947
|
-
lines = lines.join('<span></span>');
|
948
|
-
|
949
|
-
lineNumbersWrapper = document.createElement('span');
|
950
|
-
lineNumbersWrapper.className = 'line-numbers-rows';
|
951
|
-
lineNumbersWrapper.innerHTML = lines;
|
952
|
-
|
953
|
-
if (pre.hasAttribute('data-start')) {
|
954
|
-
pre.style.counterReset = 'linenumber ' + (parseInt(pre.getAttribute('data-start'), 10) - 1);
|
955
|
-
}
|
956
|
-
|
957
|
-
env.element.appendChild(lineNumbersWrapper);
|
958
|
-
|
959
|
-
});
|
960
|
-
|
961
|
-
}());
|