1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
4 | (factory((global.dl = global.dl || {})));
|
5 | }(this, (function (exports) { 'use strict';
|
6 |
|
7 | var html = function(dom) {
|
8 | if (!dom.querySelector("html").getAttribute("lang")) {
|
9 | dom.querySelector("html").setAttribute("lang", "en");
|
10 | }
|
11 |
|
12 | var head = dom.querySelector("head");
|
13 |
|
14 |
|
15 | if (!dom.querySelector("meta[charset]")) {
|
16 | var meta = dom.createElement("meta");
|
17 | meta.setAttribute("charset", "utf-8");
|
18 | head.appendChild(meta);
|
19 | }
|
20 | if (!dom.querySelector("meta[name=viewport]")) {
|
21 | var meta$1 = dom.createElement("meta");
|
22 | meta$1.setAttribute("name", "viewport");
|
23 | meta$1.setAttribute("content", "width=device-width, initial-scale=1");
|
24 | head.appendChild(meta$1);
|
25 | }
|
26 | };
|
27 |
|
28 | var base = "html {\n font: 400 15px/1.55em -apple-system, BlinkMacSystemFont, \"Roboto\", sans-serif;\n}\n\nhtml {\n -ms-text-size-adjust: 100%;\n -webkit-text-size-adjust: 100%;\n text-size-adjust: 100%;\n}\nbody {\n margin: 0;\n}\n\n/*\nhtml, body, div, span, applet, object, iframe,\nh1, h2, h3, h4, h5, h6, p, blockquote, pre,\na, abbr, acronym, address, big, cite, code,\ndel, dfn, em, img, ins, kbd, q, s, samp,\nsmall, strike, strong, sub, sup, tt, var,\nb, u, i, center,\ndl, dt, dd, ol, ul, li,\nfieldset, form, label, legend,\ntable, caption, tbody, tfoot, thead, tr, th, td,\narticle, aside, canvas, details, embed,\nfigure, figcaption, footer, header, hgroup,\nmenu, nav, output, ruby, section, summary,\ntime, mark, audio, video {\n\tmargin: 0;\n\tpadding: 0;\n\tborder: 0;\n\tfont-size: 100%;\n\tfont: inherit;\n\tvertical-align: baseline;\n}\narticle, aside, details, figcaption, figure,\nfooter, header, hgroup, menu, nav, section {\n\tdisplay: block;\n}\nbody {\n\tline-height: 1;\n}\nol, ul {\n\tlist-style: none;\n}\nblockquote, q {\n\tquotes: none;\n}\nblockquote:before, blockquote:after,\nq:before, q:after {\n\tcontent: '';\n\tcontent: none;\n}\ntable {\n\tborder-collapse: collapse;\n\tborder-spacing: 0;\n}*/\n";
|
29 |
|
30 | var layout = ".l-body,\n.l-page,\ndt-article > * {\n margin-left: 24px;\n margin-right: 24px;\n box-sizing: border-box;\n}\n\n@media(min-width: 768px) {\n .l-body,\n .l-page,\n dt-article > * {\n margin-left: 72px;\n margin-right: 72px;\n }\n}\n\n@media(min-width: 1080px) {\n .l-body,\n dt-article > * {\n margin-left: calc(50% - 984px / 2);\n width: 648px;\n }\n .l-body-outset,\n dt-article .l-body-outset {\n margin-left: calc(50% - 984px / 2 - 24px);\n width: calc(648px + 48px);\n }\n .l-middle,\n dt-article .l-middle {\n width: 816px;\n margin-left: calc(50% - 984px / 2);\n }\n .l-page,\n dt-article .l-page {\n width: 984px;\n margin-left: auto;\n margin-right: auto;\n }\n .l-page-outset,\n dt-article .l-page-outset {\n width: 1080px;\n margin-left: auto;\n margin-right: auto;\n }\n .l-screen,\n dt-article .l-screen {\n margin-left: auto;\n margin-right: auto;\n width: auto;\n }\n .l-screen-inset,\n dt-article .l-screen-inset {\n margin-left: 24px;\n margin-right: 24px;\n width: auto;\n }\n .l-gutter,\n dt-article .l-gutter {\n clear: both;\n float: right;\n margin-top: 0;\n margin-left: 24px;\n margin-right: calc((100vw - 960px) / 2);\n width: calc((984px - 648px) / 2 - 24px);\n }\n /* Side */\n .side.l-body,\n dt-article .side.l-body {\n clear: both;\n float: right;\n margin-top: 0;\n margin-left: 48px;\n margin-right: calc((100vw - 984px + 648px) / 2);\n width: calc(648px / 2 - 24px);\n }\n .side.l-body-outset,\n dt-article .side.l-body-outset {\n clear: both;\n float: right;\n margin-top: 0;\n margin-left: 48px;\n margin-right: calc((100vw - 984px + 648px - 48px) / 2);\n width: calc(648px / 2 - 48px + 24px);\n }\n .side.l-page,\n dt-article .side.l-page {\n clear: both;\n float: right;\n margin-top: 0;\n margin-left: 48px;\n margin-right: calc((100vw - 984px) / 2);\n width: calc(960px / 2 - 48px);\n }\n}\n";
|
31 |
|
32 | var article = "dt-article {\n color: rgba(0, 0, 0, 0.8);\n font: 15px/1.55em -apple-system, BlinkMacSystemFont, \"Roboto\", sans-serif;\n}\n\n@media(min-width: 1024px) {\n dt-article {\n font-size: 20px;\n }\n}\n\ndt-article h1 {\n font-weight: 700;\n font-size: 32px;\n line-height: 1.1em;\n /*-webkit-font-smoothing: antialiased;*/\n}\n\n@media(min-width: 1024px) {\n dt-article h1 {\n font-size: 50px;\n margin-bottom: 12px;\n letter-spacing: -0.025em;\n }\n}\n\n@media(min-width: 1024px) {\n dt-article > h1:first-of-type {\n margin-top: 100px;\n }\n}\n\ndt-article h2 {\n font-weight: 400;\n font-size: 28px;\n line-height: 1.25em;\n margin-top: 12px;\n margin-bottom: 24px;\n}\n\ndt-article h1 + h2 {\n padding-bottom: 48px;\n margin-bottom: 48px;\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n}\n\ndt-article h3 {\n font-weight: 700;\n font-size: 20px;\n line-height: 1.4em;\n margin-top: 24px;\n margin-bottom: 24px;\n}\n\ndt-article h4 {\n font-weight: 600;\n text-transform: uppercase;\n font-size: 14px;\n line-height: 1.4em;\n}\n\ndt-article a {\n color: inherit;\n}\n\ndt-article p {\n margin-bottom: 24px;\n -webkit-font-smoothing: antialiased;\n /*font-family: Georgia, serif;*/\n}\n\ndt-article p a {\n /*text-decoration: none;*/\n /*background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.25) 50%, rgba(0, 0, 0, 0) 50%);*/\n /*background-repeat: repeat-x;*/\n /*background-size: 2px 1em;*/\n /*background-position: 0 1.25em;*/\n}\n\ndt-article p .link {\n text-decoration: underline;\n cursor: pointer;\n}\n\n\n\ndt-article ul {\n padding-left: 20px;\n}\n\ndt-article li {\n /*margin-bottom: 24px;*/\n}\n\ndt-article pre {\n font-size: 14px;\n margin-bottom: 20px;\n}\n\n\ndt-article hr {\n border: none;\n border-bottom: 1px solid rgba(0, 0, 0, 0.2);\n margin-top: 60px;\n margin-bottom: 60px;\n}\n\ndt-article section {\n margin-top: 60px;\n margin-bottom: 60px;\n}\n\n\n/* Figure */\n\ndt-article figure {\n position: relative;\n margin-top: 30px;\n margin-bottom: 30px;\n}\n\n@media(min-width: 1024px) {\n dt-article figure {\n margin-top: 48px;\n margin-bottom: 48px;\n }\n}\n\ndt-article figure img {\n width: 100%;\n}\n\ndt-article figure svg text,\ndt-article figure svg tspan {\n}\n\ndt-article figure figcaption {\n color: rgba(0, 0, 0, 0.6);\n font-size: 12px;\n line-height: 1.5em;\n}\n@media(min-width: 1024px) {\n dt-article figure figcaption {\n font-size: 13px;\n }\n}\n\ndt-article figure.external img {\n background: white;\n border: 1px solid rgba(0, 0, 0, 0.1);\n box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1);\n padding: 18px;\n box-sizing: border-box;\n}\n\ndt-article figure figcaption a {\n color: rgba(0, 0, 0, 0.6);\n}\n\n/*dt-article figure figcaption::before {\n position: relative;\n display: block;\n top: -20px;\n content: \"\";\n width: 25px;\n border-top: 1px solid rgba(0, 0, 0, 0.3);\n}*/\n\ndt-article span.equation-mimic {\n font-family: georgia;\n font-size: 115%;\n font-style: italic;\n}\n\ndt-article figure figcaption b {\n font-weight: 600;\n color: rgba(0, 0, 0, 1.0);\n}\n\ndt-article > dt-code {\n display: block;\n}\n";
|
33 |
|
34 | var code = "/**\n * prism.js default theme for JavaScript, CSS and HTML\n * Based on dabblet (http://dabblet.com)\n * @author Lea Verou\n */\n\n code {\n white-space:pre-wrap;\n background: rgba(0, 0, 0, 0.04);\n border-radius: 2px;\n padding: 4px 7px;\n font-size: 15px;\n color: rgba(0, 0, 0, 0.6);\n }\n\n pre code {\n display: block;\n background: white;\n border: 1px solid rgba(0, 0, 0, 0.08);\n box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);\n }\n\n\ncode[class*=\"language-\"],\npre[class*=\"language-\"] {\n\tcolor: black;\n\ttext-shadow: 0 1px white;\n\tfont-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;\n\ttext-align: left;\n\twhite-space: pre;\n\tword-spacing: normal;\n\tword-break: normal;\n\tword-wrap: normal;\n\tline-height: 1.5;\n\n\t-moz-tab-size: 4;\n\t-o-tab-size: 4;\n\ttab-size: 4;\n\n\t-webkit-hyphens: none;\n\t-moz-hyphens: none;\n\t-ms-hyphens: none;\n\thyphens: none;\n}\n\npre[class*=\"language-\"]::-moz-selection, pre[class*=\"language-\"] ::-moz-selection,\ncode[class*=\"language-\"]::-moz-selection, code[class*=\"language-\"] ::-moz-selection {\n\ttext-shadow: none;\n\tbackground: #b3d4fc;\n}\n\npre[class*=\"language-\"]::selection, pre[class*=\"language-\"] ::selection,\ncode[class*=\"language-\"]::selection, code[class*=\"language-\"] ::selection {\n\ttext-shadow: none;\n\tbackground: #b3d4fc;\n}\n\n@media print {\n\tcode[class*=\"language-\"],\n\tpre[class*=\"language-\"] {\n\t\ttext-shadow: none;\n\t}\n}\n\n/* Code blocks */\npre[class*=\"language-\"] {\n\toverflow: auto;\n}\n\n:not(pre) > code[class*=\"language-\"],\npre[class*=\"language-\"] {\n}\n\n/* Inline code */\n:not(pre) > code[class*=\"language-\"] {\n\twhite-space: normal;\n}\n\n.token.comment,\n.token.prolog,\n.token.doctype,\n.token.cdata {\n\tcolor: slategray;\n}\n\n.token.punctuation {\n\tcolor: #999;\n}\n\n.namespace {\n\topacity: .7;\n}\n\n.token.property,\n.token.tag,\n.token.boolean,\n.token.number,\n.token.constant,\n.token.symbol,\n.token.deleted {\n\tcolor: #905;\n}\n\n.token.selector,\n.token.attr-name,\n.token.string,\n.token.char,\n.token.builtin,\n.token.inserted {\n\tcolor: #690;\n}\n\n.token.operator,\n.token.entity,\n.token.url,\n.language-css .token.string,\n.style .token.string {\n\tcolor: #a67f59;\n\tbackground: hsla(0, 0%, 100%, .5);\n}\n\n.token.atrule,\n.token.attr-value,\n.token.keyword {\n\tcolor: #07a;\n}\n\n.token.function {\n\tcolor: #DD4A68;\n}\n\n.token.regex,\n.token.important,\n.token.variable {\n\tcolor: #e90;\n}\n\n.token.important,\n.token.bold {\n\tfont-weight: bold;\n}\n.token.italic {\n\tfont-style: italic;\n}\n\n.token.entity {\n\tcursor: help;\n}\n";
|
35 |
|
36 | var styles = function(dom) {
|
37 | var s = dom.createElement("style");
|
38 | s.textContent = base + layout + article + code;
|
39 | dom.querySelector("head").appendChild(s);
|
40 | };
|
41 |
|
42 | function isNothing(subject) {
|
43 | return (typeof subject === 'undefined') || (subject === null);
|
44 | }
|
45 |
|
46 |
|
47 | function isObject(subject) {
|
48 | return (typeof subject === 'object') && (subject !== null);
|
49 | }
|
50 |
|
51 |
|
52 | function toArray(sequence) {
|
53 | if (Array.isArray(sequence)) { return sequence; }
|
54 | else if (isNothing(sequence)) { return []; }
|
55 |
|
56 | return [ sequence ];
|
57 | }
|
58 |
|
59 |
|
60 | function extend(target, source) {
|
61 | var index, length, key, sourceKeys;
|
62 |
|
63 | if (source) {
|
64 | sourceKeys = Object.keys(source);
|
65 |
|
66 | for (index = 0, length = sourceKeys.length; index < length; index += 1) {
|
67 | key = sourceKeys[index];
|
68 | target[key] = source[key];
|
69 | }
|
70 | }
|
71 |
|
72 | return target;
|
73 | }
|
74 |
|
75 |
|
76 | function repeat(string, count) {
|
77 | var result = '', cycle;
|
78 |
|
79 | for (cycle = 0; cycle < count; cycle += 1) {
|
80 | result += string;
|
81 | }
|
82 |
|
83 | return result;
|
84 | }
|
85 |
|
86 |
|
87 | function isNegativeZero(number) {
|
88 | return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
|
89 | }
|
90 |
|
91 |
|
92 | var isNothing_1 = isNothing;
|
93 | var isObject_1 = isObject;
|
94 | var toArray_1 = toArray;
|
95 | var repeat_1 = repeat;
|
96 | var isNegativeZero_1 = isNegativeZero;
|
97 | var extend_1 = extend;
|
98 |
|
99 | var common$1 = {
|
100 | isNothing: isNothing_1,
|
101 | isObject: isObject_1,
|
102 | toArray: toArray_1,
|
103 | repeat: repeat_1,
|
104 | isNegativeZero: isNegativeZero_1,
|
105 | extend: extend_1
|
106 | };
|
107 |
|
108 |
|
109 |
|
110 | function YAMLException$2(reason, mark) {
|
111 |
|
112 | Error.call(this);
|
113 |
|
114 |
|
115 | if (Error.captureStackTrace) {
|
116 |
|
117 | Error.captureStackTrace(this, this.constructor);
|
118 | } else {
|
119 |
|
120 | this.stack = (new Error()).stack || '';
|
121 | }
|
122 |
|
123 | this.name = 'YAMLException';
|
124 | this.reason = reason;
|
125 | this.mark = mark;
|
126 | this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
|
127 | }
|
128 |
|
129 |
|
130 |
|
131 | YAMLException$2.prototype = Object.create(Error.prototype);
|
132 | YAMLException$2.prototype.constructor = YAMLException$2;
|
133 |
|
134 |
|
135 | YAMLException$2.prototype.toString = function toString(compact) {
|
136 | var result = this.name + ': ';
|
137 |
|
138 | result += this.reason || '(unknown reason)';
|
139 |
|
140 | if (!compact && this.mark) {
|
141 | result += ' ' + this.mark.toString();
|
142 | }
|
143 |
|
144 | return result;
|
145 | };
|
146 |
|
147 |
|
148 | var exception = YAMLException$2;
|
149 |
|
150 | var common$3 = common$1;
|
151 |
|
152 |
|
153 | function Mark$1(name, buffer, position, line, column) {
|
154 | this.name = name;
|
155 | this.buffer = buffer;
|
156 | this.position = position;
|
157 | this.line = line;
|
158 | this.column = column;
|
159 | }
|
160 |
|
161 |
|
162 | Mark$1.prototype.getSnippet = function getSnippet(indent, maxLength) {
|
163 | var this$1 = this;
|
164 |
|
165 | var head, start, tail, end, snippet;
|
166 |
|
167 | if (!this.buffer) { return null; }
|
168 |
|
169 | indent = indent || 4;
|
170 | maxLength = maxLength || 75;
|
171 |
|
172 | head = '';
|
173 | start = this.position;
|
174 |
|
175 | while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
|
176 | start -= 1;
|
177 | if (this$1.position - start > (maxLength / 2 - 1)) {
|
178 | head = ' ... ';
|
179 | start += 5;
|
180 | break;
|
181 | }
|
182 | }
|
183 |
|
184 | tail = '';
|
185 | end = this.position;
|
186 |
|
187 | while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
|
188 | end += 1;
|
189 | if (end - this$1.position > (maxLength / 2 - 1)) {
|
190 | tail = ' ... ';
|
191 | end -= 5;
|
192 | break;
|
193 | }
|
194 | }
|
195 |
|
196 | snippet = this.buffer.slice(start, end);
|
197 |
|
198 | return common$3.repeat(' ', indent) + head + snippet + tail + '\n' +
|
199 | common$3.repeat(' ', indent + this.position - start + head.length) + '^';
|
200 | };
|
201 |
|
202 |
|
203 | Mark$1.prototype.toString = function toString(compact) {
|
204 | var snippet, where = '';
|
205 |
|
206 | if (this.name) {
|
207 | where += 'in "' + this.name + '" ';
|
208 | }
|
209 |
|
210 | where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
|
211 |
|
212 | if (!compact) {
|
213 | snippet = this.getSnippet();
|
214 |
|
215 | if (snippet) {
|
216 | where += ':\n' + snippet;
|
217 | }
|
218 | }
|
219 |
|
220 | return where;
|
221 | };
|
222 |
|
223 |
|
224 | var mark = Mark$1;
|
225 |
|
226 | var YAMLException$4 = exception;
|
227 |
|
228 | var TYPE_CONSTRUCTOR_OPTIONS = [
|
229 | 'kind',
|
230 | 'resolve',
|
231 | 'construct',
|
232 | 'instanceOf',
|
233 | 'predicate',
|
234 | 'represent',
|
235 | 'defaultStyle',
|
236 | 'styleAliases'
|
237 | ];
|
238 |
|
239 | var YAML_NODE_KINDS = [
|
240 | 'scalar',
|
241 | 'sequence',
|
242 | 'mapping'
|
243 | ];
|
244 |
|
245 | function compileStyleAliases(map) {
|
246 | var result = {};
|
247 |
|
248 | if (map !== null) {
|
249 | Object.keys(map).forEach(function (style) {
|
250 | map[style].forEach(function (alias) {
|
251 | result[String(alias)] = style;
|
252 | });
|
253 | });
|
254 | }
|
255 |
|
256 | return result;
|
257 | }
|
258 |
|
259 | function Type$2(tag, options) {
|
260 | options = options || {};
|
261 |
|
262 | Object.keys(options).forEach(function (name) {
|
263 | if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
264 | throw new YAMLException$4('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
265 | }
|
266 | });
|
267 |
|
268 |
|
269 | this.tag = tag;
|
270 | this.kind = options['kind'] || null;
|
271 | this.resolve = options['resolve'] || function () { return true; };
|
272 | this.construct = options['construct'] || function (data) { return data; };
|
273 | this.instanceOf = options['instanceOf'] || null;
|
274 | this.predicate = options['predicate'] || null;
|
275 | this.represent = options['represent'] || null;
|
276 | this.defaultStyle = options['defaultStyle'] || null;
|
277 | this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
|
278 |
|
279 | if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
280 | throw new YAMLException$4('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
281 | }
|
282 | }
|
283 |
|
284 | var type = Type$2;
|
285 |
|
286 | var common$4 = common$1;
|
287 | var YAMLException$3 = exception;
|
288 | var Type$1 = type;
|
289 |
|
290 |
|
291 | function compileList(schema, name, result) {
|
292 | var exclude = [];
|
293 |
|
294 | schema.include.forEach(function (includedSchema) {
|
295 | result = compileList(includedSchema, name, result);
|
296 | });
|
297 |
|
298 | schema[name].forEach(function (currentType) {
|
299 | result.forEach(function (previousType, previousIndex) {
|
300 | if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
|
301 | exclude.push(previousIndex);
|
302 | }
|
303 | });
|
304 |
|
305 | result.push(currentType);
|
306 | });
|
307 |
|
308 | return result.filter(function (type$$1, index) {
|
309 | return exclude.indexOf(index) === -1;
|
310 | });
|
311 | }
|
312 |
|
313 |
|
314 | function compileMap(/* lists... */) {
|
315 | var arguments$1 = arguments;
|
316 |
|
317 | var result = {
|
318 | scalar: {},
|
319 | sequence: {},
|
320 | mapping: {},
|
321 | fallback: {}
|
322 | }, index, length;
|
323 |
|
324 | function collectType(type$$1) {
|
325 | result[type$$1.kind][type$$1.tag] = result['fallback'][type$$1.tag] = type$$1;
|
326 | }
|
327 |
|
328 | for (index = 0, length = arguments.length; index < length; index += 1) {
|
329 | arguments$1[index].forEach(collectType);
|
330 | }
|
331 | return result;
|
332 | }
|
333 |
|
334 |
|
335 | function Schema$2(definition) {
|
336 | this.include = definition.include || [];
|
337 | this.implicit = definition.implicit || [];
|
338 | this.explicit = definition.explicit || [];
|
339 |
|
340 | this.implicit.forEach(function (type$$1) {
|
341 | if (type$$1.loadKind && type$$1.loadKind !== 'scalar') {
|
342 | throw new YAMLException$3('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
|
343 | }
|
344 | });
|
345 |
|
346 | this.compiledImplicit = compileList(this, 'implicit', []);
|
347 | this.compiledExplicit = compileList(this, 'explicit', []);
|
348 | this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
|
349 | }
|
350 |
|
351 |
|
352 | Schema$2.DEFAULT = null;
|
353 |
|
354 |
|
355 | Schema$2.create = function createSchema() {
|
356 | var schemas, types;
|
357 |
|
358 | switch (arguments.length) {
|
359 | case 1:
|
360 | schemas = Schema$2.DEFAULT;
|
361 | types = arguments[0];
|
362 | break;
|
363 |
|
364 | case 2:
|
365 | schemas = arguments[0];
|
366 | types = arguments[1];
|
367 | break;
|
368 |
|
369 | default:
|
370 | throw new YAMLException$3('Wrong number of arguments for Schema.create function');
|
371 | }
|
372 |
|
373 | schemas = common$4.toArray(schemas);
|
374 | types = common$4.toArray(types);
|
375 |
|
376 | if (!schemas.every(function (schema) { return schema instanceof Schema$2; })) {
|
377 | throw new YAMLException$3('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
|
378 | }
|
379 |
|
380 | if (!types.every(function (type$$1) { return type$$1 instanceof Type$1; })) {
|
381 | throw new YAMLException$3('Specified list of YAML types (or a single Type object) contains a non-Type object.');
|
382 | }
|
383 |
|
384 | return new Schema$2({
|
385 | include: schemas,
|
386 | explicit: types
|
387 | });
|
388 | };
|
389 |
|
390 |
|
391 | var schema = Schema$2;
|
392 |
|
393 | var Type$3 = type;
|
394 |
|
395 | var str = new Type$3('tag:yaml.org,2002:str', {
|
396 | kind: 'scalar',
|
397 | construct: function (data) { return data !== null ? data : ''; }
|
398 | });
|
399 |
|
400 | var Type$4 = type;
|
401 |
|
402 | var seq = new Type$4('tag:yaml.org,2002:seq', {
|
403 | kind: 'sequence',
|
404 | construct: function (data) { return data !== null ? data : []; }
|
405 | });
|
406 |
|
407 | var Type$5 = type;
|
408 |
|
409 | var map = new Type$5('tag:yaml.org,2002:map', {
|
410 | kind: 'mapping',
|
411 | construct: function (data) { return data !== null ? data : {}; }
|
412 | });
|
413 |
|
414 | var Schema$5 = schema;
|
415 |
|
416 |
|
417 | var failsafe = new Schema$5({
|
418 | explicit: [
|
419 | str,
|
420 | seq,
|
421 | map
|
422 | ]
|
423 | });
|
424 |
|
425 | var Type$6 = type;
|
426 |
|
427 | function resolveYamlNull(data) {
|
428 | if (data === null) { return true; }
|
429 |
|
430 | var max = data.length;
|
431 |
|
432 | return (max === 1 && data === '~') ||
|
433 | (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
|
434 | }
|
435 |
|
436 | function constructYamlNull() {
|
437 | return null;
|
438 | }
|
439 |
|
440 | function isNull(object) {
|
441 | return object === null;
|
442 | }
|
443 |
|
444 | var _null = new Type$6('tag:yaml.org,2002:null', {
|
445 | kind: 'scalar',
|
446 | resolve: resolveYamlNull,
|
447 | construct: constructYamlNull,
|
448 | predicate: isNull,
|
449 | represent: {
|
450 | canonical: function () { return '~'; },
|
451 | lowercase: function () { return 'null'; },
|
452 | uppercase: function () { return 'NULL'; },
|
453 | camelcase: function () { return 'Null'; }
|
454 | },
|
455 | defaultStyle: 'lowercase'
|
456 | });
|
457 |
|
458 | var Type$7 = type;
|
459 |
|
460 | function resolveYamlBoolean(data) {
|
461 | if (data === null) { return false; }
|
462 |
|
463 | var max = data.length;
|
464 |
|
465 | return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
|
466 | (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
|
467 | }
|
468 |
|
469 | function constructYamlBoolean(data) {
|
470 | return data === 'true' ||
|
471 | data === 'True' ||
|
472 | data === 'TRUE';
|
473 | }
|
474 |
|
475 | function isBoolean(object) {
|
476 | return Object.prototype.toString.call(object) === '[object Boolean]';
|
477 | }
|
478 |
|
479 | var bool = new Type$7('tag:yaml.org,2002:bool', {
|
480 | kind: 'scalar',
|
481 | resolve: resolveYamlBoolean,
|
482 | construct: constructYamlBoolean,
|
483 | predicate: isBoolean,
|
484 | represent: {
|
485 | lowercase: function (object) { return object ? 'true' : 'false'; },
|
486 | uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
|
487 | camelcase: function (object) { return object ? 'True' : 'False'; }
|
488 | },
|
489 | defaultStyle: 'lowercase'
|
490 | });
|
491 |
|
492 | var common$5 = common$1;
|
493 | var Type$8 = type;
|
494 |
|
495 | function isHexCode(c) {
|
496 | return ((0x30 <= c) && (c <= 0x39)) ||
|
497 | ((0x41 <= c) && (c <= 0x46)) ||
|
498 | ((0x61 <= c) && (c <= 0x66));
|
499 | }
|
500 |
|
501 | function isOctCode(c) {
|
502 | return ((0x30 <= c) && (c <= 0x37));
|
503 | }
|
504 |
|
505 | function isDecCode(c) {
|
506 | return ((0x30 <= c) && (c <= 0x39));
|
507 | }
|
508 |
|
509 | function resolveYamlInteger(data) {
|
510 | if (data === null) { return false; }
|
511 |
|
512 | var max = data.length,
|
513 | index = 0,
|
514 | hasDigits = false,
|
515 | ch;
|
516 |
|
517 | if (!max) { return false; }
|
518 |
|
519 | ch = data[index];
|
520 |
|
521 |
|
522 | if (ch === '-' || ch === '+') {
|
523 | ch = data[++index];
|
524 | }
|
525 |
|
526 | if (ch === '0') {
|
527 |
|
528 | if (index + 1 === max) { return true; }
|
529 | ch = data[++index];
|
530 |
|
531 |
|
532 |
|
533 | if (ch === 'b') {
|
534 |
|
535 | index++;
|
536 |
|
537 | for (; index < max; index++) {
|
538 | ch = data[index];
|
539 | if (ch === '_') { continue; }
|
540 | if (ch !== '0' && ch !== '1') { return false; }
|
541 | hasDigits = true;
|
542 | }
|
543 | return hasDigits;
|
544 | }
|
545 |
|
546 |
|
547 | if (ch === 'x') {
|
548 |
|
549 | index++;
|
550 |
|
551 | for (; index < max; index++) {
|
552 | ch = data[index];
|
553 | if (ch === '_') { continue; }
|
554 | if (!isHexCode(data.charCodeAt(index))) { return false; }
|
555 | hasDigits = true;
|
556 | }
|
557 | return hasDigits;
|
558 | }
|
559 |
|
560 |
|
561 | for (; index < max; index++) {
|
562 | ch = data[index];
|
563 | if (ch === '_') { continue; }
|
564 | if (!isOctCode(data.charCodeAt(index))) { return false; }
|
565 | hasDigits = true;
|
566 | }
|
567 | return hasDigits;
|
568 | }
|
569 |
|
570 |
|
571 |
|
572 | for (; index < max; index++) {
|
573 | ch = data[index];
|
574 | if (ch === '_') { continue; }
|
575 | if (ch === ':') { break; }
|
576 | if (!isDecCode(data.charCodeAt(index))) {
|
577 | return false;
|
578 | }
|
579 | hasDigits = true;
|
580 | }
|
581 |
|
582 | if (!hasDigits) { return false; }
|
583 |
|
584 |
|
585 | if (ch !== ':') { return true; }
|
586 |
|
587 |
|
588 | return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
|
589 | }
|
590 |
|
591 | function constructYamlInteger(data) {
|
592 | var value = data, sign = 1, ch, base, digits = [];
|
593 |
|
594 | if (value.indexOf('_') !== -1) {
|
595 | value = value.replace(/_/g, '');
|
596 | }
|
597 |
|
598 | ch = value[0];
|
599 |
|
600 | if (ch === '-' || ch === '+') {
|
601 | if (ch === '-') { sign = -1; }
|
602 | value = value.slice(1);
|
603 | ch = value[0];
|
604 | }
|
605 |
|
606 | if (value === '0') { return 0; }
|
607 |
|
608 | if (ch === '0') {
|
609 | if (value[1] === 'b') { return sign * parseInt(value.slice(2), 2); }
|
610 | if (value[1] === 'x') { return sign * parseInt(value, 16); }
|
611 | return sign * parseInt(value, 8);
|
612 | }
|
613 |
|
614 | if (value.indexOf(':') !== -1) {
|
615 | value.split(':').forEach(function (v) {
|
616 | digits.unshift(parseInt(v, 10));
|
617 | });
|
618 |
|
619 | value = 0;
|
620 | base = 1;
|
621 |
|
622 | digits.forEach(function (d) {
|
623 | value += (d * base);
|
624 | base *= 60;
|
625 | });
|
626 |
|
627 | return sign * value;
|
628 |
|
629 | }
|
630 |
|
631 | return sign * parseInt(value, 10);
|
632 | }
|
633 |
|
634 | function isInteger(object) {
|
635 | return (Object.prototype.toString.call(object)) === '[object Number]' &&
|
636 | (object % 1 === 0 && !common$5.isNegativeZero(object));
|
637 | }
|
638 |
|
639 | var int_1 = new Type$8('tag:yaml.org,2002:int', {
|
640 | kind: 'scalar',
|
641 | resolve: resolveYamlInteger,
|
642 | construct: constructYamlInteger,
|
643 | predicate: isInteger,
|
644 | represent: {
|
645 | binary: function (object) { return '0b' + object.toString(2); },
|
646 | octal: function (object) { return '0' + object.toString(8); },
|
647 | decimal: function (object) { return object.toString(10); },
|
648 | hexadecimal: function (object) { return '0x' + object.toString(16).toUpperCase(); }
|
649 | },
|
650 | defaultStyle: 'decimal',
|
651 | styleAliases: {
|
652 | binary: [ 2, 'bin' ],
|
653 | octal: [ 8, 'oct' ],
|
654 | decimal: [ 10, 'dec' ],
|
655 | hexadecimal: [ 16, 'hex' ]
|
656 | }
|
657 | });
|
658 |
|
659 | var common$6 = common$1;
|
660 | var Type$9 = type;
|
661 |
|
662 | var YAML_FLOAT_PATTERN = new RegExp(
|
663 | '^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?' +
|
664 | '|\\.[0-9_]+(?:[eE][-+][0-9]+)?' +
|
665 | '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
|
666 | '|[-+]?\\.(?:inf|Inf|INF)' +
|
667 | '|\\.(?:nan|NaN|NAN))$');
|
668 |
|
669 | function resolveYamlFloat(data) {
|
670 | if (data === null) { return false; }
|
671 |
|
672 | if (!YAML_FLOAT_PATTERN.test(data)) { return false; }
|
673 |
|
674 | return true;
|
675 | }
|
676 |
|
677 | function constructYamlFloat(data) {
|
678 | var value, sign, base, digits;
|
679 |
|
680 | value = data.replace(/_/g, '').toLowerCase();
|
681 | sign = value[0] === '-' ? -1 : 1;
|
682 | digits = [];
|
683 |
|
684 | if ('+-'.indexOf(value[0]) >= 0) {
|
685 | value = value.slice(1);
|
686 | }
|
687 |
|
688 | if (value === '.inf') {
|
689 | return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
690 |
|
691 | } else if (value === '.nan') {
|
692 | return NaN;
|
693 |
|
694 | } else if (value.indexOf(':') >= 0) {
|
695 | value.split(':').forEach(function (v) {
|
696 | digits.unshift(parseFloat(v, 10));
|
697 | });
|
698 |
|
699 | value = 0.0;
|
700 | base = 1;
|
701 |
|
702 | digits.forEach(function (d) {
|
703 | value += d * base;
|
704 | base *= 60;
|
705 | });
|
706 |
|
707 | return sign * value;
|
708 |
|
709 | }
|
710 | return sign * parseFloat(value, 10);
|
711 | }
|
712 |
|
713 |
|
714 | var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
715 |
|
716 | function representYamlFloat(object, style) {
|
717 | var res;
|
718 |
|
719 | if (isNaN(object)) {
|
720 | switch (style) {
|
721 | case 'lowercase': return '.nan';
|
722 | case 'uppercase': return '.NAN';
|
723 | case 'camelcase': return '.NaN';
|
724 | }
|
725 | } else if (Number.POSITIVE_INFINITY === object) {
|
726 | switch (style) {
|
727 | case 'lowercase': return '.inf';
|
728 | case 'uppercase': return '.INF';
|
729 | case 'camelcase': return '.Inf';
|
730 | }
|
731 | } else if (Number.NEGATIVE_INFINITY === object) {
|
732 | switch (style) {
|
733 | case 'lowercase': return '-.inf';
|
734 | case 'uppercase': return '-.INF';
|
735 | case 'camelcase': return '-.Inf';
|
736 | }
|
737 | } else if (common$6.isNegativeZero(object)) {
|
738 | return '-0.0';
|
739 | }
|
740 |
|
741 | res = object.toString(10);
|
742 |
|
743 |
|
744 |
|
745 |
|
746 | return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
|
747 | }
|
748 |
|
749 | function isFloat(object) {
|
750 | return (Object.prototype.toString.call(object) === '[object Number]') &&
|
751 | (object % 1 !== 0 || common$6.isNegativeZero(object));
|
752 | }
|
753 |
|
754 | var float_1 = new Type$9('tag:yaml.org,2002:float', {
|
755 | kind: 'scalar',
|
756 | resolve: resolveYamlFloat,
|
757 | construct: constructYamlFloat,
|
758 | predicate: isFloat,
|
759 | represent: representYamlFloat,
|
760 | defaultStyle: 'lowercase'
|
761 | });
|
762 |
|
763 | var Schema$4 = schema;
|
764 |
|
765 |
|
766 | var json = new Schema$4({
|
767 | include: [
|
768 | failsafe
|
769 | ],
|
770 | implicit: [
|
771 | _null,
|
772 | bool,
|
773 | int_1,
|
774 | float_1
|
775 | ]
|
776 | });
|
777 |
|
778 | var Schema$3 = schema;
|
779 |
|
780 |
|
781 | var core = new Schema$3({
|
782 | include: [
|
783 | json
|
784 | ]
|
785 | });
|
786 |
|
787 | var Type$10 = type;
|
788 |
|
789 | var YAML_DATE_REGEXP = new RegExp(
|
790 | '^([0-9][0-9][0-9][0-9])' +
|
791 | '-([0-9][0-9])' +
|
792 | '-([0-9][0-9])$');
|
793 |
|
794 | var YAML_TIMESTAMP_REGEXP = new RegExp(
|
795 | '^([0-9][0-9][0-9][0-9])' +
|
796 | '-([0-9][0-9]?)' +
|
797 | '-([0-9][0-9]?)' +
|
798 | '(?:[Tt]|[ \\t]+)' +
|
799 | '([0-9][0-9]?)' +
|
800 | ':([0-9][0-9])' +
|
801 | ':([0-9][0-9])' +
|
802 | '(?:\\.([0-9]*))?' +
|
803 | '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' +
|
804 | '(?::([0-9][0-9]))?))?$');
|
805 |
|
806 | function resolveYamlTimestamp(data) {
|
807 | if (data === null) { return false; }
|
808 | if (YAML_DATE_REGEXP.exec(data) !== null) { return true; }
|
809 | if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) { return true; }
|
810 | return false;
|
811 | }
|
812 |
|
813 | function constructYamlTimestamp(data) {
|
814 | var match, year, month, day, hour, minute, second, fraction = 0,
|
815 | delta = null, tz_hour, tz_minute, date;
|
816 |
|
817 | match = YAML_DATE_REGEXP.exec(data);
|
818 | if (match === null) { match = YAML_TIMESTAMP_REGEXP.exec(data); }
|
819 |
|
820 | if (match === null) { throw new Error('Date resolve error'); }
|
821 |
|
822 |
|
823 |
|
824 | year = +(match[1]);
|
825 | month = +(match[2]) - 1;
|
826 | day = +(match[3]);
|
827 |
|
828 | if (!match[4]) {
|
829 | return new Date(Date.UTC(year, month, day));
|
830 | }
|
831 |
|
832 |
|
833 |
|
834 | hour = +(match[4]);
|
835 | minute = +(match[5]);
|
836 | second = +(match[6]);
|
837 |
|
838 | if (match[7]) {
|
839 | fraction = match[7].slice(0, 3);
|
840 | while (fraction.length < 3) {
|
841 | fraction += '0';
|
842 | }
|
843 | fraction = +fraction;
|
844 | }
|
845 |
|
846 |
|
847 |
|
848 | if (match[9]) {
|
849 | tz_hour = +(match[10]);
|
850 | tz_minute = +(match[11] || 0);
|
851 | delta = (tz_hour * 60 + tz_minute) * 60000;
|
852 | if (match[9] === '-') { delta = -delta; }
|
853 | }
|
854 |
|
855 | date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
856 |
|
857 | if (delta) { date.setTime(date.getTime() - delta); }
|
858 |
|
859 | return date;
|
860 | }
|
861 |
|
862 | function representYamlTimestamp(object /*, style*/) {
|
863 | return object.toISOString();
|
864 | }
|
865 |
|
866 | var timestamp = new Type$10('tag:yaml.org,2002:timestamp', {
|
867 | kind: 'scalar',
|
868 | resolve: resolveYamlTimestamp,
|
869 | construct: constructYamlTimestamp,
|
870 | instanceOf: Date,
|
871 | represent: representYamlTimestamp
|
872 | });
|
873 |
|
874 | var Type$11 = type;
|
875 |
|
876 | function resolveYamlMerge(data) {
|
877 | return data === '<<' || data === null;
|
878 | }
|
879 |
|
880 | var merge = new Type$11('tag:yaml.org,2002:merge', {
|
881 | kind: 'scalar',
|
882 | resolve: resolveYamlMerge
|
883 | });
|
884 |
|
885 | var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
886 |
|
887 | function commonjsRequire () {
|
888 | throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
|
889 | }
|
890 |
|
891 |
|
892 |
|
893 | function createCommonjsModule(fn, module) {
|
894 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
895 | }
|
896 |
|
897 | var NodeBuffer;
|
898 |
|
899 | try {
|
900 |
|
901 | var _require = commonjsRequire;
|
902 | NodeBuffer = _require('buffer').Buffer;
|
903 | } catch (__) {}
|
904 |
|
905 | var Type$12 = type;
|
906 |
|
907 |
|
908 |
|
909 | var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
|
910 |
|
911 |
|
912 | function resolveYamlBinary(data) {
|
913 | if (data === null) { return false; }
|
914 |
|
915 | var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
|
916 |
|
917 |
|
918 | for (idx = 0; idx < max; idx++) {
|
919 | code = map.indexOf(data.charAt(idx));
|
920 |
|
921 |
|
922 | if (code > 64) { continue; }
|
923 |
|
924 |
|
925 | if (code < 0) { return false; }
|
926 |
|
927 | bitlen += 6;
|
928 | }
|
929 |
|
930 |
|
931 | return (bitlen % 8) === 0;
|
932 | }
|
933 |
|
934 | function constructYamlBinary(data) {
|
935 | var idx, tailbits,
|
936 | input = data.replace(/[\r\n=]/g, ''),
|
937 | max = input.length,
|
938 | map = BASE64_MAP,
|
939 | bits = 0,
|
940 | result = [];
|
941 |
|
942 |
|
943 |
|
944 | for (idx = 0; idx < max; idx++) {
|
945 | if ((idx % 4 === 0) && idx) {
|
946 | result.push((bits >> 16) & 0xFF);
|
947 | result.push((bits >> 8) & 0xFF);
|
948 | result.push(bits & 0xFF);
|
949 | }
|
950 |
|
951 | bits = (bits << 6) | map.indexOf(input.charAt(idx));
|
952 | }
|
953 |
|
954 |
|
955 |
|
956 | tailbits = (max % 4) * 6;
|
957 |
|
958 | if (tailbits === 0) {
|
959 | result.push((bits >> 16) & 0xFF);
|
960 | result.push((bits >> 8) & 0xFF);
|
961 | result.push(bits & 0xFF);
|
962 | } else if (tailbits === 18) {
|
963 | result.push((bits >> 10) & 0xFF);
|
964 | result.push((bits >> 2) & 0xFF);
|
965 | } else if (tailbits === 12) {
|
966 | result.push((bits >> 4) & 0xFF);
|
967 | }
|
968 |
|
969 |
|
970 | if (NodeBuffer) { return new NodeBuffer(result); }
|
971 |
|
972 | return result;
|
973 | }
|
974 |
|
975 | function representYamlBinary(object /*, style*/) {
|
976 | var result = '', bits = 0, idx, tail,
|
977 | max = object.length,
|
978 | map = BASE64_MAP;
|
979 |
|
980 |
|
981 |
|
982 | for (idx = 0; idx < max; idx++) {
|
983 | if ((idx % 3 === 0) && idx) {
|
984 | result += map[(bits >> 18) & 0x3F];
|
985 | result += map[(bits >> 12) & 0x3F];
|
986 | result += map[(bits >> 6) & 0x3F];
|
987 | result += map[bits & 0x3F];
|
988 | }
|
989 |
|
990 | bits = (bits << 8) + object[idx];
|
991 | }
|
992 |
|
993 |
|
994 |
|
995 | tail = max % 3;
|
996 |
|
997 | if (tail === 0) {
|
998 | result += map[(bits >> 18) & 0x3F];
|
999 | result += map[(bits >> 12) & 0x3F];
|
1000 | result += map[(bits >> 6) & 0x3F];
|
1001 | result += map[bits & 0x3F];
|
1002 | } else if (tail === 2) {
|
1003 | result += map[(bits >> 10) & 0x3F];
|
1004 | result += map[(bits >> 4) & 0x3F];
|
1005 | result += map[(bits << 2) & 0x3F];
|
1006 | result += map[64];
|
1007 | } else if (tail === 1) {
|
1008 | result += map[(bits >> 2) & 0x3F];
|
1009 | result += map[(bits << 4) & 0x3F];
|
1010 | result += map[64];
|
1011 | result += map[64];
|
1012 | }
|
1013 |
|
1014 | return result;
|
1015 | }
|
1016 |
|
1017 | function isBinary(object) {
|
1018 | return NodeBuffer && NodeBuffer.isBuffer(object);
|
1019 | }
|
1020 |
|
1021 | var binary = new Type$12('tag:yaml.org,2002:binary', {
|
1022 | kind: 'scalar',
|
1023 | resolve: resolveYamlBinary,
|
1024 | construct: constructYamlBinary,
|
1025 | predicate: isBinary,
|
1026 | represent: representYamlBinary
|
1027 | });
|
1028 |
|
1029 | var Type$13 = type;
|
1030 |
|
1031 | var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
1032 | var _toString = Object.prototype.toString;
|
1033 |
|
1034 | function resolveYamlOmap(data) {
|
1035 | if (data === null) { return true; }
|
1036 |
|
1037 | var objectKeys = [], index, length, pair, pairKey, pairHasKey,
|
1038 | object = data;
|
1039 |
|
1040 | for (index = 0, length = object.length; index < length; index += 1) {
|
1041 | pair = object[index];
|
1042 | pairHasKey = false;
|
1043 |
|
1044 | if (_toString.call(pair) !== '[object Object]') { return false; }
|
1045 |
|
1046 | for (pairKey in pair) {
|
1047 | if (_hasOwnProperty$1.call(pair, pairKey)) {
|
1048 | if (!pairHasKey) { pairHasKey = true; }
|
1049 | else { return false; }
|
1050 | }
|
1051 | }
|
1052 |
|
1053 | if (!pairHasKey) { return false; }
|
1054 |
|
1055 | if (objectKeys.indexOf(pairKey) === -1) { objectKeys.push(pairKey); }
|
1056 | else { return false; }
|
1057 | }
|
1058 |
|
1059 | return true;
|
1060 | }
|
1061 |
|
1062 | function constructYamlOmap(data) {
|
1063 | return data !== null ? data : [];
|
1064 | }
|
1065 |
|
1066 | var omap = new Type$13('tag:yaml.org,2002:omap', {
|
1067 | kind: 'sequence',
|
1068 | resolve: resolveYamlOmap,
|
1069 | construct: constructYamlOmap
|
1070 | });
|
1071 |
|
1072 | var Type$14 = type;
|
1073 |
|
1074 | var _toString$1 = Object.prototype.toString;
|
1075 |
|
1076 | function resolveYamlPairs(data) {
|
1077 | if (data === null) { return true; }
|
1078 |
|
1079 | var index, length, pair, keys, result,
|
1080 | object = data;
|
1081 |
|
1082 | result = new Array(object.length);
|
1083 |
|
1084 | for (index = 0, length = object.length; index < length; index += 1) {
|
1085 | pair = object[index];
|
1086 |
|
1087 | if (_toString$1.call(pair) !== '[object Object]') { return false; }
|
1088 |
|
1089 | keys = Object.keys(pair);
|
1090 |
|
1091 | if (keys.length !== 1) { return false; }
|
1092 |
|
1093 | result[index] = [ keys[0], pair[keys[0]] ];
|
1094 | }
|
1095 |
|
1096 | return true;
|
1097 | }
|
1098 |
|
1099 | function constructYamlPairs(data) {
|
1100 | if (data === null) { return []; }
|
1101 |
|
1102 | var index, length, pair, keys, result,
|
1103 | object = data;
|
1104 |
|
1105 | result = new Array(object.length);
|
1106 |
|
1107 | for (index = 0, length = object.length; index < length; index += 1) {
|
1108 | pair = object[index];
|
1109 |
|
1110 | keys = Object.keys(pair);
|
1111 |
|
1112 | result[index] = [ keys[0], pair[keys[0]] ];
|
1113 | }
|
1114 |
|
1115 | return result;
|
1116 | }
|
1117 |
|
1118 | var pairs = new Type$14('tag:yaml.org,2002:pairs', {
|
1119 | kind: 'sequence',
|
1120 | resolve: resolveYamlPairs,
|
1121 | construct: constructYamlPairs
|
1122 | });
|
1123 |
|
1124 | var Type$15 = type;
|
1125 |
|
1126 | var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
1127 |
|
1128 | function resolveYamlSet(data) {
|
1129 | if (data === null) { return true; }
|
1130 |
|
1131 | var key, object = data;
|
1132 |
|
1133 | for (key in object) {
|
1134 | if (_hasOwnProperty$2.call(object, key)) {
|
1135 | if (object[key] !== null) { return false; }
|
1136 | }
|
1137 | }
|
1138 |
|
1139 | return true;
|
1140 | }
|
1141 |
|
1142 | function constructYamlSet(data) {
|
1143 | return data !== null ? data : {};
|
1144 | }
|
1145 |
|
1146 | var set = new Type$15('tag:yaml.org,2002:set', {
|
1147 | kind: 'mapping',
|
1148 | resolve: resolveYamlSet,
|
1149 | construct: constructYamlSet
|
1150 | });
|
1151 |
|
1152 | var Schema$1 = schema;
|
1153 |
|
1154 |
|
1155 | var default_safe = new Schema$1({
|
1156 | include: [
|
1157 | core
|
1158 | ],
|
1159 | implicit: [
|
1160 | timestamp,
|
1161 | merge
|
1162 | ],
|
1163 | explicit: [
|
1164 | binary,
|
1165 | omap,
|
1166 | pairs,
|
1167 | set
|
1168 | ]
|
1169 | });
|
1170 |
|
1171 | var Type$16 = type;
|
1172 |
|
1173 | function resolveJavascriptUndefined() {
|
1174 | return true;
|
1175 | }
|
1176 |
|
1177 | function constructJavascriptUndefined() {
|
1178 |
|
1179 | return undefined;
|
1180 | }
|
1181 |
|
1182 | function representJavascriptUndefined() {
|
1183 | return '';
|
1184 | }
|
1185 |
|
1186 | function isUndefined(object) {
|
1187 | return typeof object === 'undefined';
|
1188 | }
|
1189 |
|
1190 | var _undefined = new Type$16('tag:yaml.org,2002:js/undefined', {
|
1191 | kind: 'scalar',
|
1192 | resolve: resolveJavascriptUndefined,
|
1193 | construct: constructJavascriptUndefined,
|
1194 | predicate: isUndefined,
|
1195 | represent: representJavascriptUndefined
|
1196 | });
|
1197 |
|
1198 | var Type$17 = type;
|
1199 |
|
1200 | function resolveJavascriptRegExp(data) {
|
1201 | if (data === null) { return false; }
|
1202 | if (data.length === 0) { return false; }
|
1203 |
|
1204 | var regexp = data,
|
1205 | tail = /\/([gim]*)$/.exec(data),
|
1206 | modifiers = '';
|
1207 |
|
1208 |
|
1209 |
|
1210 | if (regexp[0] === '/') {
|
1211 | if (tail) { modifiers = tail[1]; }
|
1212 |
|
1213 | if (modifiers.length > 3) { return false; }
|
1214 |
|
1215 | if (regexp[regexp.length - modifiers.length - 1] !== '/') { return false; }
|
1216 | }
|
1217 |
|
1218 | return true;
|
1219 | }
|
1220 |
|
1221 | function constructJavascriptRegExp(data) {
|
1222 | var regexp = data,
|
1223 | tail = /\/([gim]*)$/.exec(data),
|
1224 | modifiers = '';
|
1225 |
|
1226 |
|
1227 | if (regexp[0] === '/') {
|
1228 | if (tail) { modifiers = tail[1]; }
|
1229 | regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
|
1230 | }
|
1231 |
|
1232 | return new RegExp(regexp, modifiers);
|
1233 | }
|
1234 |
|
1235 | function representJavascriptRegExp(object /*, style*/) {
|
1236 | var result = '/' + object.source + '/';
|
1237 |
|
1238 | if (object.global) { result += 'g'; }
|
1239 | if (object.multiline) { result += 'm'; }
|
1240 | if (object.ignoreCase) { result += 'i'; }
|
1241 |
|
1242 | return result;
|
1243 | }
|
1244 |
|
1245 | function isRegExp(object) {
|
1246 | return Object.prototype.toString.call(object) === '[object RegExp]';
|
1247 | }
|
1248 |
|
1249 | var regexp = new Type$17('tag:yaml.org,2002:js/regexp', {
|
1250 | kind: 'scalar',
|
1251 | resolve: resolveJavascriptRegExp,
|
1252 | construct: constructJavascriptRegExp,
|
1253 | predicate: isRegExp,
|
1254 | represent: representJavascriptRegExp
|
1255 | });
|
1256 |
|
1257 | var esprima;
|
1258 |
|
1259 |
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 |
|
1265 |
|
1266 | try {
|
1267 |
|
1268 | var _require$1 = commonjsRequire;
|
1269 | esprima = _require$1('esprima');
|
1270 | } catch (_) {
|
1271 |
|
1272 | if (typeof window !== 'undefined') { esprima = window.esprima; }
|
1273 | }
|
1274 |
|
1275 | var Type$18 = type;
|
1276 |
|
1277 | function resolveJavascriptFunction(data) {
|
1278 | if (data === null) { return false; }
|
1279 |
|
1280 | try {
|
1281 | var source = '(' + data + ')',
|
1282 | ast = esprima.parse(source, { range: true });
|
1283 |
|
1284 | if (ast.type !== 'Program' ||
|
1285 | ast.body.length !== 1 ||
|
1286 | ast.body[0].type !== 'ExpressionStatement' ||
|
1287 | ast.body[0].expression.type !== 'FunctionExpression') {
|
1288 | return false;
|
1289 | }
|
1290 |
|
1291 | return true;
|
1292 | } catch (err) {
|
1293 | return false;
|
1294 | }
|
1295 | }
|
1296 |
|
1297 | function constructJavascriptFunction(data) {
|
1298 |
|
1299 |
|
1300 | var source = '(' + data + ')',
|
1301 | ast = esprima.parse(source, { range: true }),
|
1302 | params = [],
|
1303 | body;
|
1304 |
|
1305 | if (ast.type !== 'Program' ||
|
1306 | ast.body.length !== 1 ||
|
1307 | ast.body[0].type !== 'ExpressionStatement' ||
|
1308 | ast.body[0].expression.type !== 'FunctionExpression') {
|
1309 | throw new Error('Failed to resolve function');
|
1310 | }
|
1311 |
|
1312 | ast.body[0].expression.params.forEach(function (param) {
|
1313 | params.push(param.name);
|
1314 | });
|
1315 |
|
1316 | body = ast.body[0].expression.body.range;
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 | return new Function(params, source.slice(body[0] + 1, body[1] - 1));
|
1322 | }
|
1323 |
|
1324 | function representJavascriptFunction(object /*, style*/) {
|
1325 | return object.toString();
|
1326 | }
|
1327 |
|
1328 | function isFunction(object) {
|
1329 | return Object.prototype.toString.call(object) === '[object Function]';
|
1330 | }
|
1331 |
|
1332 | var _function = new Type$18('tag:yaml.org,2002:js/function', {
|
1333 | kind: 'scalar',
|
1334 | resolve: resolveJavascriptFunction,
|
1335 | construct: constructJavascriptFunction,
|
1336 | predicate: isFunction,
|
1337 | represent: representJavascriptFunction
|
1338 | });
|
1339 |
|
1340 | var Schema$6 = schema;
|
1341 |
|
1342 |
|
1343 | var default_full = Schema$6.DEFAULT = new Schema$6({
|
1344 | include: [
|
1345 | default_safe
|
1346 | ],
|
1347 | explicit: [
|
1348 | _undefined,
|
1349 | regexp,
|
1350 | _function
|
1351 | ]
|
1352 | });
|
1353 |
|
1354 | var common = common$1;
|
1355 | var YAMLException$1 = exception;
|
1356 | var Mark = mark;
|
1357 | var DEFAULT_SAFE_SCHEMA$1 = default_safe;
|
1358 | var DEFAULT_FULL_SCHEMA$1 = default_full;
|
1359 |
|
1360 |
|
1361 | var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
1362 |
|
1363 |
|
1364 | var CONTEXT_FLOW_IN = 1;
|
1365 | var CONTEXT_FLOW_OUT = 2;
|
1366 | var CONTEXT_BLOCK_IN = 3;
|
1367 | var CONTEXT_BLOCK_OUT = 4;
|
1368 |
|
1369 |
|
1370 | var CHOMPING_CLIP = 1;
|
1371 | var CHOMPING_STRIP = 2;
|
1372 | var CHOMPING_KEEP = 3;
|
1373 |
|
1374 |
|
1375 | var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
1376 | var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
1377 | var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
1378 | var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
1379 | var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
1380 |
|
1381 |
|
1382 | function is_EOL(c) {
|
1383 | return (c === 0x0A) || (c === 0x0D);
|
1384 | }
|
1385 |
|
1386 | function is_WHITE_SPACE(c) {
|
1387 | return (c === 0x09) || (c === 0x20);
|
1388 | }
|
1389 |
|
1390 | function is_WS_OR_EOL(c) {
|
1391 | return (c === 0x09) ||
|
1392 | (c === 0x20) ||
|
1393 | (c === 0x0A) ||
|
1394 | (c === 0x0D);
|
1395 | }
|
1396 |
|
1397 | function is_FLOW_INDICATOR(c) {
|
1398 | return c === 0x2C ||
|
1399 | c === 0x5B ||
|
1400 | c === 0x5D ||
|
1401 | c === 0x7B ||
|
1402 | c === 0x7D;
|
1403 | }
|
1404 |
|
1405 | function fromHexCode(c) {
|
1406 | var lc;
|
1407 |
|
1408 | if ((0x30 <= c) && (c <= 0x39)) {
|
1409 | return c - 0x30;
|
1410 | }
|
1411 |
|
1412 |
|
1413 | lc = c | 0x20;
|
1414 |
|
1415 | if ((0x61 <= lc) && (lc <= 0x66)) {
|
1416 | return lc - 0x61 + 10;
|
1417 | }
|
1418 |
|
1419 | return -1;
|
1420 | }
|
1421 |
|
1422 | function escapedHexLen(c) {
|
1423 | if (c === 0x78) { return 2; }
|
1424 | if (c === 0x75) { return 4; }
|
1425 | if (c === 0x55) { return 8; }
|
1426 | return 0;
|
1427 | }
|
1428 |
|
1429 | function fromDecimalCode(c) {
|
1430 | if ((0x30 <= c) && (c <= 0x39)) {
|
1431 | return c - 0x30;
|
1432 | }
|
1433 |
|
1434 | return -1;
|
1435 | }
|
1436 |
|
1437 | function simpleEscapeSequence(c) {
|
1438 | return (c === 0x30) ? '\x00' :
|
1439 | (c === 0x61) ? '\x07' :
|
1440 | (c === 0x62) ? '\x08' :
|
1441 | (c === 0x74) ? '\x09' :
|
1442 | (c === 0x09) ? '\x09' :
|
1443 | (c === 0x6E) ? '\x0A' :
|
1444 | (c === 0x76) ? '\x0B' :
|
1445 | (c === 0x66) ? '\x0C' :
|
1446 | (c === 0x72) ? '\x0D' :
|
1447 | (c === 0x65) ? '\x1B' :
|
1448 | (c === 0x20) ? ' ' :
|
1449 | (c === 0x22) ? '\x22' :
|
1450 | (c === 0x2F) ? '/' :
|
1451 | (c === 0x5C) ? '\x5C' :
|
1452 | (c === 0x4E) ? '\x85' :
|
1453 | (c === 0x5F) ? '\xA0' :
|
1454 | (c === 0x4C) ? '\u2028' :
|
1455 | (c === 0x50) ? '\u2029' : '';
|
1456 | }
|
1457 |
|
1458 | function charFromCodepoint(c) {
|
1459 | if (c <= 0xFFFF) {
|
1460 | return String.fromCharCode(c);
|
1461 | }
|
1462 |
|
1463 |
|
1464 | return String.fromCharCode(((c - 0x010000) >> 10) + 0xD800,
|
1465 | ((c - 0x010000) & 0x03FF) + 0xDC00);
|
1466 | }
|
1467 |
|
1468 | var simpleEscapeCheck = new Array(256);
|
1469 | var simpleEscapeMap = new Array(256);
|
1470 | for (var i = 0; i < 256; i++) {
|
1471 | simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
1472 | simpleEscapeMap[i] = simpleEscapeSequence(i);
|
1473 | }
|
1474 |
|
1475 |
|
1476 | function State(input, options) {
|
1477 | this.input = input;
|
1478 |
|
1479 | this.filename = options['filename'] || null;
|
1480 | this.schema = options['schema'] || DEFAULT_FULL_SCHEMA$1;
|
1481 | this.onWarning = options['onWarning'] || null;
|
1482 | this.legacy = options['legacy'] || false;
|
1483 | this.json = options['json'] || false;
|
1484 | this.listener = options['listener'] || null;
|
1485 |
|
1486 | this.implicitTypes = this.schema.compiledImplicit;
|
1487 | this.typeMap = this.schema.compiledTypeMap;
|
1488 |
|
1489 | this.length = input.length;
|
1490 | this.position = 0;
|
1491 | this.line = 0;
|
1492 | this.lineStart = 0;
|
1493 | this.lineIndent = 0;
|
1494 |
|
1495 | this.documents = [];
|
1496 |
|
1497 | |
1498 |
|
1499 |
|
1500 |
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 | }
|
1508 |
|
1509 |
|
1510 | function generateError(state, message) {
|
1511 | return new YAMLException$1(
|
1512 | message,
|
1513 | new Mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
|
1514 | }
|
1515 |
|
1516 | function throwError(state, message) {
|
1517 | throw generateError(state, message);
|
1518 | }
|
1519 |
|
1520 | function throwWarning(state, message) {
|
1521 | if (state.onWarning) {
|
1522 | state.onWarning.call(null, generateError(state, message));
|
1523 | }
|
1524 | }
|
1525 |
|
1526 |
|
1527 | var directiveHandlers = {
|
1528 |
|
1529 | YAML: function handleYamlDirective(state, name, args) {
|
1530 |
|
1531 | var match, major, minor;
|
1532 |
|
1533 | if (state.version !== null) {
|
1534 | throwError(state, 'duplication of %YAML directive');
|
1535 | }
|
1536 |
|
1537 | if (args.length !== 1) {
|
1538 | throwError(state, 'YAML directive accepts exactly one argument');
|
1539 | }
|
1540 |
|
1541 | match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
1542 |
|
1543 | if (match === null) {
|
1544 | throwError(state, 'ill-formed argument of the YAML directive');
|
1545 | }
|
1546 |
|
1547 | major = parseInt(match[1], 10);
|
1548 | minor = parseInt(match[2], 10);
|
1549 |
|
1550 | if (major !== 1) {
|
1551 | throwError(state, 'unacceptable YAML version of the document');
|
1552 | }
|
1553 |
|
1554 | state.version = args[0];
|
1555 | state.checkLineBreaks = (minor < 2);
|
1556 |
|
1557 | if (minor !== 1 && minor !== 2) {
|
1558 | throwWarning(state, 'unsupported YAML version of the document');
|
1559 | }
|
1560 | },
|
1561 |
|
1562 | TAG: function handleTagDirective(state, name, args) {
|
1563 |
|
1564 | var handle, prefix;
|
1565 |
|
1566 | if (args.length !== 2) {
|
1567 | throwError(state, 'TAG directive accepts exactly two arguments');
|
1568 | }
|
1569 |
|
1570 | handle = args[0];
|
1571 | prefix = args[1];
|
1572 |
|
1573 | if (!PATTERN_TAG_HANDLE.test(handle)) {
|
1574 | throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
|
1575 | }
|
1576 |
|
1577 | if (_hasOwnProperty.call(state.tagMap, handle)) {
|
1578 | throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
1579 | }
|
1580 |
|
1581 | if (!PATTERN_TAG_URI.test(prefix)) {
|
1582 | throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
|
1583 | }
|
1584 |
|
1585 | state.tagMap[handle] = prefix;
|
1586 | }
|
1587 | };
|
1588 |
|
1589 |
|
1590 | function captureSegment(state, start, end, checkJson) {
|
1591 | var _position, _length, _character, _result;
|
1592 |
|
1593 | if (start < end) {
|
1594 | _result = state.input.slice(start, end);
|
1595 |
|
1596 | if (checkJson) {
|
1597 | for (_position = 0, _length = _result.length;
|
1598 | _position < _length;
|
1599 | _position += 1) {
|
1600 | _character = _result.charCodeAt(_position);
|
1601 | if (!(_character === 0x09 ||
|
1602 | (0x20 <= _character && _character <= 0x10FFFF))) {
|
1603 | throwError(state, 'expected valid JSON character');
|
1604 | }
|
1605 | }
|
1606 | } else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
1607 | throwError(state, 'the stream contains non-printable characters');
|
1608 | }
|
1609 |
|
1610 | state.result += _result;
|
1611 | }
|
1612 | }
|
1613 |
|
1614 | function mergeMappings(state, destination, source, overridableKeys) {
|
1615 | var sourceKeys, key, index, quantity;
|
1616 |
|
1617 | if (!common.isObject(source)) {
|
1618 | throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
|
1619 | }
|
1620 |
|
1621 | sourceKeys = Object.keys(source);
|
1622 |
|
1623 | for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
1624 | key = sourceKeys[index];
|
1625 |
|
1626 | if (!_hasOwnProperty.call(destination, key)) {
|
1627 | destination[key] = source[key];
|
1628 | overridableKeys[key] = true;
|
1629 | }
|
1630 | }
|
1631 | }
|
1632 |
|
1633 | function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode) {
|
1634 | var index, quantity;
|
1635 |
|
1636 | keyNode = String(keyNode);
|
1637 |
|
1638 | if (_result === null) {
|
1639 | _result = {};
|
1640 | }
|
1641 |
|
1642 | if (keyTag === 'tag:yaml.org,2002:merge') {
|
1643 | if (Array.isArray(valueNode)) {
|
1644 | for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
1645 | mergeMappings(state, _result, valueNode[index], overridableKeys);
|
1646 | }
|
1647 | } else {
|
1648 | mergeMappings(state, _result, valueNode, overridableKeys);
|
1649 | }
|
1650 | } else {
|
1651 | if (!state.json &&
|
1652 | !_hasOwnProperty.call(overridableKeys, keyNode) &&
|
1653 | _hasOwnProperty.call(_result, keyNode)) {
|
1654 | throwError(state, 'duplicated mapping key');
|
1655 | }
|
1656 | _result[keyNode] = valueNode;
|
1657 | delete overridableKeys[keyNode];
|
1658 | }
|
1659 |
|
1660 | return _result;
|
1661 | }
|
1662 |
|
1663 | function readLineBreak(state) {
|
1664 | var ch;
|
1665 |
|
1666 | ch = state.input.charCodeAt(state.position);
|
1667 |
|
1668 | if (ch === 0x0A) {
|
1669 | state.position++;
|
1670 | } else if (ch === 0x0D) {
|
1671 | state.position++;
|
1672 | if (state.input.charCodeAt(state.position) === 0x0A) {
|
1673 | state.position++;
|
1674 | }
|
1675 | } else {
|
1676 | throwError(state, 'a line break is expected');
|
1677 | }
|
1678 |
|
1679 | state.line += 1;
|
1680 | state.lineStart = state.position;
|
1681 | }
|
1682 |
|
1683 | function skipSeparationSpace(state, allowComments, checkIndent) {
|
1684 | var lineBreaks = 0,
|
1685 | ch = state.input.charCodeAt(state.position);
|
1686 |
|
1687 | while (ch !== 0) {
|
1688 | while (is_WHITE_SPACE(ch)) {
|
1689 | ch = state.input.charCodeAt(++state.position);
|
1690 | }
|
1691 |
|
1692 | if (allowComments && ch === 0x23) {
|
1693 | do {
|
1694 | ch = state.input.charCodeAt(++state.position);
|
1695 | } while (ch !== 0x0A && ch !== 0x0D && ch !== 0);
|
1696 | }
|
1697 |
|
1698 | if (is_EOL(ch)) {
|
1699 | readLineBreak(state);
|
1700 |
|
1701 | ch = state.input.charCodeAt(state.position);
|
1702 | lineBreaks++;
|
1703 | state.lineIndent = 0;
|
1704 |
|
1705 | while (ch === 0x20) {
|
1706 | state.lineIndent++;
|
1707 | ch = state.input.charCodeAt(++state.position);
|
1708 | }
|
1709 | } else {
|
1710 | break;
|
1711 | }
|
1712 | }
|
1713 |
|
1714 | if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
1715 | throwWarning(state, 'deficient indentation');
|
1716 | }
|
1717 |
|
1718 | return lineBreaks;
|
1719 | }
|
1720 |
|
1721 | function testDocumentSeparator(state) {
|
1722 | var _position = state.position,
|
1723 | ch;
|
1724 |
|
1725 | ch = state.input.charCodeAt(_position);
|
1726 |
|
1727 |
|
1728 |
|
1729 | if ((ch === 0x2D || ch === 0x2E) &&
|
1730 | ch === state.input.charCodeAt(_position + 1) &&
|
1731 | ch === state.input.charCodeAt(_position + 2)) {
|
1732 |
|
1733 | _position += 3;
|
1734 |
|
1735 | ch = state.input.charCodeAt(_position);
|
1736 |
|
1737 | if (ch === 0 || is_WS_OR_EOL(ch)) {
|
1738 | return true;
|
1739 | }
|
1740 | }
|
1741 |
|
1742 | return false;
|
1743 | }
|
1744 |
|
1745 | function writeFoldedLines(state, count) {
|
1746 | if (count === 1) {
|
1747 | state.result += ' ';
|
1748 | } else if (count > 1) {
|
1749 | state.result += common.repeat('\n', count - 1);
|
1750 | }
|
1751 | }
|
1752 |
|
1753 |
|
1754 | function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
1755 | var preceding,
|
1756 | following,
|
1757 | captureStart,
|
1758 | captureEnd,
|
1759 | hasPendingContent,
|
1760 | _line,
|
1761 | _lineStart,
|
1762 | _lineIndent,
|
1763 | _kind = state.kind,
|
1764 | _result = state.result,
|
1765 | ch;
|
1766 |
|
1767 | ch = state.input.charCodeAt(state.position);
|
1768 |
|
1769 | if (is_WS_OR_EOL(ch) ||
|
1770 | is_FLOW_INDICATOR(ch) ||
|
1771 | ch === 0x23 ||
|
1772 | ch === 0x26 ||
|
1773 | ch === 0x2A ||
|
1774 | ch === 0x21 ||
|
1775 | ch === 0x7C ||
|
1776 | ch === 0x3E ||
|
1777 | ch === 0x27 ||
|
1778 | ch === 0x22 ||
|
1779 | ch === 0x25 ||
|
1780 | ch === 0x40 ||
|
1781 | ch === 0x60) {
|
1782 | return false;
|
1783 | }
|
1784 |
|
1785 | if (ch === 0x3F || ch === 0x2D) {
|
1786 | following = state.input.charCodeAt(state.position + 1);
|
1787 |
|
1788 | if (is_WS_OR_EOL(following) ||
|
1789 | withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
1790 | return false;
|
1791 | }
|
1792 | }
|
1793 |
|
1794 | state.kind = 'scalar';
|
1795 | state.result = '';
|
1796 | captureStart = captureEnd = state.position;
|
1797 | hasPendingContent = false;
|
1798 |
|
1799 | while (ch !== 0) {
|
1800 | if (ch === 0x3A) {
|
1801 | following = state.input.charCodeAt(state.position + 1);
|
1802 |
|
1803 | if (is_WS_OR_EOL(following) ||
|
1804 | withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
1805 | break;
|
1806 | }
|
1807 |
|
1808 | } else if (ch === 0x23) {
|
1809 | preceding = state.input.charCodeAt(state.position - 1);
|
1810 |
|
1811 | if (is_WS_OR_EOL(preceding)) {
|
1812 | break;
|
1813 | }
|
1814 |
|
1815 | } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
|
1816 | withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
1817 | break;
|
1818 |
|
1819 | } else if (is_EOL(ch)) {
|
1820 | _line = state.line;
|
1821 | _lineStart = state.lineStart;
|
1822 | _lineIndent = state.lineIndent;
|
1823 | skipSeparationSpace(state, false, -1);
|
1824 |
|
1825 | if (state.lineIndent >= nodeIndent) {
|
1826 | hasPendingContent = true;
|
1827 | ch = state.input.charCodeAt(state.position);
|
1828 | continue;
|
1829 | } else {
|
1830 | state.position = captureEnd;
|
1831 | state.line = _line;
|
1832 | state.lineStart = _lineStart;
|
1833 | state.lineIndent = _lineIndent;
|
1834 | break;
|
1835 | }
|
1836 | }
|
1837 |
|
1838 | if (hasPendingContent) {
|
1839 | captureSegment(state, captureStart, captureEnd, false);
|
1840 | writeFoldedLines(state, state.line - _line);
|
1841 | captureStart = captureEnd = state.position;
|
1842 | hasPendingContent = false;
|
1843 | }
|
1844 |
|
1845 | if (!is_WHITE_SPACE(ch)) {
|
1846 | captureEnd = state.position + 1;
|
1847 | }
|
1848 |
|
1849 | ch = state.input.charCodeAt(++state.position);
|
1850 | }
|
1851 |
|
1852 | captureSegment(state, captureStart, captureEnd, false);
|
1853 |
|
1854 | if (state.result) {
|
1855 | return true;
|
1856 | }
|
1857 |
|
1858 | state.kind = _kind;
|
1859 | state.result = _result;
|
1860 | return false;
|
1861 | }
|
1862 |
|
1863 | function readSingleQuotedScalar(state, nodeIndent) {
|
1864 | var ch,
|
1865 | captureStart, captureEnd;
|
1866 |
|
1867 | ch = state.input.charCodeAt(state.position);
|
1868 |
|
1869 | if (ch !== 0x27) {
|
1870 | return false;
|
1871 | }
|
1872 |
|
1873 | state.kind = 'scalar';
|
1874 | state.result = '';
|
1875 | state.position++;
|
1876 | captureStart = captureEnd = state.position;
|
1877 |
|
1878 | while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
1879 | if (ch === 0x27) {
|
1880 | captureSegment(state, captureStart, state.position, true);
|
1881 | ch = state.input.charCodeAt(++state.position);
|
1882 |
|
1883 | if (ch === 0x27) {
|
1884 | captureStart = state.position;
|
1885 | state.position++;
|
1886 | captureEnd = state.position;
|
1887 | } else {
|
1888 | return true;
|
1889 | }
|
1890 |
|
1891 | } else if (is_EOL(ch)) {
|
1892 | captureSegment(state, captureStart, captureEnd, true);
|
1893 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
1894 | captureStart = captureEnd = state.position;
|
1895 |
|
1896 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
1897 | throwError(state, 'unexpected end of the document within a single quoted scalar');
|
1898 |
|
1899 | } else {
|
1900 | state.position++;
|
1901 | captureEnd = state.position;
|
1902 | }
|
1903 | }
|
1904 |
|
1905 | throwError(state, 'unexpected end of the stream within a single quoted scalar');
|
1906 | }
|
1907 |
|
1908 | function readDoubleQuotedScalar(state, nodeIndent) {
|
1909 | var captureStart,
|
1910 | captureEnd,
|
1911 | hexLength,
|
1912 | hexResult,
|
1913 | tmp,
|
1914 | ch;
|
1915 |
|
1916 | ch = state.input.charCodeAt(state.position);
|
1917 |
|
1918 | if (ch !== 0x22) {
|
1919 | return false;
|
1920 | }
|
1921 |
|
1922 | state.kind = 'scalar';
|
1923 | state.result = '';
|
1924 | state.position++;
|
1925 | captureStart = captureEnd = state.position;
|
1926 |
|
1927 | while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
1928 | if (ch === 0x22) {
|
1929 | captureSegment(state, captureStart, state.position, true);
|
1930 | state.position++;
|
1931 | return true;
|
1932 |
|
1933 | } else if (ch === 0x5C) {
|
1934 | captureSegment(state, captureStart, state.position, true);
|
1935 | ch = state.input.charCodeAt(++state.position);
|
1936 |
|
1937 | if (is_EOL(ch)) {
|
1938 | skipSeparationSpace(state, false, nodeIndent);
|
1939 |
|
1940 |
|
1941 | } else if (ch < 256 && simpleEscapeCheck[ch]) {
|
1942 | state.result += simpleEscapeMap[ch];
|
1943 | state.position++;
|
1944 |
|
1945 | } else if ((tmp = escapedHexLen(ch)) > 0) {
|
1946 | hexLength = tmp;
|
1947 | hexResult = 0;
|
1948 |
|
1949 | for (; hexLength > 0; hexLength--) {
|
1950 | ch = state.input.charCodeAt(++state.position);
|
1951 |
|
1952 | if ((tmp = fromHexCode(ch)) >= 0) {
|
1953 | hexResult = (hexResult << 4) + tmp;
|
1954 |
|
1955 | } else {
|
1956 | throwError(state, 'expected hexadecimal character');
|
1957 | }
|
1958 | }
|
1959 |
|
1960 | state.result += charFromCodepoint(hexResult);
|
1961 |
|
1962 | state.position++;
|
1963 |
|
1964 | } else {
|
1965 | throwError(state, 'unknown escape sequence');
|
1966 | }
|
1967 |
|
1968 | captureStart = captureEnd = state.position;
|
1969 |
|
1970 | } else if (is_EOL(ch)) {
|
1971 | captureSegment(state, captureStart, captureEnd, true);
|
1972 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
1973 | captureStart = captureEnd = state.position;
|
1974 |
|
1975 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
1976 | throwError(state, 'unexpected end of the document within a double quoted scalar');
|
1977 |
|
1978 | } else {
|
1979 | state.position++;
|
1980 | captureEnd = state.position;
|
1981 | }
|
1982 | }
|
1983 |
|
1984 | throwError(state, 'unexpected end of the stream within a double quoted scalar');
|
1985 | }
|
1986 |
|
1987 | function readFlowCollection(state, nodeIndent) {
|
1988 | var readNext = true,
|
1989 | _line,
|
1990 | _tag = state.tag,
|
1991 | _result,
|
1992 | _anchor = state.anchor,
|
1993 | following,
|
1994 | terminator,
|
1995 | isPair,
|
1996 | isExplicitPair,
|
1997 | isMapping,
|
1998 | overridableKeys = {},
|
1999 | keyNode,
|
2000 | keyTag,
|
2001 | valueNode,
|
2002 | ch;
|
2003 |
|
2004 | ch = state.input.charCodeAt(state.position);
|
2005 |
|
2006 | if (ch === 0x5B) {
|
2007 | terminator = 0x5D;
|
2008 | isMapping = false;
|
2009 | _result = [];
|
2010 | } else if (ch === 0x7B) {
|
2011 | terminator = 0x7D;
|
2012 | isMapping = true;
|
2013 | _result = {};
|
2014 | } else {
|
2015 | return false;
|
2016 | }
|
2017 |
|
2018 | if (state.anchor !== null) {
|
2019 | state.anchorMap[state.anchor] = _result;
|
2020 | }
|
2021 |
|
2022 | ch = state.input.charCodeAt(++state.position);
|
2023 |
|
2024 | while (ch !== 0) {
|
2025 | skipSeparationSpace(state, true, nodeIndent);
|
2026 |
|
2027 | ch = state.input.charCodeAt(state.position);
|
2028 |
|
2029 | if (ch === terminator) {
|
2030 | state.position++;
|
2031 | state.tag = _tag;
|
2032 | state.anchor = _anchor;
|
2033 | state.kind = isMapping ? 'mapping' : 'sequence';
|
2034 | state.result = _result;
|
2035 | return true;
|
2036 | } else if (!readNext) {
|
2037 | throwError(state, 'missed comma between flow collection entries');
|
2038 | }
|
2039 |
|
2040 | keyTag = keyNode = valueNode = null;
|
2041 | isPair = isExplicitPair = false;
|
2042 |
|
2043 | if (ch === 0x3F) {
|
2044 | following = state.input.charCodeAt(state.position + 1);
|
2045 |
|
2046 | if (is_WS_OR_EOL(following)) {
|
2047 | isPair = isExplicitPair = true;
|
2048 | state.position++;
|
2049 | skipSeparationSpace(state, true, nodeIndent);
|
2050 | }
|
2051 | }
|
2052 |
|
2053 | _line = state.line;
|
2054 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
2055 | keyTag = state.tag;
|
2056 | keyNode = state.result;
|
2057 | skipSeparationSpace(state, true, nodeIndent);
|
2058 |
|
2059 | ch = state.input.charCodeAt(state.position);
|
2060 |
|
2061 | if ((isExplicitPair || state.line === _line) && ch === 0x3A) {
|
2062 | isPair = true;
|
2063 | ch = state.input.charCodeAt(++state.position);
|
2064 | skipSeparationSpace(state, true, nodeIndent);
|
2065 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
2066 | valueNode = state.result;
|
2067 | }
|
2068 |
|
2069 | if (isMapping) {
|
2070 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
|
2071 | } else if (isPair) {
|
2072 | _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
|
2073 | } else {
|
2074 | _result.push(keyNode);
|
2075 | }
|
2076 |
|
2077 | skipSeparationSpace(state, true, nodeIndent);
|
2078 |
|
2079 | ch = state.input.charCodeAt(state.position);
|
2080 |
|
2081 | if (ch === 0x2C) {
|
2082 | readNext = true;
|
2083 | ch = state.input.charCodeAt(++state.position);
|
2084 | } else {
|
2085 | readNext = false;
|
2086 | }
|
2087 | }
|
2088 |
|
2089 | throwError(state, 'unexpected end of the stream within a flow collection');
|
2090 | }
|
2091 |
|
2092 | function readBlockScalar(state, nodeIndent) {
|
2093 | var captureStart,
|
2094 | folding,
|
2095 | chomping = CHOMPING_CLIP,
|
2096 | didReadContent = false,
|
2097 | detectedIndent = false,
|
2098 | textIndent = nodeIndent,
|
2099 | emptyLines = 0,
|
2100 | atMoreIndented = false,
|
2101 | tmp,
|
2102 | ch;
|
2103 |
|
2104 | ch = state.input.charCodeAt(state.position);
|
2105 |
|
2106 | if (ch === 0x7C) {
|
2107 | folding = false;
|
2108 | } else if (ch === 0x3E) {
|
2109 | folding = true;
|
2110 | } else {
|
2111 | return false;
|
2112 | }
|
2113 |
|
2114 | state.kind = 'scalar';
|
2115 | state.result = '';
|
2116 |
|
2117 | while (ch !== 0) {
|
2118 | ch = state.input.charCodeAt(++state.position);
|
2119 |
|
2120 | if (ch === 0x2B || ch === 0x2D) {
|
2121 | if (CHOMPING_CLIP === chomping) {
|
2122 | chomping = (ch === 0x2B) ? CHOMPING_KEEP : CHOMPING_STRIP;
|
2123 | } else {
|
2124 | throwError(state, 'repeat of a chomping mode identifier');
|
2125 | }
|
2126 |
|
2127 | } else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
2128 | if (tmp === 0) {
|
2129 | throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
|
2130 | } else if (!detectedIndent) {
|
2131 | textIndent = nodeIndent + tmp - 1;
|
2132 | detectedIndent = true;
|
2133 | } else {
|
2134 | throwError(state, 'repeat of an indentation width identifier');
|
2135 | }
|
2136 |
|
2137 | } else {
|
2138 | break;
|
2139 | }
|
2140 | }
|
2141 |
|
2142 | if (is_WHITE_SPACE(ch)) {
|
2143 | do { ch = state.input.charCodeAt(++state.position); }
|
2144 | while (is_WHITE_SPACE(ch));
|
2145 |
|
2146 | if (ch === 0x23) {
|
2147 | do { ch = state.input.charCodeAt(++state.position); }
|
2148 | while (!is_EOL(ch) && (ch !== 0));
|
2149 | }
|
2150 | }
|
2151 |
|
2152 | while (ch !== 0) {
|
2153 | readLineBreak(state);
|
2154 | state.lineIndent = 0;
|
2155 |
|
2156 | ch = state.input.charCodeAt(state.position);
|
2157 |
|
2158 | while ((!detectedIndent || state.lineIndent < textIndent) &&
|
2159 | (ch === 0x20)) {
|
2160 | state.lineIndent++;
|
2161 | ch = state.input.charCodeAt(++state.position);
|
2162 | }
|
2163 |
|
2164 | if (!detectedIndent && state.lineIndent > textIndent) {
|
2165 | textIndent = state.lineIndent;
|
2166 | }
|
2167 |
|
2168 | if (is_EOL(ch)) {
|
2169 | emptyLines++;
|
2170 | continue;
|
2171 | }
|
2172 |
|
2173 |
|
2174 | if (state.lineIndent < textIndent) {
|
2175 |
|
2176 |
|
2177 | if (chomping === CHOMPING_KEEP) {
|
2178 | state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
2179 | } else if (chomping === CHOMPING_CLIP) {
|
2180 | if (didReadContent) {
|
2181 | state.result += '\n';
|
2182 | }
|
2183 | }
|
2184 |
|
2185 |
|
2186 | break;
|
2187 | }
|
2188 |
|
2189 |
|
2190 | if (folding) {
|
2191 |
|
2192 |
|
2193 | if (is_WHITE_SPACE(ch)) {
|
2194 | atMoreIndented = true;
|
2195 |
|
2196 | state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
2197 |
|
2198 |
|
2199 | } else if (atMoreIndented) {
|
2200 | atMoreIndented = false;
|
2201 | state.result += common.repeat('\n', emptyLines + 1);
|
2202 |
|
2203 |
|
2204 | } else if (emptyLines === 0) {
|
2205 | if (didReadContent) {
|
2206 | state.result += ' ';
|
2207 | }
|
2208 |
|
2209 |
|
2210 | } else {
|
2211 | state.result += common.repeat('\n', emptyLines);
|
2212 | }
|
2213 |
|
2214 |
|
2215 | } else {
|
2216 |
|
2217 | state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
2218 | }
|
2219 |
|
2220 | didReadContent = true;
|
2221 | detectedIndent = true;
|
2222 | emptyLines = 0;
|
2223 | captureStart = state.position;
|
2224 |
|
2225 | while (!is_EOL(ch) && (ch !== 0)) {
|
2226 | ch = state.input.charCodeAt(++state.position);
|
2227 | }
|
2228 |
|
2229 | captureSegment(state, captureStart, state.position, false);
|
2230 | }
|
2231 |
|
2232 | return true;
|
2233 | }
|
2234 |
|
2235 | function readBlockSequence(state, nodeIndent) {
|
2236 | var _line,
|
2237 | _tag = state.tag,
|
2238 | _anchor = state.anchor,
|
2239 | _result = [],
|
2240 | following,
|
2241 | detected = false,
|
2242 | ch;
|
2243 |
|
2244 | if (state.anchor !== null) {
|
2245 | state.anchorMap[state.anchor] = _result;
|
2246 | }
|
2247 |
|
2248 | ch = state.input.charCodeAt(state.position);
|
2249 |
|
2250 | while (ch !== 0) {
|
2251 |
|
2252 | if (ch !== 0x2D) {
|
2253 | break;
|
2254 | }
|
2255 |
|
2256 | following = state.input.charCodeAt(state.position + 1);
|
2257 |
|
2258 | if (!is_WS_OR_EOL(following)) {
|
2259 | break;
|
2260 | }
|
2261 |
|
2262 | detected = true;
|
2263 | state.position++;
|
2264 |
|
2265 | if (skipSeparationSpace(state, true, -1)) {
|
2266 | if (state.lineIndent <= nodeIndent) {
|
2267 | _result.push(null);
|
2268 | ch = state.input.charCodeAt(state.position);
|
2269 | continue;
|
2270 | }
|
2271 | }
|
2272 |
|
2273 | _line = state.line;
|
2274 | composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
2275 | _result.push(state.result);
|
2276 | skipSeparationSpace(state, true, -1);
|
2277 |
|
2278 | ch = state.input.charCodeAt(state.position);
|
2279 |
|
2280 | if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
|
2281 | throwError(state, 'bad indentation of a sequence entry');
|
2282 | } else if (state.lineIndent < nodeIndent) {
|
2283 | break;
|
2284 | }
|
2285 | }
|
2286 |
|
2287 | if (detected) {
|
2288 | state.tag = _tag;
|
2289 | state.anchor = _anchor;
|
2290 | state.kind = 'sequence';
|
2291 | state.result = _result;
|
2292 | return true;
|
2293 | }
|
2294 | return false;
|
2295 | }
|
2296 |
|
2297 | function readBlockMapping(state, nodeIndent, flowIndent) {
|
2298 | var following,
|
2299 | allowCompact,
|
2300 | _line,
|
2301 | _tag = state.tag,
|
2302 | _anchor = state.anchor,
|
2303 | _result = {},
|
2304 | overridableKeys = {},
|
2305 | keyTag = null,
|
2306 | keyNode = null,
|
2307 | valueNode = null,
|
2308 | atExplicitKey = false,
|
2309 | detected = false,
|
2310 | ch;
|
2311 |
|
2312 | if (state.anchor !== null) {
|
2313 | state.anchorMap[state.anchor] = _result;
|
2314 | }
|
2315 |
|
2316 | ch = state.input.charCodeAt(state.position);
|
2317 |
|
2318 | while (ch !== 0) {
|
2319 | following = state.input.charCodeAt(state.position + 1);
|
2320 | _line = state.line;
|
2321 |
|
2322 |
|
2323 |
|
2324 |
|
2325 |
|
2326 | if ((ch === 0x3F || ch === 0x3A) && is_WS_OR_EOL(following)) {
|
2327 |
|
2328 | if (ch === 0x3F) {
|
2329 | if (atExplicitKey) {
|
2330 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
2331 | keyTag = keyNode = valueNode = null;
|
2332 | }
|
2333 |
|
2334 | detected = true;
|
2335 | atExplicitKey = true;
|
2336 | allowCompact = true;
|
2337 |
|
2338 | } else if (atExplicitKey) {
|
2339 |
|
2340 | atExplicitKey = false;
|
2341 | allowCompact = true;
|
2342 |
|
2343 | } else {
|
2344 | throwError(state, 'incomplete explicit mapping pair; a key node is missed');
|
2345 | }
|
2346 |
|
2347 | state.position += 1;
|
2348 | ch = following;
|
2349 |
|
2350 |
|
2351 |
|
2352 |
|
2353 | } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
2354 |
|
2355 | if (state.line === _line) {
|
2356 | ch = state.input.charCodeAt(state.position);
|
2357 |
|
2358 | while (is_WHITE_SPACE(ch)) {
|
2359 | ch = state.input.charCodeAt(++state.position);
|
2360 | }
|
2361 |
|
2362 | if (ch === 0x3A) {
|
2363 | ch = state.input.charCodeAt(++state.position);
|
2364 |
|
2365 | if (!is_WS_OR_EOL(ch)) {
|
2366 | throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
|
2367 | }
|
2368 |
|
2369 | if (atExplicitKey) {
|
2370 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
2371 | keyTag = keyNode = valueNode = null;
|
2372 | }
|
2373 |
|
2374 | detected = true;
|
2375 | atExplicitKey = false;
|
2376 | allowCompact = false;
|
2377 | keyTag = state.tag;
|
2378 | keyNode = state.result;
|
2379 |
|
2380 | } else if (detected) {
|
2381 | throwError(state, 'can not read an implicit mapping pair; a colon is missed');
|
2382 |
|
2383 | } else {
|
2384 | state.tag = _tag;
|
2385 | state.anchor = _anchor;
|
2386 | return true;
|
2387 | }
|
2388 |
|
2389 | } else if (detected) {
|
2390 | throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
|
2391 |
|
2392 | } else {
|
2393 | state.tag = _tag;
|
2394 | state.anchor = _anchor;
|
2395 | return true;
|
2396 | }
|
2397 |
|
2398 | } else {
|
2399 | break;
|
2400 | }
|
2401 |
|
2402 |
|
2403 |
|
2404 |
|
2405 | if (state.line === _line || state.lineIndent > nodeIndent) {
|
2406 | if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
2407 | if (atExplicitKey) {
|
2408 | keyNode = state.result;
|
2409 | } else {
|
2410 | valueNode = state.result;
|
2411 | }
|
2412 | }
|
2413 |
|
2414 | if (!atExplicitKey) {
|
2415 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
|
2416 | keyTag = keyNode = valueNode = null;
|
2417 | }
|
2418 |
|
2419 | skipSeparationSpace(state, true, -1);
|
2420 | ch = state.input.charCodeAt(state.position);
|
2421 | }
|
2422 |
|
2423 | if (state.lineIndent > nodeIndent && (ch !== 0)) {
|
2424 | throwError(state, 'bad indentation of a mapping entry');
|
2425 | } else if (state.lineIndent < nodeIndent) {
|
2426 | break;
|
2427 | }
|
2428 | }
|
2429 |
|
2430 |
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 | if (atExplicitKey) {
|
2436 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
2437 | }
|
2438 |
|
2439 |
|
2440 | if (detected) {
|
2441 | state.tag = _tag;
|
2442 | state.anchor = _anchor;
|
2443 | state.kind = 'mapping';
|
2444 | state.result = _result;
|
2445 | }
|
2446 |
|
2447 | return detected;
|
2448 | }
|
2449 |
|
2450 | function readTagProperty(state) {
|
2451 | var _position,
|
2452 | isVerbatim = false,
|
2453 | isNamed = false,
|
2454 | tagHandle,
|
2455 | tagName,
|
2456 | ch;
|
2457 |
|
2458 | ch = state.input.charCodeAt(state.position);
|
2459 |
|
2460 | if (ch !== 0x21) { return false; }
|
2461 |
|
2462 | if (state.tag !== null) {
|
2463 | throwError(state, 'duplication of a tag property');
|
2464 | }
|
2465 |
|
2466 | ch = state.input.charCodeAt(++state.position);
|
2467 |
|
2468 | if (ch === 0x3C) {
|
2469 | isVerbatim = true;
|
2470 | ch = state.input.charCodeAt(++state.position);
|
2471 |
|
2472 | } else if (ch === 0x21) {
|
2473 | isNamed = true;
|
2474 | tagHandle = '!!';
|
2475 | ch = state.input.charCodeAt(++state.position);
|
2476 |
|
2477 | } else {
|
2478 | tagHandle = '!';
|
2479 | }
|
2480 |
|
2481 | _position = state.position;
|
2482 |
|
2483 | if (isVerbatim) {
|
2484 | do { ch = state.input.charCodeAt(++state.position); }
|
2485 | while (ch !== 0 && ch !== 0x3E);
|
2486 |
|
2487 | if (state.position < state.length) {
|
2488 | tagName = state.input.slice(_position, state.position);
|
2489 | ch = state.input.charCodeAt(++state.position);
|
2490 | } else {
|
2491 | throwError(state, 'unexpected end of the stream within a verbatim tag');
|
2492 | }
|
2493 | } else {
|
2494 | while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
2495 |
|
2496 | if (ch === 0x21) {
|
2497 | if (!isNamed) {
|
2498 | tagHandle = state.input.slice(_position - 1, state.position + 1);
|
2499 |
|
2500 | if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
2501 | throwError(state, 'named tag handle cannot contain such characters');
|
2502 | }
|
2503 |
|
2504 | isNamed = true;
|
2505 | _position = state.position + 1;
|
2506 | } else {
|
2507 | throwError(state, 'tag suffix cannot contain exclamation marks');
|
2508 | }
|
2509 | }
|
2510 |
|
2511 | ch = state.input.charCodeAt(++state.position);
|
2512 | }
|
2513 |
|
2514 | tagName = state.input.slice(_position, state.position);
|
2515 |
|
2516 | if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
2517 | throwError(state, 'tag suffix cannot contain flow indicator characters');
|
2518 | }
|
2519 | }
|
2520 |
|
2521 | if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
2522 | throwError(state, 'tag name cannot contain such characters: ' + tagName);
|
2523 | }
|
2524 |
|
2525 | if (isVerbatim) {
|
2526 | state.tag = tagName;
|
2527 |
|
2528 | } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
|
2529 | state.tag = state.tagMap[tagHandle] + tagName;
|
2530 |
|
2531 | } else if (tagHandle === '!') {
|
2532 | state.tag = '!' + tagName;
|
2533 |
|
2534 | } else if (tagHandle === '!!') {
|
2535 | state.tag = 'tag:yaml.org,2002:' + tagName;
|
2536 |
|
2537 | } else {
|
2538 | throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
2539 | }
|
2540 |
|
2541 | return true;
|
2542 | }
|
2543 |
|
2544 | function readAnchorProperty(state) {
|
2545 | var _position,
|
2546 | ch;
|
2547 |
|
2548 | ch = state.input.charCodeAt(state.position);
|
2549 |
|
2550 | if (ch !== 0x26) { return false; }
|
2551 |
|
2552 | if (state.anchor !== null) {
|
2553 | throwError(state, 'duplication of an anchor property');
|
2554 | }
|
2555 |
|
2556 | ch = state.input.charCodeAt(++state.position);
|
2557 | _position = state.position;
|
2558 |
|
2559 | while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
2560 | ch = state.input.charCodeAt(++state.position);
|
2561 | }
|
2562 |
|
2563 | if (state.position === _position) {
|
2564 | throwError(state, 'name of an anchor node must contain at least one character');
|
2565 | }
|
2566 |
|
2567 | state.anchor = state.input.slice(_position, state.position);
|
2568 | return true;
|
2569 | }
|
2570 |
|
2571 | function readAlias(state) {
|
2572 | var _position, alias,
|
2573 | ch;
|
2574 |
|
2575 | ch = state.input.charCodeAt(state.position);
|
2576 |
|
2577 | if (ch !== 0x2A) { return false; }
|
2578 |
|
2579 | ch = state.input.charCodeAt(++state.position);
|
2580 | _position = state.position;
|
2581 |
|
2582 | while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
2583 | ch = state.input.charCodeAt(++state.position);
|
2584 | }
|
2585 |
|
2586 | if (state.position === _position) {
|
2587 | throwError(state, 'name of an alias node must contain at least one character');
|
2588 | }
|
2589 |
|
2590 | alias = state.input.slice(_position, state.position);
|
2591 |
|
2592 | if (!state.anchorMap.hasOwnProperty(alias)) {
|
2593 | throwError(state, 'unidentified alias "' + alias + '"');
|
2594 | }
|
2595 |
|
2596 | state.result = state.anchorMap[alias];
|
2597 | skipSeparationSpace(state, true, -1);
|
2598 | return true;
|
2599 | }
|
2600 |
|
2601 | function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
2602 | var allowBlockStyles,
|
2603 | allowBlockScalars,
|
2604 | allowBlockCollections,
|
2605 | indentStatus = 1,
|
2606 | atNewLine = false,
|
2607 | hasContent = false,
|
2608 | typeIndex,
|
2609 | typeQuantity,
|
2610 | type,
|
2611 | flowIndent,
|
2612 | blockIndent;
|
2613 |
|
2614 | if (state.listener !== null) {
|
2615 | state.listener('open', state);
|
2616 | }
|
2617 |
|
2618 | state.tag = null;
|
2619 | state.anchor = null;
|
2620 | state.kind = null;
|
2621 | state.result = null;
|
2622 |
|
2623 | allowBlockStyles = allowBlockScalars = allowBlockCollections =
|
2624 | CONTEXT_BLOCK_OUT === nodeContext ||
|
2625 | CONTEXT_BLOCK_IN === nodeContext;
|
2626 |
|
2627 | if (allowToSeek) {
|
2628 | if (skipSeparationSpace(state, true, -1)) {
|
2629 | atNewLine = true;
|
2630 |
|
2631 | if (state.lineIndent > parentIndent) {
|
2632 | indentStatus = 1;
|
2633 | } else if (state.lineIndent === parentIndent) {
|
2634 | indentStatus = 0;
|
2635 | } else if (state.lineIndent < parentIndent) {
|
2636 | indentStatus = -1;
|
2637 | }
|
2638 | }
|
2639 | }
|
2640 |
|
2641 | if (indentStatus === 1) {
|
2642 | while (readTagProperty(state) || readAnchorProperty(state)) {
|
2643 | if (skipSeparationSpace(state, true, -1)) {
|
2644 | atNewLine = true;
|
2645 | allowBlockCollections = allowBlockStyles;
|
2646 |
|
2647 | if (state.lineIndent > parentIndent) {
|
2648 | indentStatus = 1;
|
2649 | } else if (state.lineIndent === parentIndent) {
|
2650 | indentStatus = 0;
|
2651 | } else if (state.lineIndent < parentIndent) {
|
2652 | indentStatus = -1;
|
2653 | }
|
2654 | } else {
|
2655 | allowBlockCollections = false;
|
2656 | }
|
2657 | }
|
2658 | }
|
2659 |
|
2660 | if (allowBlockCollections) {
|
2661 | allowBlockCollections = atNewLine || allowCompact;
|
2662 | }
|
2663 |
|
2664 | if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
2665 | if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
2666 | flowIndent = parentIndent;
|
2667 | } else {
|
2668 | flowIndent = parentIndent + 1;
|
2669 | }
|
2670 |
|
2671 | blockIndent = state.position - state.lineStart;
|
2672 |
|
2673 | if (indentStatus === 1) {
|
2674 | if (allowBlockCollections &&
|
2675 | (readBlockSequence(state, blockIndent) ||
|
2676 | readBlockMapping(state, blockIndent, flowIndent)) ||
|
2677 | readFlowCollection(state, flowIndent)) {
|
2678 | hasContent = true;
|
2679 | } else {
|
2680 | if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
|
2681 | readSingleQuotedScalar(state, flowIndent) ||
|
2682 | readDoubleQuotedScalar(state, flowIndent)) {
|
2683 | hasContent = true;
|
2684 |
|
2685 | } else if (readAlias(state)) {
|
2686 | hasContent = true;
|
2687 |
|
2688 | if (state.tag !== null || state.anchor !== null) {
|
2689 | throwError(state, 'alias node should not have any properties');
|
2690 | }
|
2691 |
|
2692 | } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
2693 | hasContent = true;
|
2694 |
|
2695 | if (state.tag === null) {
|
2696 | state.tag = '?';
|
2697 | }
|
2698 | }
|
2699 |
|
2700 | if (state.anchor !== null) {
|
2701 | state.anchorMap[state.anchor] = state.result;
|
2702 | }
|
2703 | }
|
2704 | } else if (indentStatus === 0) {
|
2705 |
|
2706 |
|
2707 | hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
2708 | }
|
2709 | }
|
2710 |
|
2711 | if (state.tag !== null && state.tag !== '!') {
|
2712 | if (state.tag === '?') {
|
2713 | for (typeIndex = 0, typeQuantity = state.implicitTypes.length;
|
2714 | typeIndex < typeQuantity;
|
2715 | typeIndex += 1) {
|
2716 | type = state.implicitTypes[typeIndex];
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 |
|
2722 | if (type.resolve(state.result)) {
|
2723 | state.result = type.construct(state.result);
|
2724 | state.tag = type.tag;
|
2725 | if (state.anchor !== null) {
|
2726 | state.anchorMap[state.anchor] = state.result;
|
2727 | }
|
2728 | break;
|
2729 | }
|
2730 | }
|
2731 | } else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
|
2732 | type = state.typeMap[state.kind || 'fallback'][state.tag];
|
2733 |
|
2734 | if (state.result !== null && type.kind !== state.kind) {
|
2735 | throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
|
2736 | }
|
2737 |
|
2738 | if (!type.resolve(state.result)) {
|
2739 | throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
|
2740 | } else {
|
2741 | state.result = type.construct(state.result);
|
2742 | if (state.anchor !== null) {
|
2743 | state.anchorMap[state.anchor] = state.result;
|
2744 | }
|
2745 | }
|
2746 | } else {
|
2747 | throwError(state, 'unknown tag !<' + state.tag + '>');
|
2748 | }
|
2749 | }
|
2750 |
|
2751 | if (state.listener !== null) {
|
2752 | state.listener('close', state);
|
2753 | }
|
2754 | return state.tag !== null || state.anchor !== null || hasContent;
|
2755 | }
|
2756 |
|
2757 | function readDocument(state) {
|
2758 | var documentStart = state.position,
|
2759 | _position,
|
2760 | directiveName,
|
2761 | directiveArgs,
|
2762 | hasDirectives = false,
|
2763 | ch;
|
2764 |
|
2765 | state.version = null;
|
2766 | state.checkLineBreaks = state.legacy;
|
2767 | state.tagMap = {};
|
2768 | state.anchorMap = {};
|
2769 |
|
2770 | while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
2771 | skipSeparationSpace(state, true, -1);
|
2772 |
|
2773 | ch = state.input.charCodeAt(state.position);
|
2774 |
|
2775 | if (state.lineIndent > 0 || ch !== 0x25) {
|
2776 | break;
|
2777 | }
|
2778 |
|
2779 | hasDirectives = true;
|
2780 | ch = state.input.charCodeAt(++state.position);
|
2781 | _position = state.position;
|
2782 |
|
2783 | while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
2784 | ch = state.input.charCodeAt(++state.position);
|
2785 | }
|
2786 |
|
2787 | directiveName = state.input.slice(_position, state.position);
|
2788 | directiveArgs = [];
|
2789 |
|
2790 | if (directiveName.length < 1) {
|
2791 | throwError(state, 'directive name must not be less than one character in length');
|
2792 | }
|
2793 |
|
2794 | while (ch !== 0) {
|
2795 | while (is_WHITE_SPACE(ch)) {
|
2796 | ch = state.input.charCodeAt(++state.position);
|
2797 | }
|
2798 |
|
2799 | if (ch === 0x23) {
|
2800 | do { ch = state.input.charCodeAt(++state.position); }
|
2801 | while (ch !== 0 && !is_EOL(ch));
|
2802 | break;
|
2803 | }
|
2804 |
|
2805 | if (is_EOL(ch)) { break; }
|
2806 |
|
2807 | _position = state.position;
|
2808 |
|
2809 | while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
2810 | ch = state.input.charCodeAt(++state.position);
|
2811 | }
|
2812 |
|
2813 | directiveArgs.push(state.input.slice(_position, state.position));
|
2814 | }
|
2815 |
|
2816 | if (ch !== 0) { readLineBreak(state); }
|
2817 |
|
2818 | if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
|
2819 | directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
2820 | } else {
|
2821 | throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
2822 | }
|
2823 | }
|
2824 |
|
2825 | skipSeparationSpace(state, true, -1);
|
2826 |
|
2827 | if (state.lineIndent === 0 &&
|
2828 | state.input.charCodeAt(state.position) === 0x2D &&
|
2829 | state.input.charCodeAt(state.position + 1) === 0x2D &&
|
2830 | state.input.charCodeAt(state.position + 2) === 0x2D) {
|
2831 | state.position += 3;
|
2832 | skipSeparationSpace(state, true, -1);
|
2833 |
|
2834 | } else if (hasDirectives) {
|
2835 | throwError(state, 'directives end mark is expected');
|
2836 | }
|
2837 |
|
2838 | composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
2839 | skipSeparationSpace(state, true, -1);
|
2840 |
|
2841 | if (state.checkLineBreaks &&
|
2842 | PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
2843 | throwWarning(state, 'non-ASCII line breaks are interpreted as content');
|
2844 | }
|
2845 |
|
2846 | state.documents.push(state.result);
|
2847 |
|
2848 | if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
2849 |
|
2850 | if (state.input.charCodeAt(state.position) === 0x2E) {
|
2851 | state.position += 3;
|
2852 | skipSeparationSpace(state, true, -1);
|
2853 | }
|
2854 | return;
|
2855 | }
|
2856 |
|
2857 | if (state.position < (state.length - 1)) {
|
2858 | throwError(state, 'end of the stream or a document separator is expected');
|
2859 | } else {
|
2860 | return;
|
2861 | }
|
2862 | }
|
2863 |
|
2864 |
|
2865 | function loadDocuments(input, options) {
|
2866 | input = String(input);
|
2867 | options = options || {};
|
2868 |
|
2869 | if (input.length !== 0) {
|
2870 |
|
2871 |
|
2872 | if (input.charCodeAt(input.length - 1) !== 0x0A &&
|
2873 | input.charCodeAt(input.length - 1) !== 0x0D) {
|
2874 | input += '\n';
|
2875 | }
|
2876 |
|
2877 |
|
2878 | if (input.charCodeAt(0) === 0xFEFF) {
|
2879 | input = input.slice(1);
|
2880 | }
|
2881 | }
|
2882 |
|
2883 | var state = new State(input, options);
|
2884 |
|
2885 |
|
2886 | state.input += '\0';
|
2887 |
|
2888 | while (state.input.charCodeAt(state.position) === 0x20) {
|
2889 | state.lineIndent += 1;
|
2890 | state.position += 1;
|
2891 | }
|
2892 |
|
2893 | while (state.position < (state.length - 1)) {
|
2894 | readDocument(state);
|
2895 | }
|
2896 |
|
2897 | return state.documents;
|
2898 | }
|
2899 |
|
2900 |
|
2901 | function loadAll$1(input, iterator, options) {
|
2902 | var documents = loadDocuments(input, options), index, length;
|
2903 |
|
2904 | for (index = 0, length = documents.length; index < length; index += 1) {
|
2905 | iterator(documents[index]);
|
2906 | }
|
2907 | }
|
2908 |
|
2909 |
|
2910 | function load$1(input, options) {
|
2911 | var documents = loadDocuments(input, options);
|
2912 |
|
2913 | if (documents.length === 0) {
|
2914 |
|
2915 | return undefined;
|
2916 | } else if (documents.length === 1) {
|
2917 | return documents[0];
|
2918 | }
|
2919 | throw new YAMLException$1('expected a single document in the stream, but found more');
|
2920 | }
|
2921 |
|
2922 |
|
2923 | function safeLoadAll$1(input, output, options) {
|
2924 | loadAll$1(input, output, common.extend({ schema: DEFAULT_SAFE_SCHEMA$1 }, options));
|
2925 | }
|
2926 |
|
2927 |
|
2928 | function safeLoad$1(input, options) {
|
2929 | return load$1(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA$1 }, options));
|
2930 | }
|
2931 |
|
2932 |
|
2933 | var loadAll_1 = loadAll$1;
|
2934 | var load_1 = load$1;
|
2935 | var safeLoadAll_1 = safeLoadAll$1;
|
2936 | var safeLoad_1 = safeLoad$1;
|
2937 |
|
2938 | var loader$1 = {
|
2939 | loadAll: loadAll_1,
|
2940 | load: load_1,
|
2941 | safeLoadAll: safeLoadAll_1,
|
2942 | safeLoad: safeLoad_1
|
2943 | };
|
2944 |
|
2945 | var common$7 = common$1;
|
2946 | var YAMLException$5 = exception;
|
2947 | var DEFAULT_FULL_SCHEMA$2 = default_full;
|
2948 | var DEFAULT_SAFE_SCHEMA$2 = default_safe;
|
2949 |
|
2950 | var _toString$2 = Object.prototype.toString;
|
2951 | var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
2952 |
|
2953 | var CHAR_TAB = 0x09;
|
2954 | var CHAR_LINE_FEED = 0x0A;
|
2955 | var CHAR_SPACE = 0x20;
|
2956 | var CHAR_EXCLAMATION = 0x21;
|
2957 | var CHAR_DOUBLE_QUOTE = 0x22;
|
2958 | var CHAR_SHARP = 0x23;
|
2959 | var CHAR_PERCENT = 0x25;
|
2960 | var CHAR_AMPERSAND = 0x26;
|
2961 | var CHAR_SINGLE_QUOTE = 0x27;
|
2962 | var CHAR_ASTERISK = 0x2A;
|
2963 | var CHAR_COMMA = 0x2C;
|
2964 | var CHAR_MINUS = 0x2D;
|
2965 | var CHAR_COLON = 0x3A;
|
2966 | var CHAR_GREATER_THAN = 0x3E;
|
2967 | var CHAR_QUESTION = 0x3F;
|
2968 | var CHAR_COMMERCIAL_AT = 0x40;
|
2969 | var CHAR_LEFT_SQUARE_BRACKET = 0x5B;
|
2970 | var CHAR_RIGHT_SQUARE_BRACKET = 0x5D;
|
2971 | var CHAR_GRAVE_ACCENT = 0x60;
|
2972 | var CHAR_LEFT_CURLY_BRACKET = 0x7B;
|
2973 | var CHAR_VERTICAL_LINE = 0x7C;
|
2974 | var CHAR_RIGHT_CURLY_BRACKET = 0x7D;
|
2975 |
|
2976 | var ESCAPE_SEQUENCES = {};
|
2977 |
|
2978 | ESCAPE_SEQUENCES[0x00] = '\\0';
|
2979 | ESCAPE_SEQUENCES[0x07] = '\\a';
|
2980 | ESCAPE_SEQUENCES[0x08] = '\\b';
|
2981 | ESCAPE_SEQUENCES[0x09] = '\\t';
|
2982 | ESCAPE_SEQUENCES[0x0A] = '\\n';
|
2983 | ESCAPE_SEQUENCES[0x0B] = '\\v';
|
2984 | ESCAPE_SEQUENCES[0x0C] = '\\f';
|
2985 | ESCAPE_SEQUENCES[0x0D] = '\\r';
|
2986 | ESCAPE_SEQUENCES[0x1B] = '\\e';
|
2987 | ESCAPE_SEQUENCES[0x22] = '\\"';
|
2988 | ESCAPE_SEQUENCES[0x5C] = '\\\\';
|
2989 | ESCAPE_SEQUENCES[0x85] = '\\N';
|
2990 | ESCAPE_SEQUENCES[0xA0] = '\\_';
|
2991 | ESCAPE_SEQUENCES[0x2028] = '\\L';
|
2992 | ESCAPE_SEQUENCES[0x2029] = '\\P';
|
2993 |
|
2994 | var DEPRECATED_BOOLEANS_SYNTAX = [
|
2995 | 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
|
2996 | 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
|
2997 | ];
|
2998 |
|
2999 | function compileStyleMap(schema, map) {
|
3000 | var result, keys, index, length, tag, style, type;
|
3001 |
|
3002 | if (map === null) { return {}; }
|
3003 |
|
3004 | result = {};
|
3005 | keys = Object.keys(map);
|
3006 |
|
3007 | for (index = 0, length = keys.length; index < length; index += 1) {
|
3008 | tag = keys[index];
|
3009 | style = String(map[tag]);
|
3010 |
|
3011 | if (tag.slice(0, 2) === '!!') {
|
3012 | tag = 'tag:yaml.org,2002:' + tag.slice(2);
|
3013 | }
|
3014 | type = schema.compiledTypeMap['fallback'][tag];
|
3015 |
|
3016 | if (type && _hasOwnProperty$3.call(type.styleAliases, style)) {
|
3017 | style = type.styleAliases[style];
|
3018 | }
|
3019 |
|
3020 | result[tag] = style;
|
3021 | }
|
3022 |
|
3023 | return result;
|
3024 | }
|
3025 |
|
3026 | function encodeHex(character) {
|
3027 | var string, handle, length;
|
3028 |
|
3029 | string = character.toString(16).toUpperCase();
|
3030 |
|
3031 | if (character <= 0xFF) {
|
3032 | handle = 'x';
|
3033 | length = 2;
|
3034 | } else if (character <= 0xFFFF) {
|
3035 | handle = 'u';
|
3036 | length = 4;
|
3037 | } else if (character <= 0xFFFFFFFF) {
|
3038 | handle = 'U';
|
3039 | length = 8;
|
3040 | } else {
|
3041 | throw new YAMLException$5('code point within a string may not be greater than 0xFFFFFFFF');
|
3042 | }
|
3043 |
|
3044 | return '\\' + handle + common$7.repeat('0', length - string.length) + string;
|
3045 | }
|
3046 |
|
3047 | function State$1(options) {
|
3048 | this.schema = options['schema'] || DEFAULT_FULL_SCHEMA$2;
|
3049 | this.indent = Math.max(1, (options['indent'] || 2));
|
3050 | this.skipInvalid = options['skipInvalid'] || false;
|
3051 | this.flowLevel = (common$7.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
|
3052 | this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
|
3053 | this.sortKeys = options['sortKeys'] || false;
|
3054 | this.lineWidth = options['lineWidth'] || 80;
|
3055 | this.noRefs = options['noRefs'] || false;
|
3056 | this.noCompatMode = options['noCompatMode'] || false;
|
3057 |
|
3058 | this.implicitTypes = this.schema.compiledImplicit;
|
3059 | this.explicitTypes = this.schema.compiledExplicit;
|
3060 |
|
3061 | this.tag = null;
|
3062 | this.result = '';
|
3063 |
|
3064 | this.duplicates = [];
|
3065 | this.usedDuplicates = null;
|
3066 | }
|
3067 |
|
3068 |
|
3069 | function indentString(string, spaces) {
|
3070 | var ind = common$7.repeat(' ', spaces),
|
3071 | position = 0,
|
3072 | next = -1,
|
3073 | result = '',
|
3074 | line,
|
3075 | length = string.length;
|
3076 |
|
3077 | while (position < length) {
|
3078 | next = string.indexOf('\n', position);
|
3079 | if (next === -1) {
|
3080 | line = string.slice(position);
|
3081 | position = length;
|
3082 | } else {
|
3083 | line = string.slice(position, next + 1);
|
3084 | position = next + 1;
|
3085 | }
|
3086 |
|
3087 | if (line.length && line !== '\n') { result += ind; }
|
3088 |
|
3089 | result += line;
|
3090 | }
|
3091 |
|
3092 | return result;
|
3093 | }
|
3094 |
|
3095 | function generateNextLine(state, level) {
|
3096 | return '\n' + common$7.repeat(' ', state.indent * level);
|
3097 | }
|
3098 |
|
3099 | function testImplicitResolving(state, str) {
|
3100 | var index, length, type;
|
3101 |
|
3102 | for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
|
3103 | type = state.implicitTypes[index];
|
3104 |
|
3105 | if (type.resolve(str)) {
|
3106 | return true;
|
3107 | }
|
3108 | }
|
3109 |
|
3110 | return false;
|
3111 | }
|
3112 |
|
3113 |
|
3114 | function isWhitespace(c) {
|
3115 | return c === CHAR_SPACE || c === CHAR_TAB;
|
3116 | }
|
3117 |
|
3118 |
|
3119 |
|
3120 |
|
3121 |
|
3122 | function isPrintable(c) {
|
3123 | return (0x00020 <= c && c <= 0x00007E)
|
3124 | || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
|
3125 | || ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF )
|
3126 | || (0x10000 <= c && c <= 0x10FFFF);
|
3127 | }
|
3128 |
|
3129 |
|
3130 | function isPlainSafe(c) {
|
3131 |
|
3132 |
|
3133 | return isPrintable(c) && c !== 0xFEFF
|
3134 |
|
3135 | && c !== CHAR_COMMA
|
3136 | && c !== CHAR_LEFT_SQUARE_BRACKET
|
3137 | && c !== CHAR_RIGHT_SQUARE_BRACKET
|
3138 | && c !== CHAR_LEFT_CURLY_BRACKET
|
3139 | && c !== CHAR_RIGHT_CURLY_BRACKET
|
3140 |
|
3141 | && c !== CHAR_COLON
|
3142 | && c !== CHAR_SHARP;
|
3143 | }
|
3144 |
|
3145 |
|
3146 | function isPlainSafeFirst(c) {
|
3147 |
|
3148 |
|
3149 | return isPrintable(c) && c !== 0xFEFF
|
3150 | && !isWhitespace(c)
|
3151 |
|
3152 |
|
3153 | && c !== CHAR_MINUS
|
3154 | && c !== CHAR_QUESTION
|
3155 | && c !== CHAR_COLON
|
3156 | && c !== CHAR_COMMA
|
3157 | && c !== CHAR_LEFT_SQUARE_BRACKET
|
3158 | && c !== CHAR_RIGHT_SQUARE_BRACKET
|
3159 | && c !== CHAR_LEFT_CURLY_BRACKET
|
3160 | && c !== CHAR_RIGHT_CURLY_BRACKET
|
3161 |
|
3162 | && c !== CHAR_SHARP
|
3163 | && c !== CHAR_AMPERSAND
|
3164 | && c !== CHAR_ASTERISK
|
3165 | && c !== CHAR_EXCLAMATION
|
3166 | && c !== CHAR_VERTICAL_LINE
|
3167 | && c !== CHAR_GREATER_THAN
|
3168 | && c !== CHAR_SINGLE_QUOTE
|
3169 | && c !== CHAR_DOUBLE_QUOTE
|
3170 |
|
3171 | && c !== CHAR_PERCENT
|
3172 | && c !== CHAR_COMMERCIAL_AT
|
3173 | && c !== CHAR_GRAVE_ACCENT;
|
3174 | }
|
3175 |
|
3176 | var STYLE_PLAIN = 1;
|
3177 | var STYLE_SINGLE = 2;
|
3178 | var STYLE_LITERAL = 3;
|
3179 | var STYLE_FOLDED = 4;
|
3180 | var STYLE_DOUBLE = 5;
|
3181 |
|
3182 |
|
3183 |
|
3184 |
|
3185 |
|
3186 |
|
3187 |
|
3188 |
|
3189 | function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
|
3190 | var i;
|
3191 | var char;
|
3192 | var hasLineBreak = false;
|
3193 | var hasFoldableLine = false;
|
3194 | var shouldTrackWidth = lineWidth !== -1;
|
3195 | var previousLineBreak = -1;
|
3196 | var plain = isPlainSafeFirst(string.charCodeAt(0))
|
3197 | && !isWhitespace(string.charCodeAt(string.length - 1));
|
3198 |
|
3199 | if (singleLineOnly) {
|
3200 |
|
3201 |
|
3202 | for (i = 0; i < string.length; i++) {
|
3203 | char = string.charCodeAt(i);
|
3204 | if (!isPrintable(char)) {
|
3205 | return STYLE_DOUBLE;
|
3206 | }
|
3207 | plain = plain && isPlainSafe(char);
|
3208 | }
|
3209 | } else {
|
3210 |
|
3211 | for (i = 0; i < string.length; i++) {
|
3212 | char = string.charCodeAt(i);
|
3213 | if (char === CHAR_LINE_FEED) {
|
3214 | hasLineBreak = true;
|
3215 |
|
3216 | if (shouldTrackWidth) {
|
3217 | hasFoldableLine = hasFoldableLine ||
|
3218 |
|
3219 | (i - previousLineBreak - 1 > lineWidth &&
|
3220 | string[previousLineBreak + 1] !== ' ');
|
3221 | previousLineBreak = i;
|
3222 | }
|
3223 | } else if (!isPrintable(char)) {
|
3224 | return STYLE_DOUBLE;
|
3225 | }
|
3226 | plain = plain && isPlainSafe(char);
|
3227 | }
|
3228 |
|
3229 | hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
|
3230 | (i - previousLineBreak - 1 > lineWidth &&
|
3231 | string[previousLineBreak + 1] !== ' '));
|
3232 | }
|
3233 |
|
3234 |
|
3235 |
|
3236 | if (!hasLineBreak && !hasFoldableLine) {
|
3237 |
|
3238 |
|
3239 | return plain && !testAmbiguousType(string)
|
3240 | ? STYLE_PLAIN : STYLE_SINGLE;
|
3241 | }
|
3242 |
|
3243 | if (string[0] === ' ' && indentPerLevel > 9) {
|
3244 | return STYLE_DOUBLE;
|
3245 | }
|
3246 |
|
3247 |
|
3248 | return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
3249 | }
|
3250 |
|
3251 |
|
3252 |
|
3253 |
|
3254 |
|
3255 |
|
3256 |
|
3257 | function writeScalar(state, string, level, iskey) {
|
3258 | state.dump = (function () {
|
3259 | if (string.length === 0) {
|
3260 | return "''";
|
3261 | }
|
3262 | if (!state.noCompatMode &&
|
3263 | DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
|
3264 | return "'" + string + "'";
|
3265 | }
|
3266 |
|
3267 | var indent = state.indent * Math.max(1, level);
|
3268 |
|
3269 |
|
3270 |
|
3271 |
|
3272 |
|
3273 |
|
3274 |
|
3275 | var lineWidth = state.lineWidth === -1
|
3276 | ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
3277 |
|
3278 |
|
3279 | var singleLineOnly = iskey
|
3280 |
|
3281 | || (state.flowLevel > -1 && level >= state.flowLevel);
|
3282 | function testAmbiguity(string) {
|
3283 | return testImplicitResolving(state, string);
|
3284 | }
|
3285 |
|
3286 | switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
|
3287 | case STYLE_PLAIN:
|
3288 | return string;
|
3289 | case STYLE_SINGLE:
|
3290 | return "'" + string.replace(/'/g, "''") + "'";
|
3291 | case STYLE_LITERAL:
|
3292 | return '|' + blockHeader(string, state.indent)
|
3293 | + dropEndingNewline(indentString(string, indent));
|
3294 | case STYLE_FOLDED:
|
3295 | return '>' + blockHeader(string, state.indent)
|
3296 | + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
3297 | case STYLE_DOUBLE:
|
3298 | return '"' + escapeString(string, lineWidth) + '"';
|
3299 | default:
|
3300 | throw new YAMLException$5('impossible error: invalid scalar style');
|
3301 | }
|
3302 | }());
|
3303 | }
|
3304 |
|
3305 |
|
3306 | function blockHeader(string, indentPerLevel) {
|
3307 | var indentIndicator = (string[0] === ' ') ? String(indentPerLevel) : '';
|
3308 |
|
3309 |
|
3310 | var clip = string[string.length - 1] === '\n';
|
3311 | var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
|
3312 | var chomp = keep ? '+' : (clip ? '' : '-');
|
3313 |
|
3314 | return indentIndicator + chomp + '\n';
|
3315 | }
|
3316 |
|
3317 |
|
3318 | function dropEndingNewline(string) {
|
3319 | return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
|
3320 | }
|
3321 |
|
3322 |
|
3323 |
|
3324 | function foldString(string, width) {
|
3325 |
|
3326 |
|
3327 |
|
3328 |
|
3329 | var lineRe = /(\n+)([^\n]*)/g;
|
3330 |
|
3331 |
|
3332 | var result = (function () {
|
3333 | var nextLF = string.indexOf('\n');
|
3334 | nextLF = nextLF !== -1 ? nextLF : string.length;
|
3335 | lineRe.lastIndex = nextLF;
|
3336 | return foldLine(string.slice(0, nextLF), width);
|
3337 | }());
|
3338 |
|
3339 | var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
|
3340 | var moreIndented;
|
3341 |
|
3342 |
|
3343 | var match;
|
3344 | while ((match = lineRe.exec(string))) {
|
3345 | var prefix = match[1], line = match[2];
|
3346 | moreIndented = (line[0] === ' ');
|
3347 | result += prefix
|
3348 | + (!prevMoreIndented && !moreIndented && line !== ''
|
3349 | ? '\n' : '')
|
3350 | + foldLine(line, width);
|
3351 | prevMoreIndented = moreIndented;
|
3352 | }
|
3353 |
|
3354 | return result;
|
3355 | }
|
3356 |
|
3357 |
|
3358 |
|
3359 |
|
3360 |
|
3361 | function foldLine(line, width) {
|
3362 | if (line === '' || line[0] === ' ') { return line; }
|
3363 |
|
3364 |
|
3365 | var breakRe = / [^ ]/g;
|
3366 | var match;
|
3367 |
|
3368 | var start = 0, end, curr = 0, next = 0;
|
3369 | var result = '';
|
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 |
|
3375 | while ((match = breakRe.exec(line))) {
|
3376 | next = match.index;
|
3377 |
|
3378 | if (next - start > width) {
|
3379 | end = (curr > start) ? curr : next;
|
3380 | result += '\n' + line.slice(start, end);
|
3381 |
|
3382 | start = end + 1;
|
3383 | }
|
3384 | curr = next;
|
3385 | }
|
3386 |
|
3387 |
|
3388 |
|
3389 | result += '\n';
|
3390 |
|
3391 | if (line.length - start > width && curr > start) {
|
3392 | result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
|
3393 | } else {
|
3394 | result += line.slice(start);
|
3395 | }
|
3396 |
|
3397 | return result.slice(1);
|
3398 | }
|
3399 |
|
3400 |
|
3401 | function escapeString(string) {
|
3402 | var result = '';
|
3403 | var char;
|
3404 | var escapeSeq;
|
3405 |
|
3406 | for (var i = 0; i < string.length; i++) {
|
3407 | char = string.charCodeAt(i);
|
3408 | escapeSeq = ESCAPE_SEQUENCES[char];
|
3409 | result += !escapeSeq && isPrintable(char)
|
3410 | ? string[i]
|
3411 | : escapeSeq || encodeHex(char);
|
3412 | }
|
3413 |
|
3414 | return result;
|
3415 | }
|
3416 |
|
3417 | function writeFlowSequence(state, level, object) {
|
3418 | var _result = '',
|
3419 | _tag = state.tag,
|
3420 | index,
|
3421 | length;
|
3422 |
|
3423 | for (index = 0, length = object.length; index < length; index += 1) {
|
3424 |
|
3425 | if (writeNode(state, level, object[index], false, false)) {
|
3426 | if (index !== 0) { _result += ', '; }
|
3427 | _result += state.dump;
|
3428 | }
|
3429 | }
|
3430 |
|
3431 | state.tag = _tag;
|
3432 | state.dump = '[' + _result + ']';
|
3433 | }
|
3434 |
|
3435 | function writeBlockSequence(state, level, object, compact) {
|
3436 | var _result = '',
|
3437 | _tag = state.tag,
|
3438 | index,
|
3439 | length;
|
3440 |
|
3441 | for (index = 0, length = object.length; index < length; index += 1) {
|
3442 |
|
3443 | if (writeNode(state, level + 1, object[index], true, true)) {
|
3444 | if (!compact || index !== 0) {
|
3445 | _result += generateNextLine(state, level);
|
3446 | }
|
3447 | _result += '- ' + state.dump;
|
3448 | }
|
3449 | }
|
3450 |
|
3451 | state.tag = _tag;
|
3452 | state.dump = _result || '[]';
|
3453 | }
|
3454 |
|
3455 | function writeFlowMapping(state, level, object) {
|
3456 | var _result = '',
|
3457 | _tag = state.tag,
|
3458 | objectKeyList = Object.keys(object),
|
3459 | index,
|
3460 | length,
|
3461 | objectKey,
|
3462 | objectValue,
|
3463 | pairBuffer;
|
3464 |
|
3465 | for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
3466 | pairBuffer = '';
|
3467 |
|
3468 | if (index !== 0) { pairBuffer += ', '; }
|
3469 |
|
3470 | objectKey = objectKeyList[index];
|
3471 | objectValue = object[objectKey];
|
3472 |
|
3473 | if (!writeNode(state, level, objectKey, false, false)) {
|
3474 | continue;
|
3475 | }
|
3476 |
|
3477 | if (state.dump.length > 1024) { pairBuffer += '? '; }
|
3478 |
|
3479 | pairBuffer += state.dump + ': ';
|
3480 |
|
3481 | if (!writeNode(state, level, objectValue, false, false)) {
|
3482 | continue;
|
3483 | }
|
3484 |
|
3485 | pairBuffer += state.dump;
|
3486 |
|
3487 |
|
3488 | _result += pairBuffer;
|
3489 | }
|
3490 |
|
3491 | state.tag = _tag;
|
3492 | state.dump = '{' + _result + '}';
|
3493 | }
|
3494 |
|
3495 | function writeBlockMapping(state, level, object, compact) {
|
3496 | var _result = '',
|
3497 | _tag = state.tag,
|
3498 | objectKeyList = Object.keys(object),
|
3499 | index,
|
3500 | length,
|
3501 | objectKey,
|
3502 | objectValue,
|
3503 | explicitPair,
|
3504 | pairBuffer;
|
3505 |
|
3506 |
|
3507 | if (state.sortKeys === true) {
|
3508 |
|
3509 | objectKeyList.sort();
|
3510 | } else if (typeof state.sortKeys === 'function') {
|
3511 |
|
3512 | objectKeyList.sort(state.sortKeys);
|
3513 | } else if (state.sortKeys) {
|
3514 |
|
3515 | throw new YAMLException$5('sortKeys must be a boolean or a function');
|
3516 | }
|
3517 |
|
3518 | for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
3519 | pairBuffer = '';
|
3520 |
|
3521 | if (!compact || index !== 0) {
|
3522 | pairBuffer += generateNextLine(state, level);
|
3523 | }
|
3524 |
|
3525 | objectKey = objectKeyList[index];
|
3526 | objectValue = object[objectKey];
|
3527 |
|
3528 | if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
3529 | continue;
|
3530 | }
|
3531 |
|
3532 | explicitPair = (state.tag !== null && state.tag !== '?') ||
|
3533 | (state.dump && state.dump.length > 1024);
|
3534 |
|
3535 | if (explicitPair) {
|
3536 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
3537 | pairBuffer += '?';
|
3538 | } else {
|
3539 | pairBuffer += '? ';
|
3540 | }
|
3541 | }
|
3542 |
|
3543 | pairBuffer += state.dump;
|
3544 |
|
3545 | if (explicitPair) {
|
3546 | pairBuffer += generateNextLine(state, level);
|
3547 | }
|
3548 |
|
3549 | if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
3550 | continue;
|
3551 | }
|
3552 |
|
3553 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
3554 | pairBuffer += ':';
|
3555 | } else {
|
3556 | pairBuffer += ': ';
|
3557 | }
|
3558 |
|
3559 | pairBuffer += state.dump;
|
3560 |
|
3561 |
|
3562 | _result += pairBuffer;
|
3563 | }
|
3564 |
|
3565 | state.tag = _tag;
|
3566 | state.dump = _result || '{}';
|
3567 | }
|
3568 |
|
3569 | function detectType(state, object, explicit) {
|
3570 | var _result, typeList, index, length, type, style;
|
3571 |
|
3572 | typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
3573 |
|
3574 | for (index = 0, length = typeList.length; index < length; index += 1) {
|
3575 | type = typeList[index];
|
3576 |
|
3577 | if ((type.instanceOf || type.predicate) &&
|
3578 | (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
|
3579 | (!type.predicate || type.predicate(object))) {
|
3580 |
|
3581 | state.tag = explicit ? type.tag : '?';
|
3582 |
|
3583 | if (type.represent) {
|
3584 | style = state.styleMap[type.tag] || type.defaultStyle;
|
3585 |
|
3586 | if (_toString$2.call(type.represent) === '[object Function]') {
|
3587 | _result = type.represent(object, style);
|
3588 | } else if (_hasOwnProperty$3.call(type.represent, style)) {
|
3589 | _result = type.represent[style](object, style);
|
3590 | } else {
|
3591 | throw new YAMLException$5('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
|
3592 | }
|
3593 |
|
3594 | state.dump = _result;
|
3595 | }
|
3596 |
|
3597 | return true;
|
3598 | }
|
3599 | }
|
3600 |
|
3601 | return false;
|
3602 | }
|
3603 |
|
3604 |
|
3605 |
|
3606 |
|
3607 | function writeNode(state, level, object, block, compact, iskey) {
|
3608 | state.tag = null;
|
3609 | state.dump = object;
|
3610 |
|
3611 | if (!detectType(state, object, false)) {
|
3612 | detectType(state, object, true);
|
3613 | }
|
3614 |
|
3615 | var type = _toString$2.call(state.dump);
|
3616 |
|
3617 | if (block) {
|
3618 | block = (state.flowLevel < 0 || state.flowLevel > level);
|
3619 | }
|
3620 |
|
3621 | var objectOrArray = type === '[object Object]' || type === '[object Array]',
|
3622 | duplicateIndex,
|
3623 | duplicate;
|
3624 |
|
3625 | if (objectOrArray) {
|
3626 | duplicateIndex = state.duplicates.indexOf(object);
|
3627 | duplicate = duplicateIndex !== -1;
|
3628 | }
|
3629 |
|
3630 | if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
|
3631 | compact = false;
|
3632 | }
|
3633 |
|
3634 | if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
3635 | state.dump = '*ref_' + duplicateIndex;
|
3636 | } else {
|
3637 | if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
3638 | state.usedDuplicates[duplicateIndex] = true;
|
3639 | }
|
3640 | if (type === '[object Object]') {
|
3641 | if (block && (Object.keys(state.dump).length !== 0)) {
|
3642 | writeBlockMapping(state, level, state.dump, compact);
|
3643 | if (duplicate) {
|
3644 | state.dump = '&ref_' + duplicateIndex + state.dump;
|
3645 | }
|
3646 | } else {
|
3647 | writeFlowMapping(state, level, state.dump);
|
3648 | if (duplicate) {
|
3649 | state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
|
3650 | }
|
3651 | }
|
3652 | } else if (type === '[object Array]') {
|
3653 | if (block && (state.dump.length !== 0)) {
|
3654 | writeBlockSequence(state, level, state.dump, compact);
|
3655 | if (duplicate) {
|
3656 | state.dump = '&ref_' + duplicateIndex + state.dump;
|
3657 | }
|
3658 | } else {
|
3659 | writeFlowSequence(state, level, state.dump);
|
3660 | if (duplicate) {
|
3661 | state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
|
3662 | }
|
3663 | }
|
3664 | } else if (type === '[object String]') {
|
3665 | if (state.tag !== '?') {
|
3666 | writeScalar(state, state.dump, level, iskey);
|
3667 | }
|
3668 | } else {
|
3669 | if (state.skipInvalid) { return false; }
|
3670 | throw new YAMLException$5('unacceptable kind of an object to dump ' + type);
|
3671 | }
|
3672 |
|
3673 | if (state.tag !== null && state.tag !== '?') {
|
3674 | state.dump = '!<' + state.tag + '> ' + state.dump;
|
3675 | }
|
3676 | }
|
3677 |
|
3678 | return true;
|
3679 | }
|
3680 |
|
3681 | function getDuplicateReferences(object, state) {
|
3682 | var objects = [],
|
3683 | duplicatesIndexes = [],
|
3684 | index,
|
3685 | length;
|
3686 |
|
3687 | inspectNode(object, objects, duplicatesIndexes);
|
3688 |
|
3689 | for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
|
3690 | state.duplicates.push(objects[duplicatesIndexes[index]]);
|
3691 | }
|
3692 | state.usedDuplicates = new Array(length);
|
3693 | }
|
3694 |
|
3695 | function inspectNode(object, objects, duplicatesIndexes) {
|
3696 | var objectKeyList,
|
3697 | index,
|
3698 | length;
|
3699 |
|
3700 | if (object !== null && typeof object === 'object') {
|
3701 | index = objects.indexOf(object);
|
3702 | if (index !== -1) {
|
3703 | if (duplicatesIndexes.indexOf(index) === -1) {
|
3704 | duplicatesIndexes.push(index);
|
3705 | }
|
3706 | } else {
|
3707 | objects.push(object);
|
3708 |
|
3709 | if (Array.isArray(object)) {
|
3710 | for (index = 0, length = object.length; index < length; index += 1) {
|
3711 | inspectNode(object[index], objects, duplicatesIndexes);
|
3712 | }
|
3713 | } else {
|
3714 | objectKeyList = Object.keys(object);
|
3715 |
|
3716 | for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
3717 | inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
3718 | }
|
3719 | }
|
3720 | }
|
3721 | }
|
3722 | }
|
3723 |
|
3724 | function dump$1(input, options) {
|
3725 | options = options || {};
|
3726 |
|
3727 | var state = new State$1(options);
|
3728 |
|
3729 | if (!state.noRefs) { getDuplicateReferences(input, state); }
|
3730 |
|
3731 | if (writeNode(state, 0, input, true, true)) { return state.dump + '\n'; }
|
3732 |
|
3733 | return '';
|
3734 | }
|
3735 |
|
3736 | function safeDump$1(input, options) {
|
3737 | return dump$1(input, common$7.extend({ schema: DEFAULT_SAFE_SCHEMA$2 }, options));
|
3738 | }
|
3739 |
|
3740 | var dump_1 = dump$1;
|
3741 | var safeDump_1 = safeDump$1;
|
3742 |
|
3743 | var dumper$1 = {
|
3744 | dump: dump_1,
|
3745 | safeDump: safeDump_1
|
3746 | };
|
3747 |
|
3748 | var loader = loader$1;
|
3749 | var dumper = dumper$1;
|
3750 |
|
3751 |
|
3752 | function deprecated(name) {
|
3753 | return function () {
|
3754 | throw new Error('Function ' + name + ' is deprecated and cannot be used.');
|
3755 | };
|
3756 | }
|
3757 |
|
3758 |
|
3759 | var Type = type;
|
3760 | var Schema = schema;
|
3761 | var FAILSAFE_SCHEMA = failsafe;
|
3762 | var JSON_SCHEMA = json;
|
3763 | var CORE_SCHEMA = core;
|
3764 | var DEFAULT_SAFE_SCHEMA = default_safe;
|
3765 | var DEFAULT_FULL_SCHEMA = default_full;
|
3766 | var load = loader.load;
|
3767 | var loadAll = loader.loadAll;
|
3768 | var safeLoad = loader.safeLoad;
|
3769 | var safeLoadAll = loader.safeLoadAll;
|
3770 | var dump = dumper.dump;
|
3771 | var safeDump = dumper.safeDump;
|
3772 | var YAMLException = exception;
|
3773 |
|
3774 |
|
3775 | var MINIMAL_SCHEMA = failsafe;
|
3776 | var SAFE_SCHEMA = default_safe;
|
3777 | var DEFAULT_SCHEMA = default_full;
|
3778 |
|
3779 |
|
3780 | var scan = deprecated('scan');
|
3781 | var parse = deprecated('parse');
|
3782 | var compose = deprecated('compose');
|
3783 | var addConstructor = deprecated('addConstructor');
|
3784 |
|
3785 | var jsYaml = {
|
3786 | Type: Type,
|
3787 | Schema: Schema,
|
3788 | FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
|
3789 | JSON_SCHEMA: JSON_SCHEMA,
|
3790 | CORE_SCHEMA: CORE_SCHEMA,
|
3791 | DEFAULT_SAFE_SCHEMA: DEFAULT_SAFE_SCHEMA,
|
3792 | DEFAULT_FULL_SCHEMA: DEFAULT_FULL_SCHEMA,
|
3793 | load: load,
|
3794 | loadAll: loadAll,
|
3795 | safeLoad: safeLoad,
|
3796 | safeLoadAll: safeLoadAll,
|
3797 | dump: dump,
|
3798 | safeDump: safeDump,
|
3799 | YAMLException: YAMLException,
|
3800 | MINIMAL_SCHEMA: MINIMAL_SCHEMA,
|
3801 | SAFE_SCHEMA: SAFE_SCHEMA,
|
3802 | DEFAULT_SCHEMA: DEFAULT_SCHEMA,
|
3803 | scan: scan,
|
3804 | parse: parse,
|
3805 | compose: compose,
|
3806 | addConstructor: addConstructor
|
3807 | };
|
3808 |
|
3809 | var yaml = jsYaml;
|
3810 |
|
3811 |
|
3812 | var index = yaml;
|
3813 |
|
3814 | var frontMatter = function(dom, data) {
|
3815 | var el = dom.querySelector('script[type="text/front-matter"]');
|
3816 |
|
3817 |
|
3818 | if (el) {
|
3819 | var text = el.textContent;
|
3820 | var localData = index.safeLoad(text);
|
3821 |
|
3822 | data.title = localData.title;
|
3823 | data.description = localData.description;
|
3824 | data.published = new Date(localData.published);
|
3825 | data.updated = new Date(localData.published || localData.updated);
|
3826 |
|
3827 | data.authors = localData.authors.map(function (author, i) {
|
3828 | var a = {};
|
3829 | var name = Object.keys(author)[0];
|
3830 | var names = name.split(" ");
|
3831 | a.firstName = names.slice(0, names.length - 1).join(" ");
|
3832 | a.lastName = names[names.length -1];
|
3833 | a.personalURL = author[name];
|
3834 | if(localData.affiliations[i]) {
|
3835 | var affiliation = Object.keys(localData.affiliations[i])[0];
|
3836 | a.affiliation = affiliation;
|
3837 | a.affiliationURL = localData.affiliations[i][affiliation];
|
3838 | }
|
3839 | return a;
|
3840 | });
|
3841 |
|
3842 | }
|
3843 |
|
3844 | };
|
3845 |
|
3846 | var bibtexParse = createCommonjsModule(function (module, exports) {
|
3847 |
|
3848 |
|
3849 |
|
3850 |
|
3851 |
|
3852 |
|
3853 |
|
3854 |
|
3855 |
|
3856 |
|
3857 |
|
3858 |
|
3859 |
|
3860 |
|
3861 |
|
3862 |
|
3863 |
|
3864 |
|
3865 |
|
3866 |
|
3867 |
|
3868 |
|
3869 |
|
3870 | (function(exports) {
|
3871 |
|
3872 | function BibtexParser() {
|
3873 |
|
3874 | this.months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
3875 | this.notKey = [',','{','}',' ','='];
|
3876 | this.pos = 0;
|
3877 | this.input = "";
|
3878 | this.entries = new Array();
|
3879 |
|
3880 | this.currentEntry = "";
|
3881 |
|
3882 | this.setInput = function(t) {
|
3883 | this.input = t;
|
3884 | };
|
3885 |
|
3886 | this.getEntries = function() {
|
3887 | return this.entries;
|
3888 | };
|
3889 |
|
3890 | this.isWhitespace = function(s) {
|
3891 | return (s == ' ' || s == '\r' || s == '\t' || s == '\n');
|
3892 | };
|
3893 |
|
3894 | this.match = function(s, canCommentOut) {
|
3895 | if (canCommentOut == undefined || canCommentOut == null)
|
3896 | { canCommentOut = true; }
|
3897 | this.skipWhitespace(canCommentOut);
|
3898 | if (this.input.substring(this.pos, this.pos + s.length) == s) {
|
3899 | this.pos += s.length;
|
3900 | } else {
|
3901 | throw "Token mismatch, expected " + s + ", found "
|
3902 | + this.input.substring(this.pos);
|
3903 | }
|
3904 | this.skipWhitespace(canCommentOut);
|
3905 | };
|
3906 |
|
3907 | this.tryMatch = function(s, canCommentOut) {
|
3908 | if (canCommentOut == undefined || canCommentOut == null)
|
3909 | { canCommentOut = true; }
|
3910 | this.skipWhitespace(canCommentOut);
|
3911 | if (this.input.substring(this.pos, this.pos + s.length) == s) {
|
3912 | return true;
|
3913 | } else {
|
3914 | return false;
|
3915 | }
|
3916 | this.skipWhitespace(canCommentOut);
|
3917 | };
|
3918 |
|
3919 |
|
3920 | this.matchAt = function() {
|
3921 | var this$1 = this;
|
3922 |
|
3923 | while (this.input.length > this.pos && this.input[this.pos] != '@') {
|
3924 | this$1.pos++;
|
3925 | }
|
3926 |
|
3927 | if (this.input[this.pos] == '@') {
|
3928 | return true;
|
3929 | }
|
3930 | return false;
|
3931 | };
|
3932 |
|
3933 | this.skipWhitespace = function(canCommentOut) {
|
3934 | var this$1 = this;
|
3935 |
|
3936 | while (this.isWhitespace(this.input[this.pos])) {
|
3937 | this$1.pos++;
|
3938 | }
|
3939 | if (this.input[this.pos] == "%" && canCommentOut == true) {
|
3940 | while (this.input[this.pos] != "\n") {
|
3941 | this$1.pos++;
|
3942 | }
|
3943 | this.skipWhitespace(canCommentOut);
|
3944 | }
|
3945 | };
|
3946 |
|
3947 | this.value_braces = function() {
|
3948 | var this$1 = this;
|
3949 |
|
3950 | var bracecount = 0;
|
3951 | this.match("{", false);
|
3952 | var start = this.pos;
|
3953 | var escaped = false;
|
3954 | while (true) {
|
3955 | if (!escaped) {
|
3956 | if (this$1.input[this$1.pos] == '}') {
|
3957 | if (bracecount > 0) {
|
3958 | bracecount--;
|
3959 | } else {
|
3960 | var end = this$1.pos;
|
3961 | this$1.match("}", false);
|
3962 | return this$1.input.substring(start, end);
|
3963 | }
|
3964 | } else if (this$1.input[this$1.pos] == '{') {
|
3965 | bracecount++;
|
3966 | } else if (this$1.pos >= this$1.input.length - 1) {
|
3967 | throw "Unterminated value";
|
3968 | }
|
3969 | }
|
3970 | if (this$1.input[this$1.pos] == '\\' && escaped == false)
|
3971 | { escaped = true; }
|
3972 | else
|
3973 | { escaped = false; }
|
3974 | this$1.pos++;
|
3975 | }
|
3976 | };
|
3977 |
|
3978 | this.value_comment = function() {
|
3979 | var this$1 = this;
|
3980 |
|
3981 | var str = '';
|
3982 | var brcktCnt = 0;
|
3983 | while (!(this.tryMatch("}", false) && brcktCnt == 0)) {
|
3984 | str = str + this$1.input[this$1.pos];
|
3985 | if (this$1.input[this$1.pos] == '{')
|
3986 | { brcktCnt++; }
|
3987 | if (this$1.input[this$1.pos] == '}')
|
3988 | { brcktCnt--; }
|
3989 | if (this$1.pos >= this$1.input.length - 1) {
|
3990 | throw "Unterminated value:" + this$1.input.substring(start);
|
3991 | }
|
3992 | this$1.pos++;
|
3993 | }
|
3994 | return str;
|
3995 | };
|
3996 |
|
3997 | this.value_quotes = function() {
|
3998 | var this$1 = this;
|
3999 |
|
4000 | this.match('"', false);
|
4001 | var start = this.pos;
|
4002 | var escaped = false;
|
4003 | while (true) {
|
4004 | if (!escaped) {
|
4005 | if (this$1.input[this$1.pos] == '"') {
|
4006 | var end = this$1.pos;
|
4007 | this$1.match('"', false);
|
4008 | return this$1.input.substring(start, end);
|
4009 | } else if (this$1.pos >= this$1.input.length - 1) {
|
4010 | throw "Unterminated value:" + this$1.input.substring(start);
|
4011 | }
|
4012 | }
|
4013 | if (this$1.input[this$1.pos] == '\\' && escaped == false)
|
4014 | { escaped = true; }
|
4015 | else
|
4016 | { escaped = false; }
|
4017 | this$1.pos++;
|
4018 | }
|
4019 | };
|
4020 |
|
4021 | this.single_value = function() {
|
4022 | var start = this.pos;
|
4023 | if (this.tryMatch("{")) {
|
4024 | return this.value_braces();
|
4025 | } else if (this.tryMatch('"')) {
|
4026 | return this.value_quotes();
|
4027 | } else {
|
4028 | var k = this.key();
|
4029 | if (k.match("^[0-9]+$"))
|
4030 | { return k; }
|
4031 | else if (this.months.indexOf(k.toLowerCase()) >= 0)
|
4032 | { return k.toLowerCase(); }
|
4033 | else
|
4034 | { throw "Value expected:" + this.input.substring(start) + ' for key: ' + k; }
|
4035 |
|
4036 | }
|
4037 | };
|
4038 |
|
4039 | this.value = function() {
|
4040 | var this$1 = this;
|
4041 |
|
4042 | var values = [];
|
4043 | values.push(this.single_value());
|
4044 | while (this.tryMatch("#")) {
|
4045 | this$1.match("#");
|
4046 | values.push(this$1.single_value());
|
4047 | }
|
4048 | return values.join("");
|
4049 | };
|
4050 |
|
4051 | this.key = function() {
|
4052 | var this$1 = this;
|
4053 |
|
4054 | var start = this.pos;
|
4055 | while (true) {
|
4056 | if (this$1.pos >= this$1.input.length) {
|
4057 | throw "Runaway key";
|
4058 | }
|
4059 |
|
4060 |
|
4061 | if (this$1.notKey.indexOf(this$1.input[this$1.pos]) >= 0) {
|
4062 | return this$1.input.substring(start, this$1.pos);
|
4063 | } else {
|
4064 | this$1.pos++;
|
4065 |
|
4066 | }
|
4067 | }
|
4068 | };
|
4069 |
|
4070 | this.key_equals_value = function() {
|
4071 | var key = this.key();
|
4072 | if (this.tryMatch("=")) {
|
4073 | this.match("=");
|
4074 | var val = this.value();
|
4075 | return [ key, val ];
|
4076 | } else {
|
4077 | throw "... = value expected, equals sign missing:"
|
4078 | + this.input.substring(this.pos);
|
4079 | }
|
4080 | };
|
4081 |
|
4082 | this.key_value_list = function() {
|
4083 | var this$1 = this;
|
4084 |
|
4085 | var kv = this.key_equals_value();
|
4086 | this.currentEntry['entryTags'] = {};
|
4087 | this.currentEntry['entryTags'][kv[0]] = kv[1];
|
4088 | while (this.tryMatch(",")) {
|
4089 | this$1.match(",");
|
4090 |
|
4091 | if (this$1.tryMatch("}")) {
|
4092 | break;
|
4093 | }
|
4094 |
|
4095 | kv = this$1.key_equals_value();
|
4096 | this$1.currentEntry['entryTags'][kv[0]] = kv[1];
|
4097 | }
|
4098 | };
|
4099 |
|
4100 | this.entry_body = function(d) {
|
4101 | this.currentEntry = {};
|
4102 | this.currentEntry['citationKey'] = this.key();
|
4103 | this.currentEntry['entryType'] = d.substring(1);
|
4104 | this.match(",");
|
4105 | this.key_value_list();
|
4106 | this.entries.push(this.currentEntry);
|
4107 | };
|
4108 |
|
4109 | this.directive = function() {
|
4110 | this.match("@");
|
4111 | return "@" + this.key();
|
4112 | };
|
4113 |
|
4114 | this.preamble = function() {
|
4115 | this.currentEntry = {};
|
4116 | this.currentEntry['entryType'] = 'PREAMBLE';
|
4117 | this.currentEntry['entry'] = this.value_comment();
|
4118 | this.entries.push(this.currentEntry);
|
4119 | };
|
4120 |
|
4121 | this.comment = function() {
|
4122 | this.currentEntry = {};
|
4123 | this.currentEntry['entryType'] = 'COMMENT';
|
4124 | this.currentEntry['entry'] = this.value_comment();
|
4125 | this.entries.push(this.currentEntry);
|
4126 | };
|
4127 |
|
4128 | this.entry = function(d) {
|
4129 | this.entry_body(d);
|
4130 | };
|
4131 |
|
4132 | this.bibtex = function() {
|
4133 | var this$1 = this;
|
4134 |
|
4135 | while (this.matchAt()) {
|
4136 | var d = this$1.directive();
|
4137 | this$1.match("{");
|
4138 | if (d == "@STRING") {
|
4139 | this$1.string();
|
4140 | } else if (d == "@PREAMBLE") {
|
4141 | this$1.preamble();
|
4142 | } else if (d == "@COMMENT") {
|
4143 | this$1.comment();
|
4144 | } else {
|
4145 | this$1.entry(d);
|
4146 | }
|
4147 | this$1.match("}");
|
4148 | }
|
4149 | };
|
4150 | }
|
4151 |
|
4152 | exports.toJSON = function(bibtex) {
|
4153 | var b = new BibtexParser();
|
4154 | b.setInput(bibtex);
|
4155 | b.bibtex();
|
4156 | return b.entries;
|
4157 | };
|
4158 |
|
4159 |
|
4160 | exports.toBibtex = function(json) {
|
4161 | var out = '';
|
4162 | for ( var i in json) {
|
4163 | out += "@" + json[i].entryType;
|
4164 | out += '{';
|
4165 | if (json[i].citationKey)
|
4166 | { out += json[i].citationKey + ', '; }
|
4167 | if (json[i].entry)
|
4168 | { out += json[i].entry ; }
|
4169 | if (json[i].entryTags) {
|
4170 | var tags = '';
|
4171 | for (var jdx in json[i].entryTags) {
|
4172 | if (tags.length != 0)
|
4173 | { tags += ', '; }
|
4174 | tags += jdx + '= {' + json[i].entryTags[jdx] + '}';
|
4175 | }
|
4176 | out += tags;
|
4177 | }
|
4178 | out += '}\n\n';
|
4179 | }
|
4180 | return out;
|
4181 |
|
4182 | };
|
4183 |
|
4184 | })(exports);
|
4185 |
|
4186 |
|
4187 | });
|
4188 |
|
4189 | var bibliography = function(dom, data) {
|
4190 | var el = dom.querySelector('script[type="text/bibliography"]');
|
4191 | var citations = [];
|
4192 | var bibliography = {};
|
4193 |
|
4194 | if (el) {
|
4195 | var rawBib = el.textContent;
|
4196 | var parsed = bibtexParse.toJSON(rawBib);
|
4197 | if(parsed) {
|
4198 | parsed.forEach(function (e) {
|
4199 | bibliography[e.citationKey] = e.entryTags;
|
4200 | bibliography[e.citationKey].type = e.entryType;
|
4201 | });
|
4202 | }
|
4203 |
|
4204 |
|
4205 | var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
|
4206 | citeTags.forEach(function (el) {
|
4207 | var key = el.getAttribute("key");
|
4208 | if (key) {
|
4209 | var citationKeys = key.split(",");
|
4210 | citationKeys.forEach(function (key) {
|
4211 | if (citations.indexOf(key) == -1){
|
4212 | citations.push(key);
|
4213 | if (!(key in bibliography)){
|
4214 | console.warn("No bibliography entry found for: " + key);
|
4215 | }
|
4216 | }
|
4217 | });
|
4218 | }
|
4219 | });
|
4220 | }
|
4221 | data.bibliography = bibliography;
|
4222 | data.citations = citations;
|
4223 | };
|
4224 |
|
4225 | var expandData = function(dom, data) {
|
4226 |
|
4227 | data.authors = data.authors || [];
|
4228 |
|
4229 |
|
4230 |
|
4231 |
|
4232 |
|
4233 |
|
4234 |
|
4235 |
|
4236 |
|
4237 | data.journal = data.journal || {};
|
4238 |
|
4239 |
|
4240 |
|
4241 | if (data.published){
|
4242 | data.volume = data.published.getFullYear() - 2015;
|
4243 | data.issue = data.published.getMonth() + 1;
|
4244 | }
|
4245 | |
4246 |
|
4247 |
|
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 |
|
4261 | };
|
4262 |
|
4263 | var favicon = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA99JREFUeNrsG4t1ozDMzQSM4A2ODUonKBucN2hugtIJ6E1AboLcBiQTkJsANiAb9OCd/OpzMWBJBl5TvaeXPiiyJetry0J8wW3D3QpjRh3GjneXDq+fSQA9s2mH9x3KDhN4foJfCb8N/Jrv+2fnDn8vLRQOplWHVYdvHZYdZsBcZP1vBmh/n8DzEmhUQDPaOuP9pFuY+JwJHwHnCLQE2tnWBGEyXozY9xCUgHMhhjE2I4heVWtgIkZ83wL6Qgxj1obfWBxymPwe+b00BCCRNPbwfb60yleAkkBHGT5AEehIYz7eJrFDMF9CvH4wwhcGHiHMneFvLDQwlwvMLQq58trRcYBWfYn0A0OgHWQUSu25mE+BnoYKnnEJoeIWAifzOv7vLWd2ZKRfWAIme3tOiUaQ3UnLkb0xj1FxRIeEGKaGIHOs9nEgLaaA9i0JRYo1Ic67wJW86KSKE/ZAM8KuVMk8ITVhmxUxJ3Cl2xlm9Vtkeju1+mpCQNxaEGNCY8bs9X2YqwNoQeGjBWut/ma0QAWy/TqAsHx9wSya3I5IRxOfTC+leG+kA/4vSeEcGBtNUN6byhu3+keEZCQJUNh8MAO7HL6H8pQLnsW/Hd4T4lv93TPjfM7A46iEEqbB5EDOvwYNW6tGNZzT/o+CZ6sqZ6wUtR/wf7mi/VL8iNciT6rHih48Y55b4nKCHJCCzb4y0nwFmin3ZEMIoLfZF8F7nncFmvnWBaBj7CGAYA/WGJsUwHdYqVDwAmNsUgAx4CGgAA7GOOxADYOFWOaIKifuVYzmOpREqA21Mo7aPsgiY1PhOMAmxtR+AUbYH3Id2wc0SAFIQTsn9IUGWR8k9jx3vtXSiAacFxTAGakBk9UudkNECd6jLe+6HrshshvIuC6IlLMRy7er+JpcKma24SlE4cFZSZJDGVVrsNvitQhQrDhW0jfiOLfFd47C42eHT56D/BK0To+58Ahj+cAT8HT1UWlfLZCCd/uKawzU0Rh2EyIX/Icqth3niG8ybNroezwe6khdCNxRN+l4XGdOLVLlOOt2hTRJlr1ETIuMAltVTMz70mJrkdGAaZLSmnBEqmAE32JCMmuTlCnRgsBENtOUpHhvvsYIL0ibnBkaC6QvKcR7738GKp0AKnim7xgUSNv1bpS8QwhBt8r+EP47v/oyRK/S34yJ9nT+AN0Tkm4OdB9E4BsmXM3SnMlRFUrtp6IDpV2eKzdYvF3etm3KhQksbOLChGkSmcBdmcEwvqkrMy5BzL00NZeu3qPYJOOuCc+5NjcWKXQxFvTa3NoXJ4d8in7fiAUuTt781dkvuHX4K8AA2Usy7yNKLy0AAAAASUVORK5CYII=\n";
|
4264 |
|
4265 | var meta = function(dom, data) {
|
4266 | var head = dom.querySelector("head");
|
4267 | var appendHead = function (html) { return appendHtml(head, html); };
|
4268 |
|
4269 | function meta(name, content) {
|
4270 | if (content)
|
4271 | { appendHead(("<meta name=\"" + name + "\" content=\"" + content + "\" >")); }
|
4272 | }
|
4273 |
|
4274 | appendHead(("\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge,chrome=1\">\n <link rel=\"icon\" type=\"image/png\" href=\"data:image/png;base64," + favicon + "\">\n <link href=\"/rss.xml\" rel=\"alternate\" type=\"application/rss+xml\" title=\"Articles from Distill\">\n <link rel=\"canonical\" href=\"" + (data.url) + "\">\n <title>" + (data.title) + "</title>\n "));
|
4275 |
|
4276 | appendHead(("\n <!-- https://schema.org/Article -->\n <meta property=\"article:published\" itemprop=\"datePublished\" content=\"" + (data.published) + "\" />\n <meta property=\"article:modified\" itemprop=\"dateModified\" content=\"" + (data.updated) + "\" />\n "));
|
4277 | data.authors.forEach(function (a) {
|
4278 | appendHtml(head, ("\n <meta property=\"article:author\" content=\"" + (a.firstName) + " " + (a.lastName) + "\" />"));
|
4279 | });
|
4280 |
|
4281 | appendHead(("\n <!-- https://developers.facebook.com/docs/sharing/webmasters#markup -->\n <meta property=\"og:type\" content=\"article\"/>\n <meta property=\"og:title\" content=\"" + (data.title) + "\"/>\n <meta property=\"og:description\" content=\"" + (data.description) + "\">\n <meta property=\"og:url\" content=\"" + (data.url) + "\"/>\n <meta property=\"og:image\" content=\"" + (data.url) + "/thumbnail.png\"/>\n <meta property=\"og:locale\" content=\"en_US\" />\n <meta property=\"og:site_name\" content=\"Distill\" />\n "));
|
4282 |
|
4283 | appendHead(("\n <!-- https://dev.twitter.com/cards/types/summary -->\n <meta name=\"twitter:card\" content=\"summary_large_image\">\n <meta name=\"twitter:title\" content=\"" + (data.title) + "\">\n <meta name=\"twitter:description\" content=\"" + (data.description) + "\">\n <meta name=\"twitter:url\" content=\"" + (data.url) + "\">\n <meta name=\"twitter:image\" content=\"" + (data.url) + "/thumbnail.png\">\n <meta name=\"twitter:image:width\" content=\"560\">\n <meta name=\"twitter:image:height\" content=\"295\">\n "));
|
4284 |
|
4285 | appendHead("\n <!-- https://scholar.google.com/intl/en/scholar/inclusion.html#indexing -->\n ");
|
4286 |
|
4287 | meta("citation_title", data.title);
|
4288 | meta("citation_fulltext_html_url", data.url);
|
4289 | meta("citation_volume", data.volume);
|
4290 | meta("citation_issue", data.issue);
|
4291 | meta("citation_firstpage", data.doiSuffix? ("e" + (data.doiSuffix)) : undefined);
|
4292 | meta("citation_doi", data.doi);
|
4293 |
|
4294 | var journal = data.journal || {};
|
4295 | meta("citation_journal_title", journal.name);
|
4296 | meta("citation_journal_abbrev", journal.nameAbbrev);
|
4297 | meta("citation_issn", journal.issn);
|
4298 | meta("citation_publisher", journal.publisher);
|
4299 |
|
4300 | if (data.published){
|
4301 | var zeroPad = function (n) { return n < 10 ? "0" + n : n; };
|
4302 | var publishedYear = data.published.getFullYear();
|
4303 | var publishedMonthPadded = zeroPad(data.published.getMonth() + 1);
|
4304 | var publishedDayPadded = zeroPad(data.published.getDate());
|
4305 | meta("citation_publication_date", (publishedYear + "/" + publishedMonthPadded + "/" + publishedDayPadded));
|
4306 | }
|
4307 |
|
4308 | (data.authors || []).forEach(function (a) {
|
4309 | meta("citation_author", ((a.lastName) + ", " + (a.firstName)));
|
4310 | meta("citation_author_institution", a.affiliation);
|
4311 | });
|
4312 |
|
4313 | if (data.citations) {
|
4314 | data.citations.forEach(function (key) {
|
4315 | var d = data.bibliography[key];
|
4316 | if(!d) {
|
4317 | console.warn("No bibliography data fround for " + key);
|
4318 | } else {
|
4319 | meta("citation_reference", citation_meta_content(data.bibliography[key]) );
|
4320 | }
|
4321 | });
|
4322 | }
|
4323 | };
|
4324 |
|
4325 | function appendHtml(el, html) {
|
4326 | el.innerHTML += html;
|
4327 | }
|
4328 |
|
4329 | function citation_meta_content(ref){
|
4330 | var content = "citation_title=" + (ref.title) + ";";
|
4331 | ref.author.split(" and ").forEach(function (author) {
|
4332 | content += "citation_author=" + (author.trim()) + ";";
|
4333 | });
|
4334 | if ("journal" in ref){
|
4335 | content += "citation_journal_title=" + (ref.journal) + ";";
|
4336 | }
|
4337 | if ("volume" in ref) {
|
4338 | content += "citation_volume=" + (ref.volume) + ";";
|
4339 | }
|
4340 | if ("issue" in ref || "number" in ref){
|
4341 | content += "citation_number=" + (ref.issue || ref.number) + ";";
|
4342 | }
|
4343 | |
4344 |
|
4345 | return content;
|
4346 | }
|
4347 |
|
4348 | var logo = "<svg viewBox=\"-607 419 64 64\">\n <path style=\"fill: none; stroke: black;stroke-width: 2px;\" d=\"M-573.4,478.9c-8,0-14.6-6.4-14.6-14.5s14.6-25.9,14.6-40.8c0,14.9,14.6,32.8,14.6,40.8S-565.4,478.9-573.4,478.9z\"/>\n</svg>\n";
|
4349 |
|
4350 | var html$1 = "\n<style>\ndt-header {\n display: block;\n position: relative;\n height: 60px;\n background-color: none;\n width: 100%;\n box-sizing: border-box;\n z-index: 2;\n color: rgba(0, 0, 0, 0.8);\n}\ndt-header .content {\n border-bottom: 1px solid rgba(0, 0, 0, 0.3);\n height: 60px;\n}\ndt-header a {\n font-size: 16px;\n height: 60px;\n line-height: 60px;\n text-decoration: none;\n color: rgba(0, 0, 0, 0.8);\n}\ndt-header svg {\n width: 24px;\n position: relative;\n top: 4px;\n margin-right: -2px;\n}\ndt-header svg path {\n fill: none;\n stroke: black;\n stroke-width: 1;\n stroke-linejoin: round;\n}\ndt-header .logo {\n font-size: 16px;\n font-weight: 300;\n}\ndt-header .nav {\n float: right;\n}\ndt-header .nav a {\n font-size: 14px;\n}\n</style>\n\n<div class=\"content l-page\">\n <a href=\"/\" class=\"logo\">\n " + logo + "\n Distill\n </a>\n <div class=\"nav\">\n </div>\n</div>\n";
|
4351 |
|
4352 | var header = function(dom, data) {
|
4353 | dom.querySelector('dt-header').innerHTML = html$1;
|
4354 | };
|
4355 |
|
4356 | var html$2 = "\n<style>\n dt-appendix {\n display: block;\n font-family: \"Open Sans\";\n font-size: 14px;\n line-height: 24px;\n margin-bottom: 0;\n border-top: 1px solid rgba(0,0,0,0.1);\n color: rgba(0,0,0,0.5);\n background: rgba(0,0,0,0.025);\n padding-top: 36px;\n padding-right: 24px;\n padding-bottom: 60px;\n padding-left: 24px;\n }\n dt-appendix h3 {\n font-size: 16px;\n font-weight: 500;\n margin-top: 18px;\n margin-bottom: 18px;\n color: rgba(0,0,0,0.65);\n }\n dt-appendix .citation {\n font-size: 11px;\n line-height: 15px;\n border-left: 1px solid rgba(0, 0, 0, 0.1);\n padding-left: 18px;\n border: 1px solid rgba(0,0,0,0.1);\n background: rgba(0, 0, 0, 0.02);\n padding: 10px 18px;\n border-radius: 3px;\n color: rgba(150, 150, 150, 1);\n overflow: hidden;\n margin-top: -12px;\n }\n dt-appendix .references {\n font-size: 12px;\n line-height: 20px;\n }\n dt-appendix a {\n color: rgba(0, 0, 0, 0.6);\n }\n</style>\n\n<div class=\"l-body\">\n <h3>References</h3>\n <dt-bibliography></dt-bibliography>\n <h3 id=\"citation\">Errors, Reuse, and Citation</h3>\n <p>If you see mistakes or want to suggest changes, please submit a pull request on <a class=\"github\">github</a>.</p>\n <p>Diagrams and text are licensed under Creative Commons Attribution <a href=\"https://creativecommons.org/licenses/by/2.0/\">CC-BY 2.0</a>, unless noted otherwise, with the source available on available on <a class=\"github\">github</a>. The figures that have been reused from other sources don't fall under this license and can be recognized by a note in their caption: “Figure from …”.</p>\n <p>For attribution in academic contexts, please cite this work as</p>\n <pre class=\"citation short\"></pre>\n <p>BibTeX citation</p>\n <pre class=\"citation long\"></pre>\n</div>\n";
|
4357 |
|
4358 |
|
4359 |
|
4360 |
|
4361 |
|
4362 |
|
4363 |
|
4364 |
|
4365 |
|
4366 |
|
4367 |
|
4368 |
|
4369 |
|
4370 |
|
4371 |
|
4372 |
|
4373 |
|
4374 | var appendix = function(dom, data) {
|
4375 | var el = dom.querySelector('dt-appendix');
|
4376 | if (el) { el.innerHTML = html$2; }
|
4377 | };
|
4378 |
|
4379 | var html$3 = "\n<style>\ndt-footer {\n display: block;\n color: rgba(255, 255, 255, 0.4);\n font-weight: 300;\n padding: 40px 0;\n border-top: 1px solid rgba(0, 0, 0, 0.1);\n background-color: rgba(0, 0, 0, 0.6);\n}\ndt-footer .logo svg {\n width: 24px;\n position: relative;\n top: 4px;\n margin-right: -2px;\n}\ndt-footer .logo svg path {\n stroke: rgba(255, 255, 255, 0.8)!important;\n stroke-width: 3px!important;\n}\ndt-footer .logo {\n font-size: 16px;\n font-weight: 300;\n color: rgba(255, 255, 255, 0.8);\n text-decoration: none;\n margin-right: 6px;\n}\n</style>\n\n<div class=\"l-body\">\n <a href=\"/\" class=\"logo\">\n " + logo + "\n Distill\n </a> is dedicated to clear explanations of machine learning\n</div>\n";
|
4380 |
|
4381 | var footer = function(dom, data) {
|
4382 | var el = dom.querySelector("dt-footer");
|
4383 | if(el) { el.innerHTML = html$3; }
|
4384 | };
|
4385 |
|
4386 | var citation = function(dom, data) {
|
4387 | var citations = data.citations;
|
4388 | |
4389 |
|
4390 |
|
4391 |
|
4392 |
|
4393 |
|
4394 |
|
4395 | var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
|
4396 | console.log(citeTags);
|
4397 | citeTags.forEach(function (el) {
|
4398 | var key = el.getAttribute("key");
|
4399 | if (key) {
|
4400 | var keys = key.split(",");
|
4401 | console.log(keys);
|
4402 | var cite_string = inline_cite_short(keys);
|
4403 | el.innerHTML = cite_string;
|
4404 | }
|
4405 | });
|
4406 |
|
4407 | var bibEl = dom.querySelector("dt-bibliography");
|
4408 | if (bibEl) {
|
4409 | var ol = dom.createElement("ol");
|
4410 | citations.forEach(function (key) {
|
4411 | var el = dom.createElement("li");
|
4412 | el.textContent = bibliography_cite(data.bibliography[key]);
|
4413 | ol.appendChild(el);
|
4414 | });
|
4415 | bibEl.appendChild(ol);
|
4416 | }
|
4417 |
|
4418 | function inline_cite_short(keys){
|
4419 | function cite_string(key){
|
4420 | if (key in data.bibliography){
|
4421 | var n = data.citations.indexOf(key)+1;
|
4422 | return ""+n;
|
4423 | } else {
|
4424 | return "?";
|
4425 | }
|
4426 | }
|
4427 | return "["+keys.map(cite_string).join(", ")+"]";
|
4428 | }
|
4429 |
|
4430 | function inline_cite_long(keys){
|
4431 | function cite_string(key){
|
4432 | if (key in data.bibliography){
|
4433 | var ent = data.bibliography[key];
|
4434 | var names = ent.author.split(" and ");
|
4435 | names = names.map(function (name) { return name.split(",")[0].trim(); });
|
4436 | var year = ent.year;
|
4437 | if (names.length == 1) { return names[0] + ", " + year; }
|
4438 | if (names.length == 2) { return names[0] + " & " + names[1] + ", " + year; }
|
4439 | if (names.length > 2) { return names[0] + ", et al., " + year; }
|
4440 | } else {
|
4441 | return "?";
|
4442 | }
|
4443 | }
|
4444 | return keys.map(cite_string).join(", ");
|
4445 | }
|
4446 |
|
4447 | function bibliography_cite(ent){
|
4448 | if (ent){
|
4449 | var names = ent.author.split(" and ");
|
4450 | var cite = "";
|
4451 | var name_strings = names.map(function (name) {
|
4452 | var last = name.split(",")[0].trim();
|
4453 | var firsts = name.split(",")[1];
|
4454 | if (firsts != undefined) {
|
4455 | var initials = firsts.trim().split(" ").map(function (s) { return s.trim()[0]; });
|
4456 | return last + ", " + initials.join(".")+".";
|
4457 | }
|
4458 | return last;
|
4459 | });
|
4460 | if (names.length > 1) {
|
4461 | cite += name_strings.slice(0, names.length-1).join(", ");
|
4462 | cite += " and " + name_strings[names.length-1];
|
4463 | } else {
|
4464 | cite += name_strings[0];
|
4465 | }
|
4466 | cite += ", " + ent.year + ". ";
|
4467 | cite += ent.title + ". ";
|
4468 | cite += (ent.journal || ent.booktitle || "");
|
4469 | if ("volume" in ent){
|
4470 | var issue = ent.issue || ent.number;
|
4471 | issue = (issue != undefined)? "("+issue+")" : "";
|
4472 | cite += ", Vol " + ent.volume + issue;
|
4473 | }
|
4474 | if ("pages" in ent){
|
4475 | cite += ", pp. " + ent.pages;
|
4476 | }
|
4477 | cite += ". ";
|
4478 | return cite
|
4479 | } else {
|
4480 | return "?";
|
4481 | }
|
4482 | }
|
4483 |
|
4484 |
|
4485 |
|
4486 | function get_URL(ent){
|
4487 | if (ent){
|
4488 | var names = ent.author.split(" and ");
|
4489 | names = names.map(function (name) { return name.split(",")[0].trim(); });
|
4490 | var title = ent.title.split(" ");
|
4491 | var url = "http://search.labs.crossref.org/dois?";
|
4492 | url += uris({q: names.join(" ") + " " + title.join(" ")});
|
4493 | }
|
4494 |
|
4495 | }
|
4496 | };
|
4497 |
|
4498 | var marked = createCommonjsModule(function (module, exports) {
|
4499 |
|
4500 |
|
4501 |
|
4502 |
|
4503 |
|
4504 |
|
4505 | (function() {
|
4506 |
|
4507 |
|
4508 |
|
4509 |
|
4510 |
|
4511 | var block = {
|
4512 | newline: /^\n+/,
|
4513 | code: /^( {4}[^\n]+\n*)+/,
|
4514 | fences: noop,
|
4515 | hr: /^( *[-*_]){3,} *(?:\n+|$)/,
|
4516 | heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
|
4517 | nptable: noop,
|
4518 | lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
|
4519 | blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
|
4520 | list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
|
4521 | html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
|
4522 | def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
|
4523 | table: noop,
|
4524 | paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
|
4525 | text: /^[^\n]+/
|
4526 | };
|
4527 |
|
4528 | block.bullet = /(?:[*+-]|\d+\.)/;
|
4529 | block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
|
4530 | block.item = replace(block.item, 'gm')
|
4531 | (/bull/g, block.bullet)
|
4532 | ();
|
4533 |
|
4534 | block.list = replace(block.list)
|
4535 | (/bull/g, block.bullet)
|
4536 | ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
|
4537 | ('def', '\\n+(?=' + block.def.source + ')')
|
4538 | ();
|
4539 |
|
4540 | block.blockquote = replace(block.blockquote)
|
4541 | ('def', block.def)
|
4542 | ();
|
4543 |
|
4544 | block._tag = '(?!(?:'
|
4545 | + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
|
4546 | + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
|
4547 | + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
|
4548 |
|
4549 | block.html = replace(block.html)
|
4550 | ('comment', //)
|
4551 | ('closed', /<(tag)[\s\S]+?<\/\1>/)
|
4552 | ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
|
4553 | (/tag/g, block._tag)
|
4554 | ();
|
4555 |
|
4556 | block.paragraph = replace(block.paragraph)
|
4557 | ('hr', block.hr)
|
4558 | ('heading', block.heading)
|
4559 | ('lheading', block.lheading)
|
4560 | ('blockquote', block.blockquote)
|
4561 | ('tag', '<' + block._tag)
|
4562 | ('def', block.def)
|
4563 | ();
|
4564 |
|
4565 | /**
|
4566 | * Normal Block Grammar
|
4567 | */
|
4568 |
|
4569 | block.normal = merge({}, block);
|
4570 |
|
4571 | /**
|
4572 | * GFM Block Grammar
|
4573 | */
|
4574 |
|
4575 | block.gfm = merge({}, block.normal, {
|
4576 | fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
|
4577 | paragraph: /^/,
|
4578 | heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
|
4579 | });
|
4580 |
|
4581 | block.gfm.paragraph = replace(block.paragraph)
|
4582 | ('(?!', '(?!'
|
4583 | + block.gfm.fences.source.replace('\\1', '\\2') + '|'
|
4584 | + block.list.source.replace('\\1', '\\3') + '|')
|
4585 | ();
|
4586 |
|
4587 | /**
|
4588 | * GFM + Tables Block Grammar
|
4589 | */
|
4590 |
|
4591 | block.tables = merge({}, block.gfm, {
|
4592 | nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
|
4593 | table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
|
4594 | });
|
4595 |
|
4596 | /**
|
4597 | * Block Lexer
|
4598 | */
|
4599 |
|
4600 | function Lexer(options) {
|
4601 | this.tokens = [];
|
4602 | this.tokens.links = {};
|
4603 | this.options = options || marked.defaults;
|
4604 | this.rules = block.normal;
|
4605 |
|
4606 | if (this.options.gfm) {
|
4607 | if (this.options.tables) {
|
4608 | this.rules = block.tables;
|
4609 | } else {
|
4610 | this.rules = block.gfm;
|
4611 | }
|
4612 | }
|
4613 | }
|
4614 |
|
4615 | /**
|
4616 | * Expose Block Rules
|
4617 | */
|
4618 |
|
4619 | Lexer.rules = block;
|
4620 |
|
4621 | /**
|
4622 | * Static Lex Method
|
4623 | */
|
4624 |
|
4625 | Lexer.lex = function(src, options) {
|
4626 | var lexer = new Lexer(options);
|
4627 | return lexer.lex(src);
|
4628 | };
|
4629 |
|
4630 | /**
|
4631 | * Preprocessing
|
4632 | */
|
4633 |
|
4634 | Lexer.prototype.lex = function(src) {
|
4635 | src = src
|
4636 | .replace(/\r\n|\r/g, '\n')
|
4637 | .replace(/\t/g, ' ')
|
4638 | .replace(/\u00a0/g, ' ')
|
4639 | .replace(/\u2424/g, '\n');
|
4640 |
|
4641 | return this.token(src, true);
|
4642 | };
|
4643 |
|
4644 | /**
|
4645 | * Lexing
|
4646 | */
|
4647 |
|
4648 | Lexer.prototype.token = function(src, top, bq) {
|
4649 | var this$1 = this;
|
4650 |
|
4651 | var src = src.replace(/^ +$/gm, '')
|
4652 | , next
|
4653 | , loose
|
4654 | , cap
|
4655 | , bull
|
4656 | , b
|
4657 | , item
|
4658 | , space
|
4659 | , i
|
4660 | , l;
|
4661 |
|
4662 | while (src) {
|
4663 | // newline
|
4664 | if (cap = this$1.rules.newline.exec(src)) {
|
4665 | src = src.substring(cap[0].length);
|
4666 | if (cap[0].length > 1) {
|
4667 | this$1.tokens.push({
|
4668 | type: 'space'
|
4669 | });
|
4670 | }
|
4671 | }
|
4672 |
|
4673 | // code
|
4674 | if (cap = this$1.rules.code.exec(src)) {
|
4675 | src = src.substring(cap[0].length);
|
4676 | cap = cap[0].replace(/^ {4}/gm, '');
|
4677 | this$1.tokens.push({
|
4678 | type: 'code',
|
4679 | text: !this$1.options.pedantic
|
4680 | ? cap.replace(/\n+$/, '')
|
4681 | : cap
|
4682 | });
|
4683 | continue;
|
4684 | }
|
4685 |
|
4686 | // fences (gfm)
|
4687 | if (cap = this$1.rules.fences.exec(src)) {
|
4688 | src = src.substring(cap[0].length);
|
4689 | this$1.tokens.push({
|
4690 | type: 'code',
|
4691 | lang: cap[2],
|
4692 | text: cap[3] || ''
|
4693 | });
|
4694 | continue;
|
4695 | }
|
4696 |
|
4697 | // heading
|
4698 | if (cap = this$1.rules.heading.exec(src)) {
|
4699 | src = src.substring(cap[0].length);
|
4700 | this$1.tokens.push({
|
4701 | type: 'heading',
|
4702 | depth: cap[1].length,
|
4703 | text: cap[2]
|
4704 | });
|
4705 | continue;
|
4706 | }
|
4707 |
|
4708 | // table no leading pipe (gfm)
|
4709 | if (top && (cap = this$1.rules.nptable.exec(src))) {
|
4710 | src = src.substring(cap[0].length);
|
4711 |
|
4712 | item = {
|
4713 | type: 'table',
|
4714 | header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
|
4715 | align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
4716 | cells: cap[3].replace(/\n$/, '').split('\n')
|
4717 | };
|
4718 |
|
4719 | for (i = 0; i < item.align.length; i++) {
|
4720 | if (/^ *-+: *$/.test(item.align[i])) {
|
4721 | item.align[i] = 'right';
|
4722 | } else if (/^ *:-+: *$/.test(item.align[i])) {
|
4723 | item.align[i] = 'center';
|
4724 | } else if (/^ *:-+ *$/.test(item.align[i])) {
|
4725 | item.align[i] = 'left';
|
4726 | } else {
|
4727 | item.align[i] = null;
|
4728 | }
|
4729 | }
|
4730 |
|
4731 | for (i = 0; i < item.cells.length; i++) {
|
4732 | item.cells[i] = item.cells[i].split(/ *\| */);
|
4733 | }
|
4734 |
|
4735 | this$1.tokens.push(item);
|
4736 |
|
4737 | continue;
|
4738 | }
|
4739 |
|
4740 | // lheading
|
4741 | if (cap = this$1.rules.lheading.exec(src)) {
|
4742 | src = src.substring(cap[0].length);
|
4743 | this$1.tokens.push({
|
4744 | type: 'heading',
|
4745 | depth: cap[2] === '=' ? 1 : 2,
|
4746 | text: cap[1]
|
4747 | });
|
4748 | continue;
|
4749 | }
|
4750 |
|
4751 | // hr
|
4752 | if (cap = this$1.rules.hr.exec(src)) {
|
4753 | src = src.substring(cap[0].length);
|
4754 | this$1.tokens.push({
|
4755 | type: 'hr'
|
4756 | });
|
4757 | continue;
|
4758 | }
|
4759 |
|
4760 | // blockquote
|
4761 | if (cap = this$1.rules.blockquote.exec(src)) {
|
4762 | src = src.substring(cap[0].length);
|
4763 |
|
4764 | this$1.tokens.push({
|
4765 | type: 'blockquote_start'
|
4766 | });
|
4767 |
|
4768 | cap = cap[0].replace(/^ *> ?/gm, '');
|
4769 |
|
4770 | // Pass `top` to keep the current
|
4771 | // "toplevel" state. This is exactly
|
4772 | // how markdown.pl works.
|
4773 | this$1.token(cap, top, true);
|
4774 |
|
4775 | this$1.tokens.push({
|
4776 | type: 'blockquote_end'
|
4777 | });
|
4778 |
|
4779 | continue;
|
4780 | }
|
4781 |
|
4782 | // list
|
4783 | if (cap = this$1.rules.list.exec(src)) {
|
4784 | src = src.substring(cap[0].length);
|
4785 | bull = cap[2];
|
4786 |
|
4787 | this$1.tokens.push({
|
4788 | type: 'list_start',
|
4789 | ordered: bull.length > 1
|
4790 | });
|
4791 |
|
4792 | // Get each top-level item.
|
4793 | cap = cap[0].match(this$1.rules.item);
|
4794 |
|
4795 | next = false;
|
4796 | l = cap.length;
|
4797 | i = 0;
|
4798 |
|
4799 | for (; i < l; i++) {
|
4800 | item = cap[i];
|
4801 |
|
4802 | // Remove the list item's bullet
|
4803 | // so it is seen as the next token.
|
4804 | space = item.length;
|
4805 | item = item.replace(/^ *([*+-]|\d+\.) +/, '');
|
4806 |
|
4807 | // Outdent whatever the
|
4808 | // list item contains. Hacky.
|
4809 | if (~item.indexOf('\n ')) {
|
4810 | space -= item.length;
|
4811 | item = !this$1.options.pedantic
|
4812 | ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
|
4813 | : item.replace(/^ {1,4}/gm, '');
|
4814 | }
|
4815 |
|
4816 | // Determine whether the next list item belongs here.
|
4817 | // Backpedal if it does not belong in this list.
|
4818 | if (this$1.options.smartLists && i !== l - 1) {
|
4819 | b = block.bullet.exec(cap[i + 1])[0];
|
4820 | if (bull !== b && !(bull.length > 1 && b.length > 1)) {
|
4821 | src = cap.slice(i + 1).join('\n') + src;
|
4822 | i = l - 1;
|
4823 | }
|
4824 | }
|
4825 |
|
4826 | // Determine whether item is loose or not.
|
4827 | // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
|
4828 | // for discount behavior.
|
4829 | loose = next || /\n\n(?!\s*$)/.test(item);
|
4830 | if (i !== l - 1) {
|
4831 | next = item.charAt(item.length - 1) === '\n';
|
4832 | if (!loose) { loose = next; }
|
4833 | }
|
4834 |
|
4835 | this$1.tokens.push({
|
4836 | type: loose
|
4837 | ? 'loose_item_start'
|
4838 | : 'list_item_start'
|
4839 | });
|
4840 |
|
4841 | // Recurse.
|
4842 | this$1.token(item, false, bq);
|
4843 |
|
4844 | this$1.tokens.push({
|
4845 | type: 'list_item_end'
|
4846 | });
|
4847 | }
|
4848 |
|
4849 | this$1.tokens.push({
|
4850 | type: 'list_end'
|
4851 | });
|
4852 |
|
4853 | continue;
|
4854 | }
|
4855 |
|
4856 | // html
|
4857 | if (cap = this$1.rules.html.exec(src)) {
|
4858 | src = src.substring(cap[0].length);
|
4859 | this$1.tokens.push({
|
4860 | type: this$1.options.sanitize
|
4861 | ? 'paragraph'
|
4862 | : 'html',
|
4863 | pre: !this$1.options.sanitizer
|
4864 | && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
|
4865 | text: cap[0]
|
4866 | });
|
4867 | continue;
|
4868 | }
|
4869 |
|
4870 | // def
|
4871 | if ((!bq && top) && (cap = this$1.rules.def.exec(src))) {
|
4872 | src = src.substring(cap[0].length);
|
4873 | this$1.tokens.links[cap[1].toLowerCase()] = {
|
4874 | href: cap[2],
|
4875 | title: cap[3]
|
4876 | };
|
4877 | continue;
|
4878 | }
|
4879 |
|
4880 | // table (gfm)
|
4881 | if (top && (cap = this$1.rules.table.exec(src))) {
|
4882 | src = src.substring(cap[0].length);
|
4883 |
|
4884 | item = {
|
4885 | type: 'table',
|
4886 | header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
|
4887 | align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
4888 | cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
|
4889 | };
|
4890 |
|
4891 | for (i = 0; i < item.align.length; i++) {
|
4892 | if (/^ *-+: *$/.test(item.align[i])) {
|
4893 | item.align[i] = 'right';
|
4894 | } else if (/^ *:-+: *$/.test(item.align[i])) {
|
4895 | item.align[i] = 'center';
|
4896 | } else if (/^ *:-+ *$/.test(item.align[i])) {
|
4897 | item.align[i] = 'left';
|
4898 | } else {
|
4899 | item.align[i] = null;
|
4900 | }
|
4901 | }
|
4902 |
|
4903 | for (i = 0; i < item.cells.length; i++) {
|
4904 | item.cells[i] = item.cells[i]
|
4905 | .replace(/^ *\| *| *\| *$/g, '')
|
4906 | .split(/ *\| */);
|
4907 | }
|
4908 |
|
4909 | this$1.tokens.push(item);
|
4910 |
|
4911 | continue;
|
4912 | }
|
4913 |
|
4914 | // top-level paragraph
|
4915 | if (top && (cap = this$1.rules.paragraph.exec(src))) {
|
4916 | src = src.substring(cap[0].length);
|
4917 | this$1.tokens.push({
|
4918 | type: 'paragraph',
|
4919 | text: cap[1].charAt(cap[1].length - 1) === '\n'
|
4920 | ? cap[1].slice(0, -1)
|
4921 | : cap[1]
|
4922 | });
|
4923 | continue;
|
4924 | }
|
4925 |
|
4926 | // text
|
4927 | if (cap = this$1.rules.text.exec(src)) {
|
4928 | // Top-level should never reach here.
|
4929 | src = src.substring(cap[0].length);
|
4930 | this$1.tokens.push({
|
4931 | type: 'text',
|
4932 | text: cap[0]
|
4933 | });
|
4934 | continue;
|
4935 | }
|
4936 |
|
4937 | if (src) {
|
4938 | throw new
|
4939 | Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
4940 | }
|
4941 | }
|
4942 |
|
4943 | return this.tokens;
|
4944 | };
|
4945 |
|
4946 | /**
|
4947 | * Inline-Level Grammar
|
4948 | */
|
4949 |
|
4950 | var inline = {
|
4951 | escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
|
4952 | autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
|
4953 | url: noop,
|
4954 | tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
|
4955 | link: /^!?\[(inside)\]\(href\)/,
|
4956 | reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
|
4957 | nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
|
4958 | strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
|
4959 | em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
|
4960 | code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
|
4961 | br: /^ {2,}\n(?!\s*$)/,
|
4962 | del: noop,
|
4963 | text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
|
4964 | };
|
4965 |
|
4966 | inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
|
4967 | inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
|
4968 |
|
4969 | inline.link = replace(inline.link)
|
4970 | ('inside', inline._inside)
|
4971 | ('href', inline._href)
|
4972 | ();
|
4973 |
|
4974 | inline.reflink = replace(inline.reflink)
|
4975 | ('inside', inline._inside)
|
4976 | ();
|
4977 |
|
4978 | /**
|
4979 | * Normal Inline Grammar
|
4980 | */
|
4981 |
|
4982 | inline.normal = merge({}, inline);
|
4983 |
|
4984 | /**
|
4985 | * Pedantic Inline Grammar
|
4986 | */
|
4987 |
|
4988 | inline.pedantic = merge({}, inline.normal, {
|
4989 | strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
|
4990 | em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
|
4991 | });
|
4992 |
|
4993 | /**
|
4994 | * GFM Inline Grammar
|
4995 | */
|
4996 |
|
4997 | inline.gfm = merge({}, inline.normal, {
|
4998 | escape: replace(inline.escape)('])', '~|])')(),
|
4999 | url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
|
5000 | del: /^~~(?=\S)([\s\S]*?\S)~~/,
|
5001 | text: replace(inline.text)
|
5002 | (']|', '~]|')
|
5003 | ('|', '|https?://|')
|
5004 | ()
|
5005 | });
|
5006 |
|
5007 | /**
|
5008 | * GFM + Line Breaks Inline Grammar
|
5009 | */
|
5010 |
|
5011 | inline.breaks = merge({}, inline.gfm, {
|
5012 | br: replace(inline.br)('{2,}', '*')(),
|
5013 | text: replace(inline.gfm.text)('{2,}', '*')()
|
5014 | });
|
5015 |
|
5016 | /**
|
5017 | * Inline Lexer & Compiler
|
5018 | */
|
5019 |
|
5020 | function InlineLexer(links, options) {
|
5021 | this.options = options || marked.defaults;
|
5022 | this.links = links;
|
5023 | this.rules = inline.normal;
|
5024 | this.renderer = this.options.renderer || new Renderer;
|
5025 | this.renderer.options = this.options;
|
5026 |
|
5027 | if (!this.links) {
|
5028 | throw new
|
5029 | Error('Tokens array requires a `links` property.');
|
5030 | }
|
5031 |
|
5032 | if (this.options.gfm) {
|
5033 | if (this.options.breaks) {
|
5034 | this.rules = inline.breaks;
|
5035 | } else {
|
5036 | this.rules = inline.gfm;
|
5037 | }
|
5038 | } else if (this.options.pedantic) {
|
5039 | this.rules = inline.pedantic;
|
5040 | }
|
5041 | }
|
5042 |
|
5043 | /**
|
5044 | * Expose Inline Rules
|
5045 | */
|
5046 |
|
5047 | InlineLexer.rules = inline;
|
5048 |
|
5049 | /**
|
5050 | * Static Lexing/Compiling Method
|
5051 | */
|
5052 |
|
5053 | InlineLexer.output = function(src, links, options) {
|
5054 | var inline = new InlineLexer(links, options);
|
5055 | return inline.output(src);
|
5056 | };
|
5057 |
|
5058 | /**
|
5059 | * Lexing/Compiling
|
5060 | */
|
5061 |
|
5062 | InlineLexer.prototype.output = function(src) {
|
5063 | var this$1 = this;
|
5064 |
|
5065 | var out = ''
|
5066 | , link
|
5067 | , text
|
5068 | , href
|
5069 | , cap;
|
5070 |
|
5071 | while (src) {
|
5072 | // escape
|
5073 | if (cap = this$1.rules.escape.exec(src)) {
|
5074 | src = src.substring(cap[0].length);
|
5075 | out += cap[1];
|
5076 | continue;
|
5077 | }
|
5078 |
|
5079 | // autolink
|
5080 | if (cap = this$1.rules.autolink.exec(src)) {
|
5081 | src = src.substring(cap[0].length);
|
5082 | if (cap[2] === '@') {
|
5083 | text = cap[1].charAt(6) === ':'
|
5084 | ? this$1.mangle(cap[1].substring(7))
|
5085 | : this$1.mangle(cap[1]);
|
5086 | href = this$1.mangle('mailto:') + text;
|
5087 | } else {
|
5088 | text = escape(cap[1]);
|
5089 | href = text;
|
5090 | }
|
5091 | out += this$1.renderer.link(href, null, text);
|
5092 | continue;
|
5093 | }
|
5094 |
|
5095 | // url (gfm)
|
5096 | if (!this$1.inLink && (cap = this$1.rules.url.exec(src))) {
|
5097 | src = src.substring(cap[0].length);
|
5098 | text = escape(cap[1]);
|
5099 | href = text;
|
5100 | out += this$1.renderer.link(href, null, text);
|
5101 | continue;
|
5102 | }
|
5103 |
|
5104 | // tag
|
5105 | if (cap = this$1.rules.tag.exec(src)) {
|
5106 | if (!this$1.inLink && /^<a /i.test(cap[0])) {
|
5107 | this$1.inLink = true;
|
5108 | } else if (this$1.inLink && /^<\/a>/i.test(cap[0])) {
|
5109 | this$1.inLink = false;
|
5110 | }
|
5111 | src = src.substring(cap[0].length);
|
5112 | out += this$1.options.sanitize
|
5113 | ? this$1.options.sanitizer
|
5114 | ? this$1.options.sanitizer(cap[0])
|
5115 | : escape(cap[0])
|
5116 | : cap[0];
|
5117 | continue;
|
5118 | }
|
5119 |
|
5120 | // link
|
5121 | if (cap = this$1.rules.link.exec(src)) {
|
5122 | src = src.substring(cap[0].length);
|
5123 | this$1.inLink = true;
|
5124 | out += this$1.outputLink(cap, {
|
5125 | href: cap[2],
|
5126 | title: cap[3]
|
5127 | });
|
5128 | this$1.inLink = false;
|
5129 | continue;
|
5130 | }
|
5131 |
|
5132 | // reflink, nolink
|
5133 | if ((cap = this$1.rules.reflink.exec(src))
|
5134 | || (cap = this$1.rules.nolink.exec(src))) {
|
5135 | src = src.substring(cap[0].length);
|
5136 | link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
|
5137 | link = this$1.links[link.toLowerCase()];
|
5138 | if (!link || !link.href) {
|
5139 | out += cap[0].charAt(0);
|
5140 | src = cap[0].substring(1) + src;
|
5141 | continue;
|
5142 | }
|
5143 | this$1.inLink = true;
|
5144 | out += this$1.outputLink(cap, link);
|
5145 | this$1.inLink = false;
|
5146 | continue;
|
5147 | }
|
5148 |
|
5149 | // strong
|
5150 | if (cap = this$1.rules.strong.exec(src)) {
|
5151 | src = src.substring(cap[0].length);
|
5152 | out += this$1.renderer.strong(this$1.output(cap[2] || cap[1]));
|
5153 | continue;
|
5154 | }
|
5155 |
|
5156 | // em
|
5157 | if (cap = this$1.rules.em.exec(src)) {
|
5158 | src = src.substring(cap[0].length);
|
5159 | out += this$1.renderer.em(this$1.output(cap[2] || cap[1]));
|
5160 | continue;
|
5161 | }
|
5162 |
|
5163 | // code
|
5164 | if (cap = this$1.rules.code.exec(src)) {
|
5165 | src = src.substring(cap[0].length);
|
5166 | out += this$1.renderer.codespan(escape(cap[2], true));
|
5167 | continue;
|
5168 | }
|
5169 |
|
5170 | // br
|
5171 | if (cap = this$1.rules.br.exec(src)) {
|
5172 | src = src.substring(cap[0].length);
|
5173 | out += this$1.renderer.br();
|
5174 | continue;
|
5175 | }
|
5176 |
|
5177 | // del (gfm)
|
5178 | if (cap = this$1.rules.del.exec(src)) {
|
5179 | src = src.substring(cap[0].length);
|
5180 | out += this$1.renderer.del(this$1.output(cap[1]));
|
5181 | continue;
|
5182 | }
|
5183 |
|
5184 | // text
|
5185 | if (cap = this$1.rules.text.exec(src)) {
|
5186 | src = src.substring(cap[0].length);
|
5187 | out += this$1.renderer.text(escape(this$1.smartypants(cap[0])));
|
5188 | continue;
|
5189 | }
|
5190 |
|
5191 | if (src) {
|
5192 | throw new
|
5193 | Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
5194 | }
|
5195 | }
|
5196 |
|
5197 | return out;
|
5198 | };
|
5199 |
|
5200 | /**
|
5201 | * Compile Link
|
5202 | */
|
5203 |
|
5204 | InlineLexer.prototype.outputLink = function(cap, link) {
|
5205 | var href = escape(link.href)
|
5206 | , title = link.title ? escape(link.title) : null;
|
5207 |
|
5208 | return cap[0].charAt(0) !== '!'
|
5209 | ? this.renderer.link(href, title, this.output(cap[1]))
|
5210 | : this.renderer.image(href, title, escape(cap[1]));
|
5211 | };
|
5212 |
|
5213 | /**
|
5214 | * Smartypants Transformations
|
5215 | */
|
5216 |
|
5217 | InlineLexer.prototype.smartypants = function(text) {
|
5218 | if (!this.options.smartypants) { return text; }
|
5219 | return text
|
5220 | // em-dashes
|
5221 | .replace(/---/g, '\u2014')
|
5222 | // en-dashes
|
5223 | .replace(/--/g, '\u2013')
|
5224 | // opening singles
|
5225 | .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
|
5226 | // closing singles & apostrophes
|
5227 | .replace(/'/g, '\u2019')
|
5228 | // opening doubles
|
5229 | .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
|
5230 | // closing doubles
|
5231 | .replace(/"/g, '\u201d')
|
5232 | // ellipses
|
5233 | .replace(/\.{3}/g, '\u2026');
|
5234 | };
|
5235 |
|
5236 | /**
|
5237 | * Mangle Links
|
5238 | */
|
5239 |
|
5240 | InlineLexer.prototype.mangle = function(text) {
|
5241 | if (!this.options.mangle) { return text; }
|
5242 | var out = ''
|
5243 | , l = text.length
|
5244 | , i = 0
|
5245 | , ch;
|
5246 |
|
5247 | for (; i < l; i++) {
|
5248 | ch = text.charCodeAt(i);
|
5249 | if (Math.random() > 0.5) {
|
5250 | ch = 'x' + ch.toString(16);
|
5251 | }
|
5252 | out += '&#' + ch + ';';
|
5253 | }
|
5254 |
|
5255 | return out;
|
5256 | };
|
5257 |
|
5258 | /**
|
5259 | * Renderer
|
5260 | */
|
5261 |
|
5262 | function Renderer(options) {
|
5263 | this.options = options || {};
|
5264 | }
|
5265 |
|
5266 | Renderer.prototype.code = function(code, lang, escaped) {
|
5267 | if (this.options.highlight) {
|
5268 | var out = this.options.highlight(code, lang);
|
5269 | if (out != null && out !== code) {
|
5270 | escaped = true;
|
5271 | code = out;
|
5272 | }
|
5273 | }
|
5274 |
|
5275 | if (!lang) {
|
5276 | return '<pre><code>'
|
5277 | + (escaped ? code : escape(code, true))
|
5278 | + '\n</code></pre>';
|
5279 | }
|
5280 |
|
5281 | return '<pre><code class="'
|
5282 | + this.options.langPrefix
|
5283 | + escape(lang, true)
|
5284 | + '">'
|
5285 | + (escaped ? code : escape(code, true))
|
5286 | + '\n</code></pre>\n';
|
5287 | };
|
5288 |
|
5289 | Renderer.prototype.blockquote = function(quote) {
|
5290 | return '<blockquote>\n' + quote + '</blockquote>\n';
|
5291 | };
|
5292 |
|
5293 | Renderer.prototype.html = function(html) {
|
5294 | return html;
|
5295 | };
|
5296 |
|
5297 | Renderer.prototype.heading = function(text, level, raw) {
|
5298 | return '<h'
|
5299 | + level
|
5300 | + ' id="'
|
5301 | + this.options.headerPrefix
|
5302 | + raw.toLowerCase().replace(/[^\w]+/g, '-')
|
5303 | + '">'
|
5304 | + text
|
5305 | + '</h'
|
5306 | + level
|
5307 | + '>\n';
|
5308 | };
|
5309 |
|
5310 | Renderer.prototype.hr = function() {
|
5311 | return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
5312 | };
|
5313 |
|
5314 | Renderer.prototype.list = function(body, ordered) {
|
5315 | var type = ordered ? 'ol' : 'ul';
|
5316 | return '<' + type + '>\n' + body + '</' + type + '>\n';
|
5317 | };
|
5318 |
|
5319 | Renderer.prototype.listitem = function(text) {
|
5320 | return '<li>' + text + '</li>\n';
|
5321 | };
|
5322 |
|
5323 | Renderer.prototype.paragraph = function(text) {
|
5324 | return '<p>' + text + '</p>\n';
|
5325 | };
|
5326 |
|
5327 | Renderer.prototype.table = function(header, body) {
|
5328 | return '<table>\n'
|
5329 | + '<thead>\n'
|
5330 | + header
|
5331 | + '</thead>\n'
|
5332 | + '<tbody>\n'
|
5333 | + body
|
5334 | + '</tbody>\n'
|
5335 | + '</table>\n';
|
5336 | };
|
5337 |
|
5338 | Renderer.prototype.tablerow = function(content) {
|
5339 | return '<tr>\n' + content + '</tr>\n';
|
5340 | };
|
5341 |
|
5342 | Renderer.prototype.tablecell = function(content, flags) {
|
5343 | var type = flags.header ? 'th' : 'td';
|
5344 | var tag = flags.align
|
5345 | ? '<' + type + ' style="text-align:' + flags.align + '">'
|
5346 | : '<' + type + '>';
|
5347 | return tag + content + '</' + type + '>\n';
|
5348 | };
|
5349 |
|
5350 | // span level renderer
|
5351 | Renderer.prototype.strong = function(text) {
|
5352 | return '<strong>' + text + '</strong>';
|
5353 | };
|
5354 |
|
5355 | Renderer.prototype.em = function(text) {
|
5356 | return '<em>' + text + '</em>';
|
5357 | };
|
5358 |
|
5359 | Renderer.prototype.codespan = function(text) {
|
5360 | return '<code>' + text + '</code>';
|
5361 | };
|
5362 |
|
5363 | Renderer.prototype.br = function() {
|
5364 | return this.options.xhtml ? '<br/>' : '<br>';
|
5365 | };
|
5366 |
|
5367 | Renderer.prototype.del = function(text) {
|
5368 | return '<del>' + text + '</del>';
|
5369 | };
|
5370 |
|
5371 | Renderer.prototype.link = function(href, title, text) {
|
5372 | if (this.options.sanitize) {
|
5373 | try {
|
5374 | var prot = decodeURIComponent(unescape(href))
|
5375 | .replace(/[^\w:]/g, '')
|
5376 | .toLowerCase();
|
5377 | } catch (e) {
|
5378 | return '';
|
5379 | }
|
5380 | if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
|
5381 | return '';
|
5382 | }
|
5383 | }
|
5384 | var out = '<a href="' + href + '"';
|
5385 | if (title) {
|
5386 | out += ' title="' + title + '"';
|
5387 | }
|
5388 | out += '>' + text + '</a>';
|
5389 | return out;
|
5390 | };
|
5391 |
|
5392 | Renderer.prototype.image = function(href, title, text) {
|
5393 | var out = '<img src="' + href + '" alt="' + text + '"';
|
5394 | if (title) {
|
5395 | out += ' title="' + title + '"';
|
5396 | }
|
5397 | out += this.options.xhtml ? '/>' : '>';
|
5398 | return out;
|
5399 | };
|
5400 |
|
5401 | Renderer.prototype.text = function(text) {
|
5402 | return text;
|
5403 | };
|
5404 |
|
5405 | /**
|
5406 | * Parsing & Compiling
|
5407 | */
|
5408 |
|
5409 | function Parser(options) {
|
5410 | this.tokens = [];
|
5411 | this.token = null;
|
5412 | this.options = options || marked.defaults;
|
5413 | this.options.renderer = this.options.renderer || new Renderer;
|
5414 | this.renderer = this.options.renderer;
|
5415 | this.renderer.options = this.options;
|
5416 | }
|
5417 |
|
5418 | /**
|
5419 | * Static Parse Method
|
5420 | */
|
5421 |
|
5422 | Parser.parse = function(src, options, renderer) {
|
5423 | var parser = new Parser(options, renderer);
|
5424 | return parser.parse(src);
|
5425 | };
|
5426 |
|
5427 | /**
|
5428 | * Parse Loop
|
5429 | */
|
5430 |
|
5431 | Parser.prototype.parse = function(src) {
|
5432 | var this$1 = this;
|
5433 |
|
5434 | this.inline = new InlineLexer(src.links, this.options, this.renderer);
|
5435 | this.tokens = src.reverse();
|
5436 |
|
5437 | var out = '';
|
5438 | while (this.next()) {
|
5439 | out += this$1.tok();
|
5440 | }
|
5441 |
|
5442 | return out;
|
5443 | };
|
5444 |
|
5445 | /**
|
5446 | * Next Token
|
5447 | */
|
5448 |
|
5449 | Parser.prototype.next = function() {
|
5450 | return this.token = this.tokens.pop();
|
5451 | };
|
5452 |
|
5453 | /**
|
5454 | * Preview Next Token
|
5455 | */
|
5456 |
|
5457 | Parser.prototype.peek = function() {
|
5458 | return this.tokens[this.tokens.length - 1] || 0;
|
5459 | };
|
5460 |
|
5461 | /**
|
5462 | * Parse Text Tokens
|
5463 | */
|
5464 |
|
5465 | Parser.prototype.parseText = function() {
|
5466 | var this$1 = this;
|
5467 |
|
5468 | var body = this.token.text;
|
5469 |
|
5470 | while (this.peek().type === 'text') {
|
5471 | body += '\n' + this$1.next().text;
|
5472 | }
|
5473 |
|
5474 | return this.inline.output(body);
|
5475 | };
|
5476 |
|
5477 | /**
|
5478 | * Parse Current Token
|
5479 | */
|
5480 |
|
5481 | Parser.prototype.tok = function() {
|
5482 | var this$1 = this;
|
5483 |
|
5484 | switch (this.token.type) {
|
5485 | case 'space': {
|
5486 | return '';
|
5487 | }
|
5488 | case 'hr': {
|
5489 | return this.renderer.hr();
|
5490 | }
|
5491 | case 'heading': {
|
5492 | return this.renderer.heading(
|
5493 | this.inline.output(this.token.text),
|
5494 | this.token.depth,
|
5495 | this.token.text);
|
5496 | }
|
5497 | case 'code': {
|
5498 | return this.renderer.code(this.token.text,
|
5499 | this.token.lang,
|
5500 | this.token.escaped);
|
5501 | }
|
5502 | case 'table': {
|
5503 | var header = ''
|
5504 | , body = ''
|
5505 | , i
|
5506 | , row
|
5507 | , cell
|
5508 | , flags
|
5509 | , j;
|
5510 |
|
5511 | // header
|
5512 | cell = '';
|
5513 | for (i = 0; i < this.token.header.length; i++) {
|
5514 | flags = { header: true, align: this$1.token.align[i] };
|
5515 | cell += this$1.renderer.tablecell(
|
5516 | this$1.inline.output(this$1.token.header[i]),
|
5517 | { header: true, align: this$1.token.align[i] }
|
5518 | );
|
5519 | }
|
5520 | header += this.renderer.tablerow(cell);
|
5521 |
|
5522 | for (i = 0; i < this.token.cells.length; i++) {
|
5523 | row = this$1.token.cells[i];
|
5524 |
|
5525 | cell = '';
|
5526 | for (j = 0; j < row.length; j++) {
|
5527 | cell += this$1.renderer.tablecell(
|
5528 | this$1.inline.output(row[j]),
|
5529 | { header: false, align: this$1.token.align[j] }
|
5530 | );
|
5531 | }
|
5532 |
|
5533 | body += this$1.renderer.tablerow(cell);
|
5534 | }
|
5535 | return this.renderer.table(header, body);
|
5536 | }
|
5537 | case 'blockquote_start': {
|
5538 | var body = '';
|
5539 |
|
5540 | while (this.next().type !== 'blockquote_end') {
|
5541 | body += this$1.tok();
|
5542 | }
|
5543 |
|
5544 | return this.renderer.blockquote(body);
|
5545 | }
|
5546 | case 'list_start': {
|
5547 | var body = ''
|
5548 | , ordered = this.token.ordered;
|
5549 |
|
5550 | while (this.next().type !== 'list_end') {
|
5551 | body += this$1.tok();
|
5552 | }
|
5553 |
|
5554 | return this.renderer.list(body, ordered);
|
5555 | }
|
5556 | case 'list_item_start': {
|
5557 | var body = '';
|
5558 |
|
5559 | while (this.next().type !== 'list_item_end') {
|
5560 | body += this$1.token.type === 'text'
|
5561 | ? this$1.parseText()
|
5562 | : this$1.tok();
|
5563 | }
|
5564 |
|
5565 | return this.renderer.listitem(body);
|
5566 | }
|
5567 | case 'loose_item_start': {
|
5568 | var body = '';
|
5569 |
|
5570 | while (this.next().type !== 'list_item_end') {
|
5571 | body += this$1.tok();
|
5572 | }
|
5573 |
|
5574 | return this.renderer.listitem(body);
|
5575 | }
|
5576 | case 'html': {
|
5577 | var html = !this.token.pre && !this.options.pedantic
|
5578 | ? this.inline.output(this.token.text)
|
5579 | : this.token.text;
|
5580 | return this.renderer.html(html);
|
5581 | }
|
5582 | case 'paragraph': {
|
5583 | return this.renderer.paragraph(this.inline.output(this.token.text));
|
5584 | }
|
5585 | case 'text': {
|
5586 | return this.renderer.paragraph(this.parseText());
|
5587 | }
|
5588 | }
|
5589 | };
|
5590 |
|
5591 | /**
|
5592 | * Helpers
|
5593 | */
|
5594 |
|
5595 | function escape(html, encode) {
|
5596 | return html
|
5597 | .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
|
5598 | .replace(/</g, '<')
|
5599 | .replace(/>/g, '>')
|
5600 | .replace(/"/g, '"')
|
5601 | .replace(/'/g, ''');
|
5602 | }
|
5603 |
|
5604 | function unescape(html) {
|
5605 | // explicitly match decimal, hex, and named HTML entities
|
5606 | return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
|
5607 | n = n.toLowerCase();
|
5608 | if (n === 'colon') { return ':'; }
|
5609 | if (n.charAt(0) === '#') {
|
5610 | return n.charAt(1) === 'x'
|
5611 | ? String.fromCharCode(parseInt(n.substring(2), 16))
|
5612 | : String.fromCharCode(+n.substring(1));
|
5613 | }
|
5614 | return '';
|
5615 | });
|
5616 | }
|
5617 |
|
5618 | function replace(regex, opt) {
|
5619 | regex = regex.source;
|
5620 | opt = opt || '';
|
5621 | return function self(name, val) {
|
5622 | if (!name) { return new RegExp(regex, opt); }
|
5623 | val = val.source || val;
|
5624 | val = val.replace(/(^|[^\[])\^/g, '$1');
|
5625 | regex = regex.replace(name, val);
|
5626 | return self;
|
5627 | };
|
5628 | }
|
5629 |
|
5630 | function noop() {}
|
5631 | noop.exec = noop;
|
5632 |
|
5633 | function merge(obj) {
|
5634 | var arguments$1 = arguments;
|
5635 |
|
5636 | var i = 1
|
5637 | , target
|
5638 | , key;
|
5639 |
|
5640 | for (; i < arguments.length; i++) {
|
5641 | target = arguments$1[i];
|
5642 | for (key in target) {
|
5643 | if (Object.prototype.hasOwnProperty.call(target, key)) {
|
5644 | obj[key] = target[key];
|
5645 | }
|
5646 | }
|
5647 | }
|
5648 |
|
5649 | return obj;
|
5650 | }
|
5651 |
|
5652 |
|
5653 | /**
|
5654 | * Marked
|
5655 | */
|
5656 |
|
5657 | function marked(src, opt, callback) {
|
5658 | if (callback || typeof opt === 'function') {
|
5659 | if (!callback) {
|
5660 | callback = opt;
|
5661 | opt = null;
|
5662 | }
|
5663 |
|
5664 | opt = merge({}, marked.defaults, opt || {});
|
5665 |
|
5666 | var highlight = opt.highlight
|
5667 | , tokens
|
5668 | , pending
|
5669 | , i = 0;
|
5670 |
|
5671 | try {
|
5672 | tokens = Lexer.lex(src, opt);
|
5673 | } catch (e) {
|
5674 | return callback(e);
|
5675 | }
|
5676 |
|
5677 | pending = tokens.length;
|
5678 |
|
5679 | var done = function(err) {
|
5680 | if (err) {
|
5681 | opt.highlight = highlight;
|
5682 | return callback(err);
|
5683 | }
|
5684 |
|
5685 | var out;
|
5686 |
|
5687 | try {
|
5688 | out = Parser.parse(tokens, opt);
|
5689 | } catch (e) {
|
5690 | err = e;
|
5691 | }
|
5692 |
|
5693 | opt.highlight = highlight;
|
5694 |
|
5695 | return err
|
5696 | ? callback(err)
|
5697 | : callback(null, out);
|
5698 | };
|
5699 |
|
5700 | if (!highlight || highlight.length < 3) {
|
5701 | return done();
|
5702 | }
|
5703 |
|
5704 | delete opt.highlight;
|
5705 |
|
5706 | if (!pending) { return done(); }
|
5707 |
|
5708 | for (; i < tokens.length; i++) {
|
5709 | (function(token) {
|
5710 | if (token.type !== 'code') {
|
5711 | return --pending || done();
|
5712 | }
|
5713 | return highlight(token.text, token.lang, function(err, code) {
|
5714 | if (err) { return done(err); }
|
5715 | if (code == null || code === token.text) {
|
5716 | return --pending || done();
|
5717 | }
|
5718 | token.text = code;
|
5719 | token.escaped = true;
|
5720 | --pending || done();
|
5721 | });
|
5722 | })(tokens[i]);
|
5723 | }
|
5724 |
|
5725 | return;
|
5726 | }
|
5727 | try {
|
5728 | if (opt) { opt = merge({}, marked.defaults, opt); }
|
5729 | return Parser.parse(Lexer.lex(src, opt), opt);
|
5730 | } catch (e) {
|
5731 | e.message += '\nPlease report this to https://github.com/chjj/marked.';
|
5732 | if ((opt || marked.defaults).silent) {
|
5733 | return '<p>An error occured:</p><pre>'
|
5734 | + escape(e.message + '', true)
|
5735 | + '</pre>';
|
5736 | }
|
5737 | throw e;
|
5738 | }
|
5739 | }
|
5740 |
|
5741 | /**
|
5742 | * Options
|
5743 | */
|
5744 |
|
5745 | marked.options =
|
5746 | marked.setOptions = function(opt) {
|
5747 | merge(marked.defaults, opt);
|
5748 | return marked;
|
5749 | };
|
5750 |
|
5751 | marked.defaults = {
|
5752 | gfm: true,
|
5753 | tables: true,
|
5754 | breaks: false,
|
5755 | pedantic: false,
|
5756 | sanitize: false,
|
5757 | sanitizer: null,
|
5758 | mangle: true,
|
5759 | smartLists: false,
|
5760 | silent: false,
|
5761 | highlight: null,
|
5762 | langPrefix: 'lang-',
|
5763 | smartypants: false,
|
5764 | headerPrefix: '',
|
5765 | renderer: new Renderer,
|
5766 | xhtml: false
|
5767 | };
|
5768 |
|
5769 | /**
|
5770 | * Expose
|
5771 | */
|
5772 |
|
5773 | marked.Parser = Parser;
|
5774 | marked.parser = Parser.parse;
|
5775 |
|
5776 | marked.Renderer = Renderer;
|
5777 |
|
5778 | marked.Lexer = Lexer;
|
5779 | marked.lexer = Lexer.lex;
|
5780 |
|
5781 | marked.InlineLexer = InlineLexer;
|
5782 | marked.inlineLexer = InlineLexer.output;
|
5783 |
|
5784 | marked.parse = marked;
|
5785 |
|
5786 | if ('object' !== 'undefined' && 'object' === 'object') {
|
5787 | module.exports = marked;
|
5788 | } else if (typeof undefined === 'function' && undefined.amd) {
|
5789 | undefined(function() { return marked; });
|
5790 | } else {
|
5791 | this.marked = marked;
|
5792 | }
|
5793 |
|
5794 | }).call(function() {
|
5795 | return this || (typeof window !== 'undefined' ? window : commonjsGlobal);
|
5796 | }());
|
5797 | });
|
5798 |
|
5799 | marked.setOptions({
|
5800 | gfm: true,
|
5801 | smartypants: true
|
5802 | });
|
5803 |
|
5804 | var markdown = function(dom, data) {
|
5805 | var markdownElements = [].slice.call(dom.querySelectorAll('[markdown]'));
|
5806 | markdownElements.forEach(function (el) {
|
5807 | var content = el.innerHTML;
|
5808 | // Set default indents
|
5809 | content = content.replace(/\n/, "");
|
5810 | var tabs = content.match(/\s*/);
|
5811 | content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
|
5812 | content = content.trim();
|
5813 |
|
5814 | el.innerHTML = marked(content);
|
5815 | });
|
5816 | };
|
5817 |
|
5818 | var prism = createCommonjsModule(function (module) {
|
5819 | /* **********************************************
|
5820 | Begin prism-core.js
|
5821 | ********************************************** */
|
5822 |
|
5823 | var _self = (typeof window !== 'undefined')
|
5824 | ? window // if in browser
|
5825 | : (
|
5826 | (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
|
5827 | ? self // if in worker
|
5828 | : {} // if in node js
|
5829 | );
|
5830 |
|
5831 | /**
|
5832 | * Prism: Lightweight, robust, elegant syntax highlighting
|
5833 | * MIT license http://www.opensource.org/licenses/mit-license.php/
|
5834 | * @author Lea Verou http://lea.verou.me
|
5835 | */
|
5836 |
|
5837 | var Prism = (function(){
|
5838 |
|
5839 | // Private helper vars
|
5840 | var lang = /\blang(?:uage)?-(\w+)\b/i;
|
5841 | var uniqueId = 0;
|
5842 |
|
5843 | var _ = _self.Prism = {
|
5844 | util: {
|
5845 | encode: function (tokens) {
|
5846 | if (tokens instanceof Token) {
|
5847 | return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
|
5848 | } else if (_.util.type(tokens) === 'Array') {
|
5849 | return tokens.map(_.util.encode);
|
5850 | } else {
|
5851 | return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
|
5852 | }
|
5853 | },
|
5854 |
|
5855 | type: function (o) {
|
5856 | return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
|
5857 | },
|
5858 |
|
5859 | objId: function (obj) {
|
5860 | if (!obj['__id']) {
|
5861 | Object.defineProperty(obj, '__id', { value: ++uniqueId });
|
5862 | }
|
5863 | return obj['__id'];
|
5864 | },
|
5865 |
|
5866 | // Deep clone a language definition (e.g. to extend it)
|
5867 | clone: function (o) {
|
5868 | var type = _.util.type(o);
|
5869 |
|
5870 | switch (type) {
|
5871 | case 'Object':
|
5872 | var clone = {};
|
5873 |
|
5874 | for (var key in o) {
|
5875 | if (o.hasOwnProperty(key)) {
|
5876 | clone[key] = _.util.clone(o[key]);
|
5877 | }
|
5878 | }
|
5879 |
|
5880 | return clone;
|
5881 |
|
5882 | case 'Array':
|
5883 | // Check for existence for IE8
|
5884 | return o.map && o.map(function(v) { return _.util.clone(v); });
|
5885 | }
|
5886 |
|
5887 | return o;
|
5888 | }
|
5889 | },
|
5890 |
|
5891 | languages: {
|
5892 | extend: function (id, redef) {
|
5893 | var lang = _.util.clone(_.languages[id]);
|
5894 |
|
5895 | for (var key in redef) {
|
5896 | lang[key] = redef[key];
|
5897 | }
|
5898 |
|
5899 | return lang;
|
5900 | },
|
5901 |
|
5902 | /**
|
5903 | * Insert a token before another token in a language literal
|
5904 | * As this needs to recreate the object (we cannot actually insert before keys in object literals),
|
5905 | * we cannot just provide an object, we need anobject and a key.
|
5906 | * @param inside The key (or language id) of the parent
|
5907 | * @param before The key to insert before. If not provided, the function appends instead.
|
5908 | * @param insert Object with the key/value pairs to insert
|
5909 | * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
|
5910 | */
|
5911 | insertBefore: function (inside, before, insert, root) {
|
5912 | root = root || _.languages;
|
5913 | var grammar = root[inside];
|
5914 |
|
5915 | if (arguments.length == 2) {
|
5916 | insert = arguments[1];
|
5917 |
|
5918 | for (var newToken in insert) {
|
5919 | if (insert.hasOwnProperty(newToken)) {
|
5920 | grammar[newToken] = insert[newToken];
|
5921 | }
|
5922 | }
|
5923 |
|
5924 | return grammar;
|
5925 | }
|
5926 |
|
5927 | var ret = {};
|
5928 |
|
5929 | for (var token in grammar) {
|
5930 |
|
5931 | if (grammar.hasOwnProperty(token)) {
|
5932 |
|
5933 | if (token == before) {
|
5934 |
|
5935 | for (var newToken in insert) {
|
5936 |
|
5937 | if (insert.hasOwnProperty(newToken)) {
|
5938 | ret[newToken] = insert[newToken];
|
5939 | }
|
5940 | }
|
5941 | }
|
5942 |
|
5943 | ret[token] = grammar[token];
|
5944 | }
|
5945 | }
|
5946 |
|
5947 | // Update references in other language definitions
|
5948 | _.languages.DFS(_.languages, function(key, value) {
|
5949 | if (value === root[inside] && key != inside) {
|
5950 | this[key] = ret;
|
5951 | }
|
5952 | });
|
5953 |
|
5954 | return root[inside] = ret;
|
5955 | },
|
5956 |
|
5957 | // Traverse a language definition with Depth First Search
|
5958 | DFS: function(o, callback, type, visited) {
|
5959 | visited = visited || {};
|
5960 | for (var i in o) {
|
5961 | if (o.hasOwnProperty(i)) {
|
5962 | callback.call(o, i, o[i], type || i);
|
5963 |
|
5964 | if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
|
5965 | visited[_.util.objId(o[i])] = true;
|
5966 | _.languages.DFS(o[i], callback, null, visited);
|
5967 | }
|
5968 | else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
|
5969 | visited[_.util.objId(o[i])] = true;
|
5970 | _.languages.DFS(o[i], callback, i, visited);
|
5971 | }
|
5972 | }
|
5973 | }
|
5974 | }
|
5975 | },
|
5976 | plugins: {},
|
5977 |
|
5978 | highlightAll: function(async, callback) {
|
5979 | var env = {
|
5980 | callback: callback,
|
5981 | selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
5982 | };
|
5983 |
|
5984 | _.hooks.run("before-highlightall", env);
|
5985 |
|
5986 | var elements = env.elements || document.querySelectorAll(env.selector);
|
5987 |
|
5988 | for (var i=0, element; element = elements[i++];) {
|
5989 | _.highlightElement(element, async === true, env.callback);
|
5990 | }
|
5991 | },
|
5992 |
|
5993 | highlightElement: function(element, async, callback) {
|
5994 | // Find language
|
5995 | var language, grammar, parent = element;
|
5996 |
|
5997 | while (parent && !lang.test(parent.className)) {
|
5998 | parent = parent.parentNode;
|
5999 | }
|
6000 |
|
6001 | if (parent) {
|
6002 | language = (parent.className.match(lang) || [,''])[1].toLowerCase();
|
6003 | grammar = _.languages[language];
|
6004 | }
|
6005 |
|
6006 | // Set language on the element, if not present
|
6007 | element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
|
6008 |
|
6009 | // Set language on the parent, for styling
|
6010 | parent = element.parentNode;
|
6011 |
|
6012 | if (/pre/i.test(parent.nodeName)) {
|
6013 | parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
|
6014 | }
|
6015 |
|
6016 | var code = element.textContent;
|
6017 |
|
6018 | var env = {
|
6019 | element: element,
|
6020 | language: language,
|
6021 | grammar: grammar,
|
6022 | code: code
|
6023 | };
|
6024 |
|
6025 | _.hooks.run('before-sanity-check', env);
|
6026 |
|
6027 | if (!env.code || !env.grammar) {
|
6028 | if (env.code) {
|
6029 | env.element.textContent = env.code;
|
6030 | }
|
6031 | _.hooks.run('complete', env);
|
6032 | return;
|
6033 | }
|
6034 |
|
6035 | _.hooks.run('before-highlight', env);
|
6036 |
|
6037 | if (async && _self.Worker) {
|
6038 | var worker = new Worker(_.filename);
|
6039 |
|
6040 | worker.onmessage = function(evt) {
|
6041 | env.highlightedCode = evt.data;
|
6042 |
|
6043 | _.hooks.run('before-insert', env);
|
6044 |
|
6045 | env.element.innerHTML = env.highlightedCode;
|
6046 |
|
6047 | callback && callback.call(env.element);
|
6048 | _.hooks.run('after-highlight', env);
|
6049 | _.hooks.run('complete', env);
|
6050 | };
|
6051 |
|
6052 | worker.postMessage(JSON.stringify({
|
6053 | language: env.language,
|
6054 | code: env.code,
|
6055 | immediateClose: true
|
6056 | }));
|
6057 | }
|
6058 | else {
|
6059 | env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
|
6060 |
|
6061 | _.hooks.run('before-insert', env);
|
6062 |
|
6063 | env.element.innerHTML = env.highlightedCode;
|
6064 |
|
6065 | callback && callback.call(element);
|
6066 |
|
6067 | _.hooks.run('after-highlight', env);
|
6068 | _.hooks.run('complete', env);
|
6069 | }
|
6070 | },
|
6071 |
|
6072 | highlight: function (text, grammar, language) {
|
6073 | var tokens = _.tokenize(text, grammar);
|
6074 | return Token.stringify(_.util.encode(tokens), language);
|
6075 | },
|
6076 |
|
6077 | tokenize: function(text, grammar, language) {
|
6078 | var Token = _.Token;
|
6079 |
|
6080 | var strarr = [text];
|
6081 |
|
6082 | var rest = grammar.rest;
|
6083 |
|
6084 | if (rest) {
|
6085 | for (var token in rest) {
|
6086 | grammar[token] = rest[token];
|
6087 | }
|
6088 |
|
6089 | delete grammar.rest;
|
6090 | }
|
6091 |
|
6092 | tokenloop: for (var token in grammar) {
|
6093 | if(!grammar.hasOwnProperty(token) || !grammar[token]) {
|
6094 | continue;
|
6095 | }
|
6096 |
|
6097 | var patterns = grammar[token];
|
6098 | patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
|
6099 |
|
6100 | for (var j = 0; j < patterns.length; ++j) {
|
6101 | var pattern = patterns[j],
|
6102 | inside = pattern.inside,
|
6103 | lookbehind = !!pattern.lookbehind,
|
6104 | greedy = !!pattern.greedy,
|
6105 | lookbehindLength = 0,
|
6106 | alias = pattern.alias;
|
6107 |
|
6108 | if (greedy && !pattern.pattern.global) {
|
6109 | // Without the global flag, lastIndex won't work
|
6110 | var flags = pattern.pattern.toString().match(/[imuy]*$/)[0];
|
6111 | pattern.pattern = RegExp(pattern.pattern.source, flags + "g");
|
6112 | }
|
6113 |
|
6114 | pattern = pattern.pattern || pattern;
|
6115 |
|
6116 | // Don’t cache length as it changes during the loop
|
6117 | for (var i=0, pos = 0; i<strarr.length; pos += strarr[i].length, ++i) {
|
6118 |
|
6119 | var str = strarr[i];
|
6120 |
|
6121 | if (strarr.length > text.length) {
|
6122 | // Something went terribly wrong, ABORT, ABORT!
|
6123 | break tokenloop;
|
6124 | }
|
6125 |
|
6126 | if (str instanceof Token) {
|
6127 | continue;
|
6128 | }
|
6129 |
|
6130 | pattern.lastIndex = 0;
|
6131 |
|
6132 | var match = pattern.exec(str),
|
6133 | delNum = 1;
|
6134 |
|
6135 | // Greedy patterns can override/remove up to two previously matched tokens
|
6136 | if (!match && greedy && i != strarr.length - 1) {
|
6137 | pattern.lastIndex = pos;
|
6138 | match = pattern.exec(text);
|
6139 | if (!match) {
|
6140 | break;
|
6141 | }
|
6142 |
|
6143 | var from = match.index + (lookbehind ? match[1].length : 0),
|
6144 | to = match.index + match[0].length,
|
6145 | k = i,
|
6146 | p = pos;
|
6147 |
|
6148 | for (var len = strarr.length; k < len && p < to; ++k) {
|
6149 | p += strarr[k].length;
|
6150 | // Move the index i to the element in strarr that is closest to from
|
6151 | if (from >= p) {
|
6152 | ++i;
|
6153 | pos = p;
|
6154 | }
|
6155 | }
|
6156 |
|
6157 | /*
|
6158 | * If strarr[i] is a Token, then the match starts inside another Token, which is invalid
|
6159 | * If strarr[k - 1] is greedy we are in conflict with another greedy pattern
|
6160 | */
|
6161 | if (strarr[i] instanceof Token || strarr[k - 1].greedy) {
|
6162 | continue;
|
6163 | }
|
6164 |
|
6165 | // Number of tokens to delete and replace with the new match
|
6166 | delNum = k - i;
|
6167 | str = text.slice(pos, p);
|
6168 | match.index -= pos;
|
6169 | }
|
6170 |
|
6171 | if (!match) {
|
6172 | continue;
|
6173 | }
|
6174 |
|
6175 | if(lookbehind) {
|
6176 | lookbehindLength = match[1].length;
|
6177 | }
|
6178 |
|
6179 | var from = match.index + lookbehindLength,
|
6180 | match = match[0].slice(lookbehindLength),
|
6181 | to = from + match.length,
|
6182 | before = str.slice(0, from),
|
6183 | after = str.slice(to);
|
6184 |
|
6185 | var args = [i, delNum];
|
6186 |
|
6187 | if (before) {
|
6188 | args.push(before);
|
6189 | }
|
6190 |
|
6191 | var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
|
6192 |
|
6193 | args.push(wrapped);
|
6194 |
|
6195 | if (after) {
|
6196 | args.push(after);
|
6197 | }
|
6198 |
|
6199 | Array.prototype.splice.apply(strarr, args);
|
6200 | }
|
6201 | }
|
6202 | }
|
6203 |
|
6204 | return strarr;
|
6205 | },
|
6206 |
|
6207 | hooks: {
|
6208 | all: {},
|
6209 |
|
6210 | add: function (name, callback) {
|
6211 | var hooks = _.hooks.all;
|
6212 |
|
6213 | hooks[name] = hooks[name] || [];
|
6214 |
|
6215 | hooks[name].push(callback);
|
6216 | },
|
6217 |
|
6218 | run: function (name, env) {
|
6219 | var callbacks = _.hooks.all[name];
|
6220 |
|
6221 | if (!callbacks || !callbacks.length) {
|
6222 | return;
|
6223 | }
|
6224 |
|
6225 | for (var i=0, callback; callback = callbacks[i++];) {
|
6226 | callback(env);
|
6227 | }
|
6228 | }
|
6229 | }
|
6230 | };
|
6231 |
|
6232 | var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
|
6233 | this.type = type;
|
6234 | this.content = content;
|
6235 | this.alias = alias;
|
6236 | // Copy of the full string this token was created from
|
6237 | this.length = (matchedStr || "").length|0;
|
6238 | this.greedy = !!greedy;
|
6239 | };
|
6240 |
|
6241 | Token.stringify = function(o, language, parent) {
|
6242 | if (typeof o == 'string') {
|
6243 | return o;
|
6244 | }
|
6245 |
|
6246 | if (_.util.type(o) === 'Array') {
|
6247 | return o.map(function(element) {
|
6248 | return Token.stringify(element, language, o);
|
6249 | }).join('');
|
6250 | }
|
6251 |
|
6252 | var env = {
|
6253 | type: o.type,
|
6254 | content: Token.stringify(o.content, language, parent),
|
6255 | tag: 'span',
|
6256 | classes: ['token', o.type],
|
6257 | attributes: {},
|
6258 | language: language,
|
6259 | parent: parent
|
6260 | };
|
6261 |
|
6262 | if (env.type == 'comment') {
|
6263 | env.attributes['spellcheck'] = 'true';
|
6264 | }
|
6265 |
|
6266 | if (o.alias) {
|
6267 | var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
|
6268 | Array.prototype.push.apply(env.classes, aliases);
|
6269 | }
|
6270 |
|
6271 | _.hooks.run('wrap', env);
|
6272 |
|
6273 | var attributes = Object.keys(env.attributes).map(function(name) {
|
6274 | return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
|
6275 | }).join(' ');
|
6276 |
|
6277 | return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
|
6278 |
|
6279 | };
|
6280 |
|
6281 | if (!_self.document) {
|
6282 | if (!_self.addEventListener) {
|
6283 | // in Node.js
|
6284 | return _self.Prism;
|
6285 | }
|
6286 | // In worker
|
6287 | _self.addEventListener('message', function(evt) {
|
6288 | var message = JSON.parse(evt.data),
|
6289 | lang = message.language,
|
6290 | code = message.code,
|
6291 | immediateClose = message.immediateClose;
|
6292 |
|
6293 | _self.postMessage(_.highlight(code, _.languages[lang], lang));
|
6294 | if (immediateClose) {
|
6295 | _self.close();
|
6296 | }
|
6297 | }, false);
|
6298 |
|
6299 | return _self.Prism;
|
6300 | }
|
6301 |
|
6302 | //Get current script and highlight
|
6303 | var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
|
6304 |
|
6305 | if (script) {
|
6306 | _.filename = script.src;
|
6307 |
|
6308 | if (document.addEventListener && !script.hasAttribute('data-manual')) {
|
6309 | if(document.readyState !== "loading") {
|
6310 | if (window.requestAnimationFrame) {
|
6311 | window.requestAnimationFrame(_.highlightAll);
|
6312 | } else {
|
6313 | window.setTimeout(_.highlightAll, 16);
|
6314 | }
|
6315 | }
|
6316 | else {
|
6317 | document.addEventListener('DOMContentLoaded', _.highlightAll);
|
6318 | }
|
6319 | }
|
6320 | }
|
6321 |
|
6322 | return _self.Prism;
|
6323 |
|
6324 | })();
|
6325 |
|
6326 | if ('object' !== 'undefined' && module.exports) {
|
6327 | module.exports = Prism;
|
6328 | }
|
6329 |
|
6330 | // hack for components to work correctly in node.js
|
6331 | if (typeof commonjsGlobal !== 'undefined') {
|
6332 | commonjsGlobal.Prism = Prism;
|
6333 | }
|
6334 |
|
6335 |
|
6336 | /* **********************************************
|
6337 | Begin prism-markup.js
|
6338 | ********************************************** */
|
6339 |
|
6340 | Prism.languages.markup = {
|
6341 | 'comment': /<!--[\w\W]*?-->/,
|
6342 | 'prolog': /<\?[\w\W]+?\?>/,
|
6343 | 'doctype': /<!DOCTYPE[\w\W]+?>/i,
|
6344 | 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
|
6345 | 'tag': {
|
6346 | pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
|
6347 | inside: {
|
6348 | 'tag': {
|
6349 | pattern: /^<\/?[^\s>\/]+/i,
|
6350 | inside: {
|
6351 | 'punctuation': /^<\/?/,
|
6352 | 'namespace': /^[^\s>\/:]+:/
|
6353 | }
|
6354 | },
|
6355 | 'attr-value': {
|
6356 | pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
|
6357 | inside: {
|
6358 | 'punctuation': /[=>"']/
|
6359 | }
|
6360 | },
|
6361 | 'punctuation': /\/?>/,
|
6362 | 'attr-name': {
|
6363 | pattern: /[^\s>\/]+/,
|
6364 | inside: {
|
6365 | 'namespace': /^[^\s>\/:]+:/
|
6366 | }
|
6367 | }
|
6368 |
|
6369 | }
|
6370 | },
|
6371 | 'entity': /&#?[\da-z]{1,8};/i
|
6372 | };
|
6373 |
|
6374 | // Plugin to make entity title show the real entity, idea by Roman Komarov
|
6375 | Prism.hooks.add('wrap', function(env) {
|
6376 |
|
6377 | if (env.type === 'entity') {
|
6378 | env.attributes['title'] = env.content.replace(/&/, '&');
|
6379 | }
|
6380 | });
|
6381 |
|
6382 | Prism.languages.xml = Prism.languages.markup;
|
6383 | Prism.languages.html = Prism.languages.markup;
|
6384 | Prism.languages.mathml = Prism.languages.markup;
|
6385 | Prism.languages.svg = Prism.languages.markup;
|
6386 |
|
6387 |
|
6388 | /* **********************************************
|
6389 | Begin prism-css.js
|
6390 | ********************************************** */
|
6391 |
|
6392 | Prism.languages.css = {
|
6393 | 'comment': /\/\*[\w\W]*?\*\//,
|
6394 | 'atrule': {
|
6395 | pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
|
6396 | inside: {
|
6397 | 'rule': /@[\w-]+/
|
6398 | // See rest below
|
6399 | }
|
6400 | },
|
6401 | 'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
|
6402 | 'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
|
6403 | 'string': {
|
6404 | pattern: /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
|
6405 | greedy: true
|
6406 | },
|
6407 | 'property': /(\b|\B)[\w-]+(?=\s*:)/i,
|
6408 | 'important': /\B!important\b/i,
|
6409 | 'function': /[-a-z0-9]+(?=\()/i,
|
6410 | 'punctuation': /[(){};:]/
|
6411 | };
|
6412 |
|
6413 | Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
|
6414 |
|
6415 | if (Prism.languages.markup) {
|
6416 | Prism.languages.insertBefore('markup', 'tag', {
|
6417 | 'style': {
|
6418 | pattern: /(<style[\w\W]*?>)[\w\W]*?(?=<\/style>)/i,
|
6419 | lookbehind: true,
|
6420 | inside: Prism.languages.css,
|
6421 | alias: 'language-css'
|
6422 | }
|
6423 | });
|
6424 |
|
6425 | Prism.languages.insertBefore('inside', 'attr-value', {
|
6426 | 'style-attr': {
|
6427 | pattern: /\s*style=("|').*?\1/i,
|
6428 | inside: {
|
6429 | 'attr-name': {
|
6430 | pattern: /^\s*style/i,
|
6431 | inside: Prism.languages.markup.tag.inside
|
6432 | },
|
6433 | 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
|
6434 | 'attr-value': {
|
6435 | pattern: /.+/i,
|
6436 | inside: Prism.languages.css
|
6437 | }
|
6438 | },
|
6439 | alias: 'language-css'
|
6440 | }
|
6441 | }, Prism.languages.markup.tag);
|
6442 | }
|
6443 |
|
6444 | /* **********************************************
|
6445 | Begin prism-clike.js
|
6446 | ********************************************** */
|
6447 |
|
6448 | Prism.languages.clike = {
|
6449 | 'comment': [
|
6450 | {
|
6451 | pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
|
6452 | lookbehind: true
|
6453 | },
|
6454 | {
|
6455 | pattern: /(^|[^\\:])\/\/.*/,
|
6456 | lookbehind: true
|
6457 | }
|
6458 | ],
|
6459 | 'string': {
|
6460 | pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
6461 | greedy: true
|
6462 | },
|
6463 | 'class-name': {
|
6464 | pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
|
6465 | lookbehind: true,
|
6466 | inside: {
|
6467 | punctuation: /(\.|\\)/
|
6468 | }
|
6469 | },
|
6470 | 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
|
6471 | 'boolean': /\b(true|false)\b/,
|
6472 | 'function': /[a-z0-9_]+(?=\()/i,
|
6473 | 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
|
6474 | 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
|
6475 | 'punctuation': /[{}[\];(),.:]/
|
6476 | };
|
6477 |
|
6478 |
|
6479 | /* **********************************************
|
6480 | Begin prism-javascript.js
|
6481 | ********************************************** */
|
6482 |
|
6483 | Prism.languages.javascript = Prism.languages.extend('clike', {
|
6484 | '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/,
|
6485 | 'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
|
6486 | // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
6487 | 'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i,
|
6488 | 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*\*?|\/|~|\^|%|\.{3}/
|
6489 | });
|
6490 |
|
6491 | Prism.languages.insertBefore('javascript', 'keyword', {
|
6492 | 'regex': {
|
6493 | pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
|
6494 | lookbehind: true,
|
6495 | greedy: true
|
6496 | }
|
6497 | });
|
6498 |
|
6499 | Prism.languages.insertBefore('javascript', 'string', {
|
6500 | 'template-string': {
|
6501 | pattern: /`(?:\\\\|\\?[^\\])*?`/,
|
6502 | greedy: true,
|
6503 | inside: {
|
6504 | 'interpolation': {
|
6505 | pattern: /\$\{[^}]+\}/,
|
6506 | inside: {
|
6507 | 'interpolation-punctuation': {
|
6508 | pattern: /^\$\{|\}$/,
|
6509 | alias: 'punctuation'
|
6510 | },
|
6511 | rest: Prism.languages.javascript
|
6512 | }
|
6513 | },
|
6514 | 'string': /[\s\S]+/
|
6515 | }
|
6516 | }
|
6517 | });
|
6518 |
|
6519 | if (Prism.languages.markup) {
|
6520 | Prism.languages.insertBefore('markup', 'tag', {
|
6521 | 'script': {
|
6522 | pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
|
6523 | lookbehind: true,
|
6524 | inside: Prism.languages.javascript,
|
6525 | alias: 'language-javascript'
|
6526 | }
|
6527 | });
|
6528 | }
|
6529 |
|
6530 | Prism.languages.js = Prism.languages.javascript;
|
6531 |
|
6532 | /* **********************************************
|
6533 | Begin prism-file-highlight.js
|
6534 | ********************************************** */
|
6535 |
|
6536 | (function () {
|
6537 | if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) {
|
6538 | return;
|
6539 | }
|
6540 |
|
6541 | self.Prism.fileHighlight = function() {
|
6542 |
|
6543 | var Extensions = {
|
6544 | 'js': 'javascript',
|
6545 | 'py': 'python',
|
6546 | 'rb': 'ruby',
|
6547 | 'ps1': 'powershell',
|
6548 | 'psm1': 'powershell',
|
6549 | 'sh': 'bash',
|
6550 | 'bat': 'batch',
|
6551 | 'h': 'c',
|
6552 | 'tex': 'latex'
|
6553 | };
|
6554 |
|
6555 | if(Array.prototype.forEach) { // Check to prevent error in IE8
|
6556 | Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function (pre) {
|
6557 | var src = pre.getAttribute('data-src');
|
6558 |
|
6559 | var language, parent = pre;
|
6560 | var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
|
6561 | while (parent && !lang.test(parent.className)) {
|
6562 | parent = parent.parentNode;
|
6563 | }
|
6564 |
|
6565 | if (parent) {
|
6566 | language = (pre.className.match(lang) || [, ''])[1];
|
6567 | }
|
6568 |
|
6569 | if (!language) {
|
6570 | var extension = (src.match(/\.(\w+)$/) || [, ''])[1];
|
6571 | language = Extensions[extension] || extension;
|
6572 | }
|
6573 |
|
6574 | var code = document.createElement('code');
|
6575 | code.className = 'language-' + language;
|
6576 |
|
6577 | pre.textContent = '';
|
6578 |
|
6579 | code.textContent = 'Loading…';
|
6580 |
|
6581 | pre.appendChild(code);
|
6582 |
|
6583 | var xhr = new XMLHttpRequest();
|
6584 |
|
6585 | xhr.open('GET', src, true);
|
6586 |
|
6587 | xhr.onreadystatechange = function () {
|
6588 | if (xhr.readyState == 4) {
|
6589 |
|
6590 | if (xhr.status < 400 && xhr.responseText) {
|
6591 | code.textContent = xhr.responseText;
|
6592 |
|
6593 | Prism.highlightElement(code);
|
6594 | }
|
6595 | else if (xhr.status >= 400) {
|
6596 | code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
|
6597 | }
|
6598 | else {
|
6599 | code.textContent = '✖ Error: File does not exist or is empty';
|
6600 | }
|
6601 | }
|
6602 | };
|
6603 |
|
6604 | xhr.send(null);
|
6605 | });
|
6606 | }
|
6607 |
|
6608 | };
|
6609 |
|
6610 | document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight);
|
6611 |
|
6612 | })();
|
6613 | });
|
6614 |
|
6615 | var code$1 = function(dom, data) {
|
6616 | var codeElements = [].slice.call(dom.querySelectorAll("dt-code"));
|
6617 | codeElements.forEach(function (el) {
|
6618 | var content = el.textContent;
|
6619 | el.innerHTML = "";
|
6620 | var language = el.getAttribute("language");
|
6621 | var c = dom.createElement("code");
|
6622 | if (el.getAttribute("block") === "") {
|
6623 | // Let's normalize the tab indents
|
6624 | content = content.replace(/\n/, "");
|
6625 | var tabs = content.match(/\s*/);
|
6626 | content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
|
6627 | content = content.trim();
|
6628 | var p = dom.createElement("pre");
|
6629 | p.appendChild(c);
|
6630 | el.appendChild(p);
|
6631 | } else {
|
6632 | el.appendChild(c);
|
6633 | }
|
6634 | var highlighted = content;
|
6635 | if (prism.languages[language]) {
|
6636 | c.setAttribute("class", "language-" + language);
|
6637 | highlighted = prism.highlight(content, prism.languages[language]);
|
6638 | }
|
6639 | c.innerHTML = highlighted;
|
6640 | });
|
6641 | };
|
6642 |
|
6643 | //import xml from "xml";
|
6644 |
|
6645 | var generateCrossref = function(data) {
|
6646 |
|
6647 | if (data.published == undefined) {
|
6648 | //console.warn("Can't generate XML for post ", data.title, "with data", data);
|
6649 | //return "";
|
6650 | data.published = new Date("invalid");
|
6651 | }
|
6652 |
|
6653 | var date = data.published;
|
6654 | var batch_timestamp = Math.floor(Date.now() / 1000);
|
6655 | var batch_id = data.authors[0].lastName.split(" ")[0].toLowerCase().slice(0,20);
|
6656 | batch_id += "_" + date.getFullYear();
|
6657 | batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp;
|
6658 | // generate XML
|
6659 | var crf_data =
|
6660 | {doi_batch : [
|
6661 |
|
6662 | { _attr: {
|
6663 | version: "4.3.7",
|
6664 | xmlns: "http://www.crossref.org/schema/4.3.7",
|
6665 | "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
|
6666 | "xsi:schemaLocation": "http://www.crossref.org/schema/4.3.7 http://www.crossref.org/schemas/crossref4.3.7.xsd",
|
6667 | }},
|
6668 |
|
6669 | { head: [
|
6670 | {doi_batch_id: batch_id},
|
6671 | {timestamp: batch_timestamp},
|
6672 | {depositor: [
|
6673 | {depositor_name: "Distill Admin"},
|
6674 | {email_address: "admin@distill.pub"} ]},
|
6675 | {registrant: "Distill"} ]},
|
6676 |
|
6677 | {body: [
|
6678 | {journal: [
|
6679 |
|
6680 | {journal_metadata: [
|
6681 | {full_title: data.journal.full_title || data.journal.title},
|
6682 | {abbrev_title: data.journal.abbrev_title || data.journal.title || data.journal.full_title},
|
6683 | {doi_data: [
|
6684 | {doi: data.journal.doi},
|
6685 | {resource: data.journal.url} ]} ]},
|
6686 |
|
6687 | {journal_issue: [
|
6688 | {publication_date: [
|
6689 | {month: date.getMonth()+1},
|
6690 | {year: date.getFullYear()} ]},
|
6691 | {journal_volume: [
|
6692 | {volume: data.volume} ]},
|
6693 | {issue: data.issue} ]},
|
6694 |
|
6695 | {journal_article: [
|
6696 | {titles: [
|
6697 | {title: data.title} ]},
|
6698 | { contributors:
|
6699 | data.authors.map(function (author, ind) { return (
|
6700 | {person_name: [
|
6701 | { _attr: {
|
6702 | contributor_role: "author",
|
6703 | sequence: (ind == 0)? "first" : "additional"
|
6704 | }},
|
6705 | {given_name: author.firstName},
|
6706 | {surname: author.lastName},
|
6707 | {affiliation: author.affiliation}
|
6708 | // TODO: ORCID?
|
6709 | ]}
|
6710 | ); })
|
6711 | },
|
6712 | {publication_date: [
|
6713 | {month: date.getMonth()+1},
|
6714 | {day: date.getDate()},
|
6715 | {year: date.getFullYear()}
|
6716 | ]},
|
6717 | { publisher_item: [
|
6718 | {item_number: data.doi}
|
6719 | ]},
|
6720 | {doi_data: [
|
6721 | {doi: data.doi},
|
6722 | //{timestamp: ""},
|
6723 | {resource: data.url} ]},
|
6724 | {citation_list:
|
6725 | data.citations.map(function (key) { return citation_xml(key, data.bibliography[key]); })
|
6726 | }
|
6727 |
|
6728 | ]} ]} ]} ]};
|
6729 |
|
6730 | return xml(crf_data);
|
6731 | };
|
6732 |
|
6733 | function citation_xml(key, ent){
|
6734 | if (ent == undefined) { return {}; }
|
6735 | var info = [];
|
6736 | info.push({_attr: {key: key}});
|
6737 | if ("title" in ent)
|
6738 | { info.push({article_title: ent.title}); }
|
6739 | if ("author" in ent)
|
6740 | { info.push({author: ent.author.split(" and ")[0].split(",")[0].trim()}); }
|
6741 | if ("journal" in ent)
|
6742 | { info.push({journal_title: ent.journal}); }
|
6743 | if ("booktitle" in ent)
|
6744 | { info.push({volume_title: ent.booktitle}); }
|
6745 | if ("volume" in ent)
|
6746 | { info.push({volume: ent.volume}); }
|
6747 | if ("issue" in ent)
|
6748 | { info.push({issue: ent.issue}); }
|
6749 | if ("doi" in ent)
|
6750 | { info.push({doi: ent.doi}); }
|
6751 | return {citation: info}
|
6752 | }
|
6753 |
|
6754 | function xml(obj) {
|
6755 | //console.log(typeof(obj), obj)
|
6756 | if (typeof obj === 'string') { return obj; }
|
6757 | if (typeof obj === 'number') { return ""+obj; }
|
6758 | var keys = Object.keys(obj);
|
6759 | if (keys.length != 1) { console.error("can't interpret ", obj, "as xml"); }
|
6760 | var name = keys[0];
|
6761 | var full_content = obj[name];
|
6762 | var attr = {};
|
6763 | if (Array.isArray(full_content)){
|
6764 | var content = [];
|
6765 | for (var i in full_content) {
|
6766 | var obj = full_content[i];
|
6767 | var obj_name = Object.keys(obj)[0];
|
6768 | if ("_attr" == obj_name) {
|
6769 | attr = obj["_attr"];
|
6770 | } else {
|
6771 | //console.log(Object.keys(obj)[0])
|
6772 | content.push(obj);
|
6773 | }
|
6774 | }
|
6775 | } else {
|
6776 | content = full_content;
|
6777 | }
|
6778 | if (content == undefined){
|
6779 | content = "undefined";
|
6780 | }
|
6781 |
|
6782 | var attr_string = "";
|
6783 | for (var k in attr) {
|
6784 | attr_string += " " + k + "=\"" + (attr[k]) + "\"";
|
6785 | }
|
6786 |
|
6787 | //console.log(typeof content, Array.isArray(content), content instanceof String, content)
|
6788 | if (Array.isArray(content)){
|
6789 | content = content.map(xml);
|
6790 | content = content.join("\n").split("\n");
|
6791 | content = content.map(function (s) { return " " + s; }).join("\n");
|
6792 | var result = "<" + name + attr_string + ">\n" + content + "\n</" + name + ">";
|
6793 | } else {
|
6794 | content = xml(content);
|
6795 | var result = "<" + name + attr_string + ">" + content + "</" + name + ">";
|
6796 | }
|
6797 | return result;
|
6798 | }
|
6799 |
|
6800 | function renderImmediately(dom) {
|
6801 | html(dom);
|
6802 | styles(dom);
|
6803 | }
|
6804 |
|
6805 | function renderOnLoad(dom, data) {
|
6806 | frontMatter(dom, data);
|
6807 | bibliography(dom, data);
|
6808 | expandData(dom, data);
|
6809 | meta(dom, data);
|
6810 | header(dom, data);
|
6811 | appendix(dom, data);
|
6812 | footer(dom, data);
|
6813 | markdown(dom, data);
|
6814 | code$1(dom, data);
|
6815 | citation(dom, data);
|
6816 | }
|
6817 |
|
6818 | // If we are in a browser, render automatically.
|
6819 | if(window && window.document) {
|
6820 | var data = data || {};
|
6821 | renderImmediately(window.document);
|
6822 | window.document.addEventListener("DOMContentLoaded", function (event) {
|
6823 | renderOnLoad(window.document, data);
|
6824 | console.log("final data:");
|
6825 | for (var k in data) {console.log(" ", k, ": ", data[k]);}
|
6826 | });
|
6827 | }
|
6828 |
|
6829 | // For node
|
6830 | function render(dom, data) {
|
6831 | renderImmediately(dom);
|
6832 | renderOnLoad(dom, data);
|
6833 | }
|
6834 |
|
6835 | exports.render = render;
|
6836 | exports.html = html;
|
6837 | exports.styles = styles;
|
6838 | exports.frontMatter = frontMatter;
|
6839 | exports.bibliography = bibliography;
|
6840 | exports.meta = meta;
|
6841 | exports.header = header;
|
6842 | exports.appendix = appendix;
|
6843 | exports.footer = footer;
|
6844 | exports.citation = citation;
|
6845 | exports.markdown = markdown;
|
6846 | exports.code = code$1;
|
6847 | exports.generateCrossref = generateCrossref;
|
6848 |
|
6849 | Object.defineProperty(exports, '__esModule', { value: true });
|
6850 |
|
6851 | })));
|
6852 | //# sourceMappingURL=template.js.map
|