mirror of
https://github.com/wassname/template.git
synced 2026-06-29 03:05:28 +08:00
8487 lines
246 KiB
JavaScript
8487 lines
246 KiB
JavaScript
(function (global, factory) {
|
||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||
(factory((global.dl = global.dl || {})));
|
||
}(this, (function (exports) { 'use strict';
|
||
|
||
var html = function(dom) {
|
||
if (!dom.querySelector("html").getAttribute("lang")) {
|
||
dom.querySelector("html").setAttribute("lang", "en");
|
||
}
|
||
|
||
var head = dom.querySelector("head");
|
||
|
||
if (!dom.querySelector("meta[charset]")) {
|
||
var meta = dom.createElement("meta");
|
||
meta.setAttribute("charset", "utf-8");
|
||
head.appendChild(meta);
|
||
}
|
||
if (!dom.querySelector("meta[name=viewport]")) {
|
||
var meta$1 = dom.createElement("meta");
|
||
meta$1.setAttribute("name", "viewport");
|
||
meta$1.setAttribute("content", "width=device-width, initial-scale=1");
|
||
head.appendChild(meta$1);
|
||
}
|
||
};
|
||
|
||
var base = "html {\n font: 400 15px/1.55em -apple-system, BlinkMacSystemFont, \"Roboto\", sans-serif;\n background-color: hsl(223, 9%, 25%);\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 background: white;\n}\n\na {\n color: #004276;\n}\n\nfigure {\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";
|
||
|
||
var layout = ".l-body,\n.l-body-outset,\n.l-page,\n.l-page-outset,\n.l-middle,\n.l-middle-outset,\ndt-article > div,\ndt-article > p,\ndt-article > h1,\ndt-article > h2,\ndt-article > h3,\ndt-article > h4,\ndt-article > figure,\ndt-article > ul,\ndt-article > dt-byline {\n width: auto;\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-body-outset,\n .l-page,\n .l-page-outset,\n .l-middle,\n .l-middle-outset,\n dt-article > div,\n dt-article > p,\n dt-article > h1,\n dt-article > h2,\n dt-article > h3,\n dt-article > h4,\n dt-article > figure,\n dt-article > ul,\n dt-article > dt-byline {\n margin-left: 72px;\n margin-right: 72px;\n }\n}\n\n@media(min-width: 1080px) {\n .l-body,\n dt-article > div,\n dt-article > p,\n dt-article > h1,\n dt-article > h2,\n dt-article > h3,\n dt-article > h4,\n dt-article > figure,\n dt-article > ul,\n dt-article > dt-byline {\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 - 96px/2);\n width: calc(648px + 96px);\n }\n .l-middle,\n dt-article .l-middle {\n width: 816px;\n margin-left: calc(50% - 984px / 2);\n margin-right: auto;\n }\n .l-page,\n dt-article .l-page,\n dt-article.centered .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 dt-article.centered .l-page-outset {\n width: 1080px;\n margin-left: auto;\n margin-right: auto;\n }\n .l-screen,\n dt-article .l-screen,\n dt-article.centered .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 dt-article.centered .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 - 984px) / 2);\n width: calc((984px - 648px) - 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\n /* Centered */\n\n .centered .l-body,\n .centered.l-body,\n dt-article.centered > div,\n dt-article.centered > p,\n dt-article.centered > h1,\n dt-article.centered > h2,\n dt-article.centered > h3,\n dt-article.centered > h4,\n dt-article.centered > figure,\n dt-article.centered > ul,\n dt-article.centered > dt-byline {\n margin-left: auto;\n margin-right: auto;\n width: 648px;\n }\n .centered .l-body-outset,\n .centered.l-body-outset,\n dt-article.centered .l-body-outset {\n margin-left: auto;\n margin-right: auto;\n width: calc(648px + 96px);\n }\n .centered .l-middle,\n .centered.l-middle,\n dt-article.centered .l-middle {\n width: 816px;\n margin-left: auto;\n margin-right: auto;\n }\n\n /* page and screen are already centered */\n\n .centered .l-gutter,\n .centered.l-gutter,\n dt-article.centered .l-gutter {\n clear: both;\n float: right;\n margin-top: 0;\n margin-left: 24px;\n margin-right: calc((100vw - 984px) / 2);\n width: calc((984px - 648px) / 2 - 24px);\n }\n /* Side */\n .centered .side.l-body,\n .centered.side.l-body,\n dt-article.centered .side.l-body {\n clear: both;\n float: right;\n margin-top: 0;\n margin-left: 48px;\n margin-right: calc((100vw - 984px) / 2);\n width: calc(648px / 2 - 24px);\n }\n}\n";
|
||
|
||
var article = "dt-article {\n display: block;\n color: rgba(0, 0, 0, 0.8);\n font: 15px/1.55em -apple-system, BlinkMacSystemFont, \"Roboto\", sans-serif;\n margin-bottom: 72px;\n overflow: hidden;\n}\n\n@media(min-width: 1024px) {\n dt-article {\n font-size: 20px;\n }\n}\n\n/* H1 */\n\ndt-article h1 {\n margin-top: 48px;\n font-weight: 400;\n font-size: 32px;\n line-height: 1.1em;\n -webkit-font-smoothing: antialiased;\n font-family: Georgia, serif;\n}\n\n\n@media(min-width: 1080px) {\n dt-article.centered h1 {\n text-align: center;\n }\n\n dt-article h1 {\n font-size: 48px;\n margin-bottom: 12px;\n letter-spacing: -0.02em;\n }\n\n dt-article > h1:first-of-type {\n margin-top: 80px;\n }\n}\n\n\n@media(min-width: 1200px) {\n dt-article h1 {\n font-size: 52px;\n }\n\n dt-article > h1:first-of-type {\n margin-top: 100px;\n }\n}\n\n/* H2 */\n\ndt-article h2 {\n font-weight: 700;\n font-size: 22px;\n line-height: 1.25em;\n margin-top: 12px;\n margin-bottom: 24px;\n}\n\n@media(min-width: 1024px) {\n dt-article h2 {\n font-size: 24px;\n }\n}\n\ndt-article h1 + h2 {\n font-family: Georgia, serif;\n font-weight: normal;\n font-size: 18px;\n line-height: 1.5em;\n margin-top: 8px;\n}\n\n\n@media(min-width: 1024px) {\n dt-article.centered h1 + h2 {\n text-align: center;\n }\n dt-article h1 + h2 {\n margin-top: 12px;\n font-size: 22px;\n }\n}\n\n/* H3 */\n\ndt-article h3 {\n font-weight: 700;\n font-size: 13px;\n line-height: 1.4em;\n margin-top: 36px;\n margin-bottom: 18px;\n text-transform: uppercase;\n letter-spacing: -0.03em;\n}\n\n@media(min-width: 1024px) {\n dt-article h3 {\n font-size: 16px;\n }\n}\n\n/* H4 */\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 border-bottom: 1px solid rgba(0, 0, 0, 0.4);\n text-decoration: none;\n}\n\ndt-article p a:hover {\n border-bottom: 1px solid rgba(0, 0, 0, 0.8);\n}\n\ndt-article p .link {\n text-decoration: underline;\n cursor: pointer;\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\ndt-article .citation {\n color: #668;\n cursor: pointer;\n}\n\ndt-include {\n width: auto;\n display: block;\n}\n";
|
||
|
||
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";
|
||
|
||
var styles = function(dom) {
|
||
var s = dom.createElement("style");
|
||
s.textContent = base + layout + article + code;
|
||
dom.querySelector("head").appendChild(s);
|
||
};
|
||
|
||
function isNothing(subject) {
|
||
return (typeof subject === 'undefined') || (subject === null);
|
||
}
|
||
|
||
|
||
function isObject(subject) {
|
||
return (typeof subject === 'object') && (subject !== null);
|
||
}
|
||
|
||
|
||
function toArray(sequence) {
|
||
if (Array.isArray(sequence)) { return sequence; }
|
||
else if (isNothing(sequence)) { return []; }
|
||
|
||
return [ sequence ];
|
||
}
|
||
|
||
|
||
function extend(target, source) {
|
||
var index, length, key, sourceKeys;
|
||
|
||
if (source) {
|
||
sourceKeys = Object.keys(source);
|
||
|
||
for (index = 0, length = sourceKeys.length; index < length; index += 1) {
|
||
key = sourceKeys[index];
|
||
target[key] = source[key];
|
||
}
|
||
}
|
||
|
||
return target;
|
||
}
|
||
|
||
|
||
function repeat(string, count) {
|
||
var result = '', cycle;
|
||
|
||
for (cycle = 0; cycle < count; cycle += 1) {
|
||
result += string;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
|
||
function isNegativeZero(number) {
|
||
return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
|
||
}
|
||
|
||
|
||
var isNothing_1 = isNothing;
|
||
var isObject_1 = isObject;
|
||
var toArray_1 = toArray;
|
||
var repeat_1 = repeat;
|
||
var isNegativeZero_1 = isNegativeZero;
|
||
var extend_1 = extend;
|
||
|
||
var common$1 = {
|
||
isNothing: isNothing_1,
|
||
isObject: isObject_1,
|
||
toArray: toArray_1,
|
||
repeat: repeat_1,
|
||
isNegativeZero: isNegativeZero_1,
|
||
extend: extend_1
|
||
};
|
||
|
||
// YAML error class. http://stackoverflow.com/questions/8458984
|
||
//
|
||
function YAMLException$2(reason, mark) {
|
||
// Super constructor
|
||
Error.call(this);
|
||
|
||
// Include stack trace in error object
|
||
if (Error.captureStackTrace) {
|
||
// Chrome and NodeJS
|
||
Error.captureStackTrace(this, this.constructor);
|
||
} else {
|
||
// FF, IE 10+ and Safari 6+. Fallback for others
|
||
this.stack = (new Error()).stack || '';
|
||
}
|
||
|
||
this.name = 'YAMLException';
|
||
this.reason = reason;
|
||
this.mark = mark;
|
||
this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
|
||
}
|
||
|
||
|
||
// Inherit from Error
|
||
YAMLException$2.prototype = Object.create(Error.prototype);
|
||
YAMLException$2.prototype.constructor = YAMLException$2;
|
||
|
||
|
||
YAMLException$2.prototype.toString = function toString(compact) {
|
||
var result = this.name + ': ';
|
||
|
||
result += this.reason || '(unknown reason)';
|
||
|
||
if (!compact && this.mark) {
|
||
result += ' ' + this.mark.toString();
|
||
}
|
||
|
||
return result;
|
||
};
|
||
|
||
|
||
var exception = YAMLException$2;
|
||
|
||
var common$3 = common$1;
|
||
|
||
|
||
function Mark$1(name, buffer, position, line, column) {
|
||
this.name = name;
|
||
this.buffer = buffer;
|
||
this.position = position;
|
||
this.line = line;
|
||
this.column = column;
|
||
}
|
||
|
||
|
||
Mark$1.prototype.getSnippet = function getSnippet(indent, maxLength) {
|
||
var this$1 = this;
|
||
|
||
var head, start, tail, end, snippet;
|
||
|
||
if (!this.buffer) { return null; }
|
||
|
||
indent = indent || 4;
|
||
maxLength = maxLength || 75;
|
||
|
||
head = '';
|
||
start = this.position;
|
||
|
||
while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
|
||
start -= 1;
|
||
if (this$1.position - start > (maxLength / 2 - 1)) {
|
||
head = ' ... ';
|
||
start += 5;
|
||
break;
|
||
}
|
||
}
|
||
|
||
tail = '';
|
||
end = this.position;
|
||
|
||
while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
|
||
end += 1;
|
||
if (end - this$1.position > (maxLength / 2 - 1)) {
|
||
tail = ' ... ';
|
||
end -= 5;
|
||
break;
|
||
}
|
||
}
|
||
|
||
snippet = this.buffer.slice(start, end);
|
||
|
||
return common$3.repeat(' ', indent) + head + snippet + tail + '\n' +
|
||
common$3.repeat(' ', indent + this.position - start + head.length) + '^';
|
||
};
|
||
|
||
|
||
Mark$1.prototype.toString = function toString(compact) {
|
||
var snippet, where = '';
|
||
|
||
if (this.name) {
|
||
where += 'in "' + this.name + '" ';
|
||
}
|
||
|
||
where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
|
||
|
||
if (!compact) {
|
||
snippet = this.getSnippet();
|
||
|
||
if (snippet) {
|
||
where += ':\n' + snippet;
|
||
}
|
||
}
|
||
|
||
return where;
|
||
};
|
||
|
||
|
||
var mark = Mark$1;
|
||
|
||
var YAMLException$4 = exception;
|
||
|
||
var TYPE_CONSTRUCTOR_OPTIONS = [
|
||
'kind',
|
||
'resolve',
|
||
'construct',
|
||
'instanceOf',
|
||
'predicate',
|
||
'represent',
|
||
'defaultStyle',
|
||
'styleAliases'
|
||
];
|
||
|
||
var YAML_NODE_KINDS = [
|
||
'scalar',
|
||
'sequence',
|
||
'mapping'
|
||
];
|
||
|
||
function compileStyleAliases(map) {
|
||
var result = {};
|
||
|
||
if (map !== null) {
|
||
Object.keys(map).forEach(function (style) {
|
||
map[style].forEach(function (alias) {
|
||
result[String(alias)] = style;
|
||
});
|
||
});
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
function Type$2(tag, options) {
|
||
options = options || {};
|
||
|
||
Object.keys(options).forEach(function (name) {
|
||
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
||
throw new YAMLException$4('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
||
}
|
||
});
|
||
|
||
// TODO: Add tag format check.
|
||
this.tag = tag;
|
||
this.kind = options['kind'] || null;
|
||
this.resolve = options['resolve'] || function () { return true; };
|
||
this.construct = options['construct'] || function (data) { return data; };
|
||
this.instanceOf = options['instanceOf'] || null;
|
||
this.predicate = options['predicate'] || null;
|
||
this.represent = options['represent'] || null;
|
||
this.defaultStyle = options['defaultStyle'] || null;
|
||
this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
|
||
|
||
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
||
throw new YAMLException$4('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
||
}
|
||
}
|
||
|
||
var type = Type$2;
|
||
|
||
var common$4 = common$1;
|
||
var YAMLException$3 = exception;
|
||
var Type$1 = type;
|
||
|
||
|
||
function compileList(schema, name, result) {
|
||
var exclude = [];
|
||
|
||
schema.include.forEach(function (includedSchema) {
|
||
result = compileList(includedSchema, name, result);
|
||
});
|
||
|
||
schema[name].forEach(function (currentType) {
|
||
result.forEach(function (previousType, previousIndex) {
|
||
if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
|
||
exclude.push(previousIndex);
|
||
}
|
||
});
|
||
|
||
result.push(currentType);
|
||
});
|
||
|
||
return result.filter(function (type$$1, index) {
|
||
return exclude.indexOf(index) === -1;
|
||
});
|
||
}
|
||
|
||
|
||
function compileMap(/* lists... */) {
|
||
var arguments$1 = arguments;
|
||
|
||
var result = {
|
||
scalar: {},
|
||
sequence: {},
|
||
mapping: {},
|
||
fallback: {}
|
||
}, index, length;
|
||
|
||
function collectType(type$$1) {
|
||
result[type$$1.kind][type$$1.tag] = result['fallback'][type$$1.tag] = type$$1;
|
||
}
|
||
|
||
for (index = 0, length = arguments.length; index < length; index += 1) {
|
||
arguments$1[index].forEach(collectType);
|
||
}
|
||
return result;
|
||
}
|
||
|
||
|
||
function Schema$2(definition) {
|
||
this.include = definition.include || [];
|
||
this.implicit = definition.implicit || [];
|
||
this.explicit = definition.explicit || [];
|
||
|
||
this.implicit.forEach(function (type$$1) {
|
||
if (type$$1.loadKind && type$$1.loadKind !== 'scalar') {
|
||
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.');
|
||
}
|
||
});
|
||
|
||
this.compiledImplicit = compileList(this, 'implicit', []);
|
||
this.compiledExplicit = compileList(this, 'explicit', []);
|
||
this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
|
||
}
|
||
|
||
|
||
Schema$2.DEFAULT = null;
|
||
|
||
|
||
Schema$2.create = function createSchema() {
|
||
var schemas, types;
|
||
|
||
switch (arguments.length) {
|
||
case 1:
|
||
schemas = Schema$2.DEFAULT;
|
||
types = arguments[0];
|
||
break;
|
||
|
||
case 2:
|
||
schemas = arguments[0];
|
||
types = arguments[1];
|
||
break;
|
||
|
||
default:
|
||
throw new YAMLException$3('Wrong number of arguments for Schema.create function');
|
||
}
|
||
|
||
schemas = common$4.toArray(schemas);
|
||
types = common$4.toArray(types);
|
||
|
||
if (!schemas.every(function (schema) { return schema instanceof Schema$2; })) {
|
||
throw new YAMLException$3('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
|
||
}
|
||
|
||
if (!types.every(function (type$$1) { return type$$1 instanceof Type$1; })) {
|
||
throw new YAMLException$3('Specified list of YAML types (or a single Type object) contains a non-Type object.');
|
||
}
|
||
|
||
return new Schema$2({
|
||
include: schemas,
|
||
explicit: types
|
||
});
|
||
};
|
||
|
||
|
||
var schema = Schema$2;
|
||
|
||
var Type$3 = type;
|
||
|
||
var str = new Type$3('tag:yaml.org,2002:str', {
|
||
kind: 'scalar',
|
||
construct: function (data) { return data !== null ? data : ''; }
|
||
});
|
||
|
||
var Type$4 = type;
|
||
|
||
var seq = new Type$4('tag:yaml.org,2002:seq', {
|
||
kind: 'sequence',
|
||
construct: function (data) { return data !== null ? data : []; }
|
||
});
|
||
|
||
var Type$5 = type;
|
||
|
||
var map = new Type$5('tag:yaml.org,2002:map', {
|
||
kind: 'mapping',
|
||
construct: function (data) { return data !== null ? data : {}; }
|
||
});
|
||
|
||
var Schema$5 = schema;
|
||
|
||
|
||
var failsafe = new Schema$5({
|
||
explicit: [
|
||
str,
|
||
seq,
|
||
map
|
||
]
|
||
});
|
||
|
||
var Type$6 = type;
|
||
|
||
function resolveYamlNull(data) {
|
||
if (data === null) { return true; }
|
||
|
||
var max = data.length;
|
||
|
||
return (max === 1 && data === '~') ||
|
||
(max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
|
||
}
|
||
|
||
function constructYamlNull() {
|
||
return null;
|
||
}
|
||
|
||
function isNull(object) {
|
||
return object === null;
|
||
}
|
||
|
||
var _null = new Type$6('tag:yaml.org,2002:null', {
|
||
kind: 'scalar',
|
||
resolve: resolveYamlNull,
|
||
construct: constructYamlNull,
|
||
predicate: isNull,
|
||
represent: {
|
||
canonical: function () { return '~'; },
|
||
lowercase: function () { return 'null'; },
|
||
uppercase: function () { return 'NULL'; },
|
||
camelcase: function () { return 'Null'; }
|
||
},
|
||
defaultStyle: 'lowercase'
|
||
});
|
||
|
||
var Type$7 = type;
|
||
|
||
function resolveYamlBoolean(data) {
|
||
if (data === null) { return false; }
|
||
|
||
var max = data.length;
|
||
|
||
return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
|
||
(max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
|
||
}
|
||
|
||
function constructYamlBoolean(data) {
|
||
return data === 'true' ||
|
||
data === 'True' ||
|
||
data === 'TRUE';
|
||
}
|
||
|
||
function isBoolean(object) {
|
||
return Object.prototype.toString.call(object) === '[object Boolean]';
|
||
}
|
||
|
||
var bool = new Type$7('tag:yaml.org,2002:bool', {
|
||
kind: 'scalar',
|
||
resolve: resolveYamlBoolean,
|
||
construct: constructYamlBoolean,
|
||
predicate: isBoolean,
|
||
represent: {
|
||
lowercase: function (object) { return object ? 'true' : 'false'; },
|
||
uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
|
||
camelcase: function (object) { return object ? 'True' : 'False'; }
|
||
},
|
||
defaultStyle: 'lowercase'
|
||
});
|
||
|
||
var common$5 = common$1;
|
||
var Type$8 = type;
|
||
|
||
function isHexCode(c) {
|
||
return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
|
||
((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
|
||
((0x61/* a */ <= c) && (c <= 0x66/* f */));
|
||
}
|
||
|
||
function isOctCode(c) {
|
||
return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
|
||
}
|
||
|
||
function isDecCode(c) {
|
||
return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
|
||
}
|
||
|
||
function resolveYamlInteger(data) {
|
||
if (data === null) { return false; }
|
||
|
||
var max = data.length,
|
||
index = 0,
|
||
hasDigits = false,
|
||
ch;
|
||
|
||
if (!max) { return false; }
|
||
|
||
ch = data[index];
|
||
|
||
// sign
|
||
if (ch === '-' || ch === '+') {
|
||
ch = data[++index];
|
||
}
|
||
|
||
if (ch === '0') {
|
||
// 0
|
||
if (index + 1 === max) { return true; }
|
||
ch = data[++index];
|
||
|
||
// base 2, base 8, base 16
|
||
|
||
if (ch === 'b') {
|
||
// base 2
|
||
index++;
|
||
|
||
for (; index < max; index++) {
|
||
ch = data[index];
|
||
if (ch === '_') { continue; }
|
||
if (ch !== '0' && ch !== '1') { return false; }
|
||
hasDigits = true;
|
||
}
|
||
return hasDigits;
|
||
}
|
||
|
||
|
||
if (ch === 'x') {
|
||
// base 16
|
||
index++;
|
||
|
||
for (; index < max; index++) {
|
||
ch = data[index];
|
||
if (ch === '_') { continue; }
|
||
if (!isHexCode(data.charCodeAt(index))) { return false; }
|
||
hasDigits = true;
|
||
}
|
||
return hasDigits;
|
||
}
|
||
|
||
// base 8
|
||
for (; index < max; index++) {
|
||
ch = data[index];
|
||
if (ch === '_') { continue; }
|
||
if (!isOctCode(data.charCodeAt(index))) { return false; }
|
||
hasDigits = true;
|
||
}
|
||
return hasDigits;
|
||
}
|
||
|
||
// base 10 (except 0) or base 60
|
||
|
||
for (; index < max; index++) {
|
||
ch = data[index];
|
||
if (ch === '_') { continue; }
|
||
if (ch === ':') { break; }
|
||
if (!isDecCode(data.charCodeAt(index))) {
|
||
return false;
|
||
}
|
||
hasDigits = true;
|
||
}
|
||
|
||
if (!hasDigits) { return false; }
|
||
|
||
// if !base60 - done;
|
||
if (ch !== ':') { return true; }
|
||
|
||
// base60 almost not used, no needs to optimize
|
||
return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
|
||
}
|
||
|
||
function constructYamlInteger(data) {
|
||
var value = data, sign = 1, ch, base, digits = [];
|
||
|
||
if (value.indexOf('_') !== -1) {
|
||
value = value.replace(/_/g, '');
|
||
}
|
||
|
||
ch = value[0];
|
||
|
||
if (ch === '-' || ch === '+') {
|
||
if (ch === '-') { sign = -1; }
|
||
value = value.slice(1);
|
||
ch = value[0];
|
||
}
|
||
|
||
if (value === '0') { return 0; }
|
||
|
||
if (ch === '0') {
|
||
if (value[1] === 'b') { return sign * parseInt(value.slice(2), 2); }
|
||
if (value[1] === 'x') { return sign * parseInt(value, 16); }
|
||
return sign * parseInt(value, 8);
|
||
}
|
||
|
||
if (value.indexOf(':') !== -1) {
|
||
value.split(':').forEach(function (v) {
|
||
digits.unshift(parseInt(v, 10));
|
||
});
|
||
|
||
value = 0;
|
||
base = 1;
|
||
|
||
digits.forEach(function (d) {
|
||
value += (d * base);
|
||
base *= 60;
|
||
});
|
||
|
||
return sign * value;
|
||
|
||
}
|
||
|
||
return sign * parseInt(value, 10);
|
||
}
|
||
|
||
function isInteger(object) {
|
||
return (Object.prototype.toString.call(object)) === '[object Number]' &&
|
||
(object % 1 === 0 && !common$5.isNegativeZero(object));
|
||
}
|
||
|
||
var int_1 = new Type$8('tag:yaml.org,2002:int', {
|
||
kind: 'scalar',
|
||
resolve: resolveYamlInteger,
|
||
construct: constructYamlInteger,
|
||
predicate: isInteger,
|
||
represent: {
|
||
binary: function (object) { return '0b' + object.toString(2); },
|
||
octal: function (object) { return '0' + object.toString(8); },
|
||
decimal: function (object) { return object.toString(10); },
|
||
hexadecimal: function (object) { return '0x' + object.toString(16).toUpperCase(); }
|
||
},
|
||
defaultStyle: 'decimal',
|
||
styleAliases: {
|
||
binary: [ 2, 'bin' ],
|
||
octal: [ 8, 'oct' ],
|
||
decimal: [ 10, 'dec' ],
|
||
hexadecimal: [ 16, 'hex' ]
|
||
}
|
||
});
|
||
|
||
var common$6 = common$1;
|
||
var Type$9 = type;
|
||
|
||
var YAML_FLOAT_PATTERN = new RegExp(
|
||
'^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?' +
|
||
'|\\.[0-9_]+(?:[eE][-+][0-9]+)?' +
|
||
'|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
|
||
'|[-+]?\\.(?:inf|Inf|INF)' +
|
||
'|\\.(?:nan|NaN|NAN))$');
|
||
|
||
function resolveYamlFloat(data) {
|
||
if (data === null) { return false; }
|
||
|
||
if (!YAML_FLOAT_PATTERN.test(data)) { return false; }
|
||
|
||
return true;
|
||
}
|
||
|
||
function constructYamlFloat(data) {
|
||
var value, sign, base, digits;
|
||
|
||
value = data.replace(/_/g, '').toLowerCase();
|
||
sign = value[0] === '-' ? -1 : 1;
|
||
digits = [];
|
||
|
||
if ('+-'.indexOf(value[0]) >= 0) {
|
||
value = value.slice(1);
|
||
}
|
||
|
||
if (value === '.inf') {
|
||
return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
||
|
||
} else if (value === '.nan') {
|
||
return NaN;
|
||
|
||
} else if (value.indexOf(':') >= 0) {
|
||
value.split(':').forEach(function (v) {
|
||
digits.unshift(parseFloat(v, 10));
|
||
});
|
||
|
||
value = 0.0;
|
||
base = 1;
|
||
|
||
digits.forEach(function (d) {
|
||
value += d * base;
|
||
base *= 60;
|
||
});
|
||
|
||
return sign * value;
|
||
|
||
}
|
||
return sign * parseFloat(value, 10);
|
||
}
|
||
|
||
|
||
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
||
|
||
function representYamlFloat(object, style) {
|
||
var res;
|
||
|
||
if (isNaN(object)) {
|
||
switch (style) {
|
||
case 'lowercase': return '.nan';
|
||
case 'uppercase': return '.NAN';
|
||
case 'camelcase': return '.NaN';
|
||
}
|
||
} else if (Number.POSITIVE_INFINITY === object) {
|
||
switch (style) {
|
||
case 'lowercase': return '.inf';
|
||
case 'uppercase': return '.INF';
|
||
case 'camelcase': return '.Inf';
|
||
}
|
||
} else if (Number.NEGATIVE_INFINITY === object) {
|
||
switch (style) {
|
||
case 'lowercase': return '-.inf';
|
||
case 'uppercase': return '-.INF';
|
||
case 'camelcase': return '-.Inf';
|
||
}
|
||
} else if (common$6.isNegativeZero(object)) {
|
||
return '-0.0';
|
||
}
|
||
|
||
res = object.toString(10);
|
||
|
||
// JS stringifier can build scientific format without dots: 5e-100,
|
||
// while YAML requres dot: 5.e-100. Fix it with simple hack
|
||
|
||
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
|
||
}
|
||
|
||
function isFloat(object) {
|
||
return (Object.prototype.toString.call(object) === '[object Number]') &&
|
||
(object % 1 !== 0 || common$6.isNegativeZero(object));
|
||
}
|
||
|
||
var float_1 = new Type$9('tag:yaml.org,2002:float', {
|
||
kind: 'scalar',
|
||
resolve: resolveYamlFloat,
|
||
construct: constructYamlFloat,
|
||
predicate: isFloat,
|
||
represent: representYamlFloat,
|
||
defaultStyle: 'lowercase'
|
||
});
|
||
|
||
var Schema$4 = schema;
|
||
|
||
|
||
var json = new Schema$4({
|
||
include: [
|
||
failsafe
|
||
],
|
||
implicit: [
|
||
_null,
|
||
bool,
|
||
int_1,
|
||
float_1
|
||
]
|
||
});
|
||
|
||
var Schema$3 = schema;
|
||
|
||
|
||
var core = new Schema$3({
|
||
include: [
|
||
json
|
||
]
|
||
});
|
||
|
||
var Type$10 = type;
|
||
|
||
var YAML_DATE_REGEXP = new RegExp(
|
||
'^([0-9][0-9][0-9][0-9])' + // [1] year
|
||
'-([0-9][0-9])' + // [2] month
|
||
'-([0-9][0-9])$'); // [3] day
|
||
|
||
var YAML_TIMESTAMP_REGEXP = new RegExp(
|
||
'^([0-9][0-9][0-9][0-9])' + // [1] year
|
||
'-([0-9][0-9]?)' + // [2] month
|
||
'-([0-9][0-9]?)' + // [3] day
|
||
'(?:[Tt]|[ \\t]+)' + // ...
|
||
'([0-9][0-9]?)' + // [4] hour
|
||
':([0-9][0-9])' + // [5] minute
|
||
':([0-9][0-9])' + // [6] second
|
||
'(?:\\.([0-9]*))?' + // [7] fraction
|
||
'(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
|
||
'(?::([0-9][0-9]))?))?$'); // [11] tz_minute
|
||
|
||
function resolveYamlTimestamp(data) {
|
||
if (data === null) { return false; }
|
||
if (YAML_DATE_REGEXP.exec(data) !== null) { return true; }
|
||
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) { return true; }
|
||
return false;
|
||
}
|
||
|
||
function constructYamlTimestamp(data) {
|
||
var match, year, month, day, hour, minute, second, fraction = 0,
|
||
delta = null, tz_hour, tz_minute, date;
|
||
|
||
match = YAML_DATE_REGEXP.exec(data);
|
||
if (match === null) { match = YAML_TIMESTAMP_REGEXP.exec(data); }
|
||
|
||
if (match === null) { throw new Error('Date resolve error'); }
|
||
|
||
// match: [1] year [2] month [3] day
|
||
|
||
year = +(match[1]);
|
||
month = +(match[2]) - 1; // JS month starts with 0
|
||
day = +(match[3]);
|
||
|
||
if (!match[4]) { // no hour
|
||
return new Date(Date.UTC(year, month, day));
|
||
}
|
||
|
||
// match: [4] hour [5] minute [6] second [7] fraction
|
||
|
||
hour = +(match[4]);
|
||
minute = +(match[5]);
|
||
second = +(match[6]);
|
||
|
||
if (match[7]) {
|
||
fraction = match[7].slice(0, 3);
|
||
while (fraction.length < 3) { // milli-seconds
|
||
fraction += '0';
|
||
}
|
||
fraction = +fraction;
|
||
}
|
||
|
||
// match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
|
||
|
||
if (match[9]) {
|
||
tz_hour = +(match[10]);
|
||
tz_minute = +(match[11] || 0);
|
||
delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
|
||
if (match[9] === '-') { delta = -delta; }
|
||
}
|
||
|
||
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
||
|
||
if (delta) { date.setTime(date.getTime() - delta); }
|
||
|
||
return date;
|
||
}
|
||
|
||
function representYamlTimestamp(object /*, style*/) {
|
||
return object.toISOString();
|
||
}
|
||
|
||
var timestamp = new Type$10('tag:yaml.org,2002:timestamp', {
|
||
kind: 'scalar',
|
||
resolve: resolveYamlTimestamp,
|
||
construct: constructYamlTimestamp,
|
||
instanceOf: Date,
|
||
represent: representYamlTimestamp
|
||
});
|
||
|
||
var Type$11 = type;
|
||
|
||
function resolveYamlMerge(data) {
|
||
return data === '<<' || data === null;
|
||
}
|
||
|
||
var merge = new Type$11('tag:yaml.org,2002:merge', {
|
||
kind: 'scalar',
|
||
resolve: resolveYamlMerge
|
||
});
|
||
|
||
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
||
|
||
function commonjsRequire () {
|
||
throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
|
||
}
|
||
|
||
|
||
|
||
function createCommonjsModule(fn, module) {
|
||
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
||
}
|
||
|
||
var NodeBuffer;
|
||
|
||
try {
|
||
// A trick for browserified version, to not include `Buffer` shim
|
||
var _require = commonjsRequire;
|
||
NodeBuffer = _require('buffer').Buffer;
|
||
} catch (__) {}
|
||
|
||
var Type$12 = type;
|
||
|
||
|
||
// [ 64, 65, 66 ] -> [ padding, CR, LF ]
|
||
var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
|
||
|
||
|
||
function resolveYamlBinary(data) {
|
||
if (data === null) { return false; }
|
||
|
||
var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
|
||
|
||
// Convert one by one.
|
||
for (idx = 0; idx < max; idx++) {
|
||
code = map.indexOf(data.charAt(idx));
|
||
|
||
// Skip CR/LF
|
||
if (code > 64) { continue; }
|
||
|
||
// Fail on illegal characters
|
||
if (code < 0) { return false; }
|
||
|
||
bitlen += 6;
|
||
}
|
||
|
||
// If there are any bits left, source was corrupted
|
||
return (bitlen % 8) === 0;
|
||
}
|
||
|
||
function constructYamlBinary(data) {
|
||
var idx, tailbits,
|
||
input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
|
||
max = input.length,
|
||
map = BASE64_MAP,
|
||
bits = 0,
|
||
result = [];
|
||
|
||
// Collect by 6*4 bits (3 bytes)
|
||
|
||
for (idx = 0; idx < max; idx++) {
|
||
if ((idx % 4 === 0) && idx) {
|
||
result.push((bits >> 16) & 0xFF);
|
||
result.push((bits >> 8) & 0xFF);
|
||
result.push(bits & 0xFF);
|
||
}
|
||
|
||
bits = (bits << 6) | map.indexOf(input.charAt(idx));
|
||
}
|
||
|
||
// Dump tail
|
||
|
||
tailbits = (max % 4) * 6;
|
||
|
||
if (tailbits === 0) {
|
||
result.push((bits >> 16) & 0xFF);
|
||
result.push((bits >> 8) & 0xFF);
|
||
result.push(bits & 0xFF);
|
||
} else if (tailbits === 18) {
|
||
result.push((bits >> 10) & 0xFF);
|
||
result.push((bits >> 2) & 0xFF);
|
||
} else if (tailbits === 12) {
|
||
result.push((bits >> 4) & 0xFF);
|
||
}
|
||
|
||
// Wrap into Buffer for NodeJS and leave Array for browser
|
||
if (NodeBuffer) { return new NodeBuffer(result); }
|
||
|
||
return result;
|
||
}
|
||
|
||
function representYamlBinary(object /*, style*/) {
|
||
var result = '', bits = 0, idx, tail,
|
||
max = object.length,
|
||
map = BASE64_MAP;
|
||
|
||
// Convert every three bytes to 4 ASCII characters.
|
||
|
||
for (idx = 0; idx < max; idx++) {
|
||
if ((idx % 3 === 0) && idx) {
|
||
result += map[(bits >> 18) & 0x3F];
|
||
result += map[(bits >> 12) & 0x3F];
|
||
result += map[(bits >> 6) & 0x3F];
|
||
result += map[bits & 0x3F];
|
||
}
|
||
|
||
bits = (bits << 8) + object[idx];
|
||
}
|
||
|
||
// Dump tail
|
||
|
||
tail = max % 3;
|
||
|
||
if (tail === 0) {
|
||
result += map[(bits >> 18) & 0x3F];
|
||
result += map[(bits >> 12) & 0x3F];
|
||
result += map[(bits >> 6) & 0x3F];
|
||
result += map[bits & 0x3F];
|
||
} else if (tail === 2) {
|
||
result += map[(bits >> 10) & 0x3F];
|
||
result += map[(bits >> 4) & 0x3F];
|
||
result += map[(bits << 2) & 0x3F];
|
||
result += map[64];
|
||
} else if (tail === 1) {
|
||
result += map[(bits >> 2) & 0x3F];
|
||
result += map[(bits << 4) & 0x3F];
|
||
result += map[64];
|
||
result += map[64];
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
function isBinary(object) {
|
||
return NodeBuffer && NodeBuffer.isBuffer(object);
|
||
}
|
||
|
||
var binary = new Type$12('tag:yaml.org,2002:binary', {
|
||
kind: 'scalar',
|
||
resolve: resolveYamlBinary,
|
||
construct: constructYamlBinary,
|
||
predicate: isBinary,
|
||
represent: representYamlBinary
|
||
});
|
||
|
||
var Type$13 = type;
|
||
|
||
var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
||
var _toString = Object.prototype.toString;
|
||
|
||
function resolveYamlOmap(data) {
|
||
if (data === null) { return true; }
|
||
|
||
var objectKeys = [], index, length, pair, pairKey, pairHasKey,
|
||
object = data;
|
||
|
||
for (index = 0, length = object.length; index < length; index += 1) {
|
||
pair = object[index];
|
||
pairHasKey = false;
|
||
|
||
if (_toString.call(pair) !== '[object Object]') { return false; }
|
||
|
||
for (pairKey in pair) {
|
||
if (_hasOwnProperty$1.call(pair, pairKey)) {
|
||
if (!pairHasKey) { pairHasKey = true; }
|
||
else { return false; }
|
||
}
|
||
}
|
||
|
||
if (!pairHasKey) { return false; }
|
||
|
||
if (objectKeys.indexOf(pairKey) === -1) { objectKeys.push(pairKey); }
|
||
else { return false; }
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
function constructYamlOmap(data) {
|
||
return data !== null ? data : [];
|
||
}
|
||
|
||
var omap = new Type$13('tag:yaml.org,2002:omap', {
|
||
kind: 'sequence',
|
||
resolve: resolveYamlOmap,
|
||
construct: constructYamlOmap
|
||
});
|
||
|
||
var Type$14 = type;
|
||
|
||
var _toString$1 = Object.prototype.toString;
|
||
|
||
function resolveYamlPairs(data) {
|
||
if (data === null) { return true; }
|
||
|
||
var index, length, pair, keys, result,
|
||
object = data;
|
||
|
||
result = new Array(object.length);
|
||
|
||
for (index = 0, length = object.length; index < length; index += 1) {
|
||
pair = object[index];
|
||
|
||
if (_toString$1.call(pair) !== '[object Object]') { return false; }
|
||
|
||
keys = Object.keys(pair);
|
||
|
||
if (keys.length !== 1) { return false; }
|
||
|
||
result[index] = [ keys[0], pair[keys[0]] ];
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
function constructYamlPairs(data) {
|
||
if (data === null) { return []; }
|
||
|
||
var index, length, pair, keys, result,
|
||
object = data;
|
||
|
||
result = new Array(object.length);
|
||
|
||
for (index = 0, length = object.length; index < length; index += 1) {
|
||
pair = object[index];
|
||
|
||
keys = Object.keys(pair);
|
||
|
||
result[index] = [ keys[0], pair[keys[0]] ];
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
var pairs = new Type$14('tag:yaml.org,2002:pairs', {
|
||
kind: 'sequence',
|
||
resolve: resolveYamlPairs,
|
||
construct: constructYamlPairs
|
||
});
|
||
|
||
var Type$15 = type;
|
||
|
||
var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
||
|
||
function resolveYamlSet(data) {
|
||
if (data === null) { return true; }
|
||
|
||
var key, object = data;
|
||
|
||
for (key in object) {
|
||
if (_hasOwnProperty$2.call(object, key)) {
|
||
if (object[key] !== null) { return false; }
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
function constructYamlSet(data) {
|
||
return data !== null ? data : {};
|
||
}
|
||
|
||
var set = new Type$15('tag:yaml.org,2002:set', {
|
||
kind: 'mapping',
|
||
resolve: resolveYamlSet,
|
||
construct: constructYamlSet
|
||
});
|
||
|
||
var Schema$1 = schema;
|
||
|
||
|
||
var default_safe = new Schema$1({
|
||
include: [
|
||
core
|
||
],
|
||
implicit: [
|
||
timestamp,
|
||
merge
|
||
],
|
||
explicit: [
|
||
binary,
|
||
omap,
|
||
pairs,
|
||
set
|
||
]
|
||
});
|
||
|
||
var Type$16 = type;
|
||
|
||
function resolveJavascriptUndefined() {
|
||
return true;
|
||
}
|
||
|
||
function constructJavascriptUndefined() {
|
||
/*eslint-disable no-undefined*/
|
||
return undefined;
|
||
}
|
||
|
||
function representJavascriptUndefined() {
|
||
return '';
|
||
}
|
||
|
||
function isUndefined(object) {
|
||
return typeof object === 'undefined';
|
||
}
|
||
|
||
var _undefined = new Type$16('tag:yaml.org,2002:js/undefined', {
|
||
kind: 'scalar',
|
||
resolve: resolveJavascriptUndefined,
|
||
construct: constructJavascriptUndefined,
|
||
predicate: isUndefined,
|
||
represent: representJavascriptUndefined
|
||
});
|
||
|
||
var Type$17 = type;
|
||
|
||
function resolveJavascriptRegExp(data) {
|
||
if (data === null) { return false; }
|
||
if (data.length === 0) { return false; }
|
||
|
||
var regexp = data,
|
||
tail = /\/([gim]*)$/.exec(data),
|
||
modifiers = '';
|
||
|
||
// if regexp starts with '/' it can have modifiers and must be properly closed
|
||
// `/foo/gim` - modifiers tail can be maximum 3 chars
|
||
if (regexp[0] === '/') {
|
||
if (tail) { modifiers = tail[1]; }
|
||
|
||
if (modifiers.length > 3) { return false; }
|
||
// if expression starts with /, is should be properly terminated
|
||
if (regexp[regexp.length - modifiers.length - 1] !== '/') { return false; }
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
function constructJavascriptRegExp(data) {
|
||
var regexp = data,
|
||
tail = /\/([gim]*)$/.exec(data),
|
||
modifiers = '';
|
||
|
||
// `/foo/gim` - tail can be maximum 4 chars
|
||
if (regexp[0] === '/') {
|
||
if (tail) { modifiers = tail[1]; }
|
||
regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
|
||
}
|
||
|
||
return new RegExp(regexp, modifiers);
|
||
}
|
||
|
||
function representJavascriptRegExp(object /*, style*/) {
|
||
var result = '/' + object.source + '/';
|
||
|
||
if (object.global) { result += 'g'; }
|
||
if (object.multiline) { result += 'm'; }
|
||
if (object.ignoreCase) { result += 'i'; }
|
||
|
||
return result;
|
||
}
|
||
|
||
function isRegExp(object) {
|
||
return Object.prototype.toString.call(object) === '[object RegExp]';
|
||
}
|
||
|
||
var regexp = new Type$17('tag:yaml.org,2002:js/regexp', {
|
||
kind: 'scalar',
|
||
resolve: resolveJavascriptRegExp,
|
||
construct: constructJavascriptRegExp,
|
||
predicate: isRegExp,
|
||
represent: representJavascriptRegExp
|
||
});
|
||
|
||
var esprima;
|
||
|
||
// Browserified version does not have esprima
|
||
//
|
||
// 1. For node.js just require module as deps
|
||
// 2. For browser try to require mudule via external AMD system.
|
||
// If not found - try to fallback to window.esprima. If not
|
||
// found too - then fail to parse.
|
||
//
|
||
try {
|
||
// workaround to exclude package from browserify list.
|
||
var _require$1 = commonjsRequire;
|
||
esprima = _require$1('esprima');
|
||
} catch (_) {
|
||
/*global window */
|
||
if (typeof window !== 'undefined') { esprima = window.esprima; }
|
||
}
|
||
|
||
var Type$18 = type;
|
||
|
||
function resolveJavascriptFunction(data) {
|
||
if (data === null) { return false; }
|
||
|
||
try {
|
||
var source = '(' + data + ')',
|
||
ast = esprima.parse(source, { range: true });
|
||
|
||
if (ast.type !== 'Program' ||
|
||
ast.body.length !== 1 ||
|
||
ast.body[0].type !== 'ExpressionStatement' ||
|
||
ast.body[0].expression.type !== 'FunctionExpression') {
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
} catch (err) {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
function constructJavascriptFunction(data) {
|
||
/*jslint evil:true*/
|
||
|
||
var source = '(' + data + ')',
|
||
ast = esprima.parse(source, { range: true }),
|
||
params = [],
|
||
body;
|
||
|
||
if (ast.type !== 'Program' ||
|
||
ast.body.length !== 1 ||
|
||
ast.body[0].type !== 'ExpressionStatement' ||
|
||
ast.body[0].expression.type !== 'FunctionExpression') {
|
||
throw new Error('Failed to resolve function');
|
||
}
|
||
|
||
ast.body[0].expression.params.forEach(function (param) {
|
||
params.push(param.name);
|
||
});
|
||
|
||
body = ast.body[0].expression.body.range;
|
||
|
||
// Esprima's ranges include the first '{' and the last '}' characters on
|
||
// function expressions. So cut them out.
|
||
/*eslint-disable no-new-func*/
|
||
return new Function(params, source.slice(body[0] + 1, body[1] - 1));
|
||
}
|
||
|
||
function representJavascriptFunction(object /*, style*/) {
|
||
return object.toString();
|
||
}
|
||
|
||
function isFunction(object) {
|
||
return Object.prototype.toString.call(object) === '[object Function]';
|
||
}
|
||
|
||
var _function = new Type$18('tag:yaml.org,2002:js/function', {
|
||
kind: 'scalar',
|
||
resolve: resolveJavascriptFunction,
|
||
construct: constructJavascriptFunction,
|
||
predicate: isFunction,
|
||
represent: representJavascriptFunction
|
||
});
|
||
|
||
var Schema$6 = schema;
|
||
|
||
|
||
var default_full = Schema$6.DEFAULT = new Schema$6({
|
||
include: [
|
||
default_safe
|
||
],
|
||
explicit: [
|
||
_undefined,
|
||
regexp,
|
||
_function
|
||
]
|
||
});
|
||
|
||
var common = common$1;
|
||
var YAMLException$1 = exception;
|
||
var Mark = mark;
|
||
var DEFAULT_SAFE_SCHEMA$1 = default_safe;
|
||
var DEFAULT_FULL_SCHEMA$1 = default_full;
|
||
|
||
|
||
var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
||
|
||
|
||
var CONTEXT_FLOW_IN = 1;
|
||
var CONTEXT_FLOW_OUT = 2;
|
||
var CONTEXT_BLOCK_IN = 3;
|
||
var CONTEXT_BLOCK_OUT = 4;
|
||
|
||
|
||
var CHOMPING_CLIP = 1;
|
||
var CHOMPING_STRIP = 2;
|
||
var CHOMPING_KEEP = 3;
|
||
|
||
|
||
var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
||
var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
||
var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
||
var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
||
var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
||
|
||
|
||
function is_EOL(c) {
|
||
return (c === 0x0A/* LF */) || (c === 0x0D/* CR */);
|
||
}
|
||
|
||
function is_WHITE_SPACE(c) {
|
||
return (c === 0x09/* Tab */) || (c === 0x20/* Space */);
|
||
}
|
||
|
||
function is_WS_OR_EOL(c) {
|
||
return (c === 0x09/* Tab */) ||
|
||
(c === 0x20/* Space */) ||
|
||
(c === 0x0A/* LF */) ||
|
||
(c === 0x0D/* CR */);
|
||
}
|
||
|
||
function is_FLOW_INDICATOR(c) {
|
||
return c === 0x2C/* , */ ||
|
||
c === 0x5B/* [ */ ||
|
||
c === 0x5D/* ] */ ||
|
||
c === 0x7B/* { */ ||
|
||
c === 0x7D/* } */;
|
||
}
|
||
|
||
function fromHexCode(c) {
|
||
var lc;
|
||
|
||
if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
|
||
return c - 0x30;
|
||
}
|
||
|
||
/*eslint-disable no-bitwise*/
|
||
lc = c | 0x20;
|
||
|
||
if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) {
|
||
return lc - 0x61 + 10;
|
||
}
|
||
|
||
return -1;
|
||
}
|
||
|
||
function escapedHexLen(c) {
|
||
if (c === 0x78/* x */) { return 2; }
|
||
if (c === 0x75/* u */) { return 4; }
|
||
if (c === 0x55/* U */) { return 8; }
|
||
return 0;
|
||
}
|
||
|
||
function fromDecimalCode(c) {
|
||
if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
|
||
return c - 0x30;
|
||
}
|
||
|
||
return -1;
|
||
}
|
||
|
||
function simpleEscapeSequence(c) {
|
||
return (c === 0x30/* 0 */) ? '\x00' :
|
||
(c === 0x61/* a */) ? '\x07' :
|
||
(c === 0x62/* b */) ? '\x08' :
|
||
(c === 0x74/* t */) ? '\x09' :
|
||
(c === 0x09/* Tab */) ? '\x09' :
|
||
(c === 0x6E/* n */) ? '\x0A' :
|
||
(c === 0x76/* v */) ? '\x0B' :
|
||
(c === 0x66/* f */) ? '\x0C' :
|
||
(c === 0x72/* r */) ? '\x0D' :
|
||
(c === 0x65/* e */) ? '\x1B' :
|
||
(c === 0x20/* Space */) ? ' ' :
|
||
(c === 0x22/* " */) ? '\x22' :
|
||
(c === 0x2F/* / */) ? '/' :
|
||
(c === 0x5C/* \ */) ? '\x5C' :
|
||
(c === 0x4E/* N */) ? '\x85' :
|
||
(c === 0x5F/* _ */) ? '\xA0' :
|
||
(c === 0x4C/* L */) ? '\u2028' :
|
||
(c === 0x50/* P */) ? '\u2029' : '';
|
||
}
|
||
|
||
function charFromCodepoint(c) {
|
||
if (c <= 0xFFFF) {
|
||
return String.fromCharCode(c);
|
||
}
|
||
// Encode UTF-16 surrogate pair
|
||
// https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
|
||
return String.fromCharCode(((c - 0x010000) >> 10) + 0xD800,
|
||
((c - 0x010000) & 0x03FF) + 0xDC00);
|
||
}
|
||
|
||
var simpleEscapeCheck = new Array(256); // integer, for fast access
|
||
var simpleEscapeMap = new Array(256);
|
||
for (var i = 0; i < 256; i++) {
|
||
simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
||
simpleEscapeMap[i] = simpleEscapeSequence(i);
|
||
}
|
||
|
||
|
||
function State(input, options) {
|
||
this.input = input;
|
||
|
||
this.filename = options['filename'] || null;
|
||
this.schema = options['schema'] || DEFAULT_FULL_SCHEMA$1;
|
||
this.onWarning = options['onWarning'] || null;
|
||
this.legacy = options['legacy'] || false;
|
||
this.json = options['json'] || false;
|
||
this.listener = options['listener'] || null;
|
||
|
||
this.implicitTypes = this.schema.compiledImplicit;
|
||
this.typeMap = this.schema.compiledTypeMap;
|
||
|
||
this.length = input.length;
|
||
this.position = 0;
|
||
this.line = 0;
|
||
this.lineStart = 0;
|
||
this.lineIndent = 0;
|
||
|
||
this.documents = [];
|
||
|
||
/*
|
||
this.version;
|
||
this.checkLineBreaks;
|
||
this.tagMap;
|
||
this.anchorMap;
|
||
this.tag;
|
||
this.anchor;
|
||
this.kind;
|
||
this.result;*/
|
||
|
||
}
|
||
|
||
|
||
function generateError(state, message) {
|
||
return new YAMLException$1(
|
||
message,
|
||
new Mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
|
||
}
|
||
|
||
function throwError(state, message) {
|
||
throw generateError(state, message);
|
||
}
|
||
|
||
function throwWarning(state, message) {
|
||
if (state.onWarning) {
|
||
state.onWarning.call(null, generateError(state, message));
|
||
}
|
||
}
|
||
|
||
|
||
var directiveHandlers = {
|
||
|
||
YAML: function handleYamlDirective(state, name, args) {
|
||
|
||
var match, major, minor;
|
||
|
||
if (state.version !== null) {
|
||
throwError(state, 'duplication of %YAML directive');
|
||
}
|
||
|
||
if (args.length !== 1) {
|
||
throwError(state, 'YAML directive accepts exactly one argument');
|
||
}
|
||
|
||
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
||
|
||
if (match === null) {
|
||
throwError(state, 'ill-formed argument of the YAML directive');
|
||
}
|
||
|
||
major = parseInt(match[1], 10);
|
||
minor = parseInt(match[2], 10);
|
||
|
||
if (major !== 1) {
|
||
throwError(state, 'unacceptable YAML version of the document');
|
||
}
|
||
|
||
state.version = args[0];
|
||
state.checkLineBreaks = (minor < 2);
|
||
|
||
if (minor !== 1 && minor !== 2) {
|
||
throwWarning(state, 'unsupported YAML version of the document');
|
||
}
|
||
},
|
||
|
||
TAG: function handleTagDirective(state, name, args) {
|
||
|
||
var handle, prefix;
|
||
|
||
if (args.length !== 2) {
|
||
throwError(state, 'TAG directive accepts exactly two arguments');
|
||
}
|
||
|
||
handle = args[0];
|
||
prefix = args[1];
|
||
|
||
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
||
throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
|
||
}
|
||
|
||
if (_hasOwnProperty.call(state.tagMap, handle)) {
|
||
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
||
}
|
||
|
||
if (!PATTERN_TAG_URI.test(prefix)) {
|
||
throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
|
||
}
|
||
|
||
state.tagMap[handle] = prefix;
|
||
}
|
||
};
|
||
|
||
|
||
function captureSegment(state, start, end, checkJson) {
|
||
var _position, _length, _character, _result;
|
||
|
||
if (start < end) {
|
||
_result = state.input.slice(start, end);
|
||
|
||
if (checkJson) {
|
||
for (_position = 0, _length = _result.length;
|
||
_position < _length;
|
||
_position += 1) {
|
||
_character = _result.charCodeAt(_position);
|
||
if (!(_character === 0x09 ||
|
||
(0x20 <= _character && _character <= 0x10FFFF))) {
|
||
throwError(state, 'expected valid JSON character');
|
||
}
|
||
}
|
||
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
||
throwError(state, 'the stream contains non-printable characters');
|
||
}
|
||
|
||
state.result += _result;
|
||
}
|
||
}
|
||
|
||
function mergeMappings(state, destination, source, overridableKeys) {
|
||
var sourceKeys, key, index, quantity;
|
||
|
||
if (!common.isObject(source)) {
|
||
throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
|
||
}
|
||
|
||
sourceKeys = Object.keys(source);
|
||
|
||
for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
||
key = sourceKeys[index];
|
||
|
||
if (!_hasOwnProperty.call(destination, key)) {
|
||
destination[key] = source[key];
|
||
overridableKeys[key] = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode) {
|
||
var index, quantity;
|
||
|
||
keyNode = String(keyNode);
|
||
|
||
if (_result === null) {
|
||
_result = {};
|
||
}
|
||
|
||
if (keyTag === 'tag:yaml.org,2002:merge') {
|
||
if (Array.isArray(valueNode)) {
|
||
for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
||
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
||
}
|
||
} else {
|
||
mergeMappings(state, _result, valueNode, overridableKeys);
|
||
}
|
||
} else {
|
||
if (!state.json &&
|
||
!_hasOwnProperty.call(overridableKeys, keyNode) &&
|
||
_hasOwnProperty.call(_result, keyNode)) {
|
||
throwError(state, 'duplicated mapping key');
|
||
}
|
||
_result[keyNode] = valueNode;
|
||
delete overridableKeys[keyNode];
|
||
}
|
||
|
||
return _result;
|
||
}
|
||
|
||
function readLineBreak(state) {
|
||
var ch;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch === 0x0A/* LF */) {
|
||
state.position++;
|
||
} else if (ch === 0x0D/* CR */) {
|
||
state.position++;
|
||
if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
|
||
state.position++;
|
||
}
|
||
} else {
|
||
throwError(state, 'a line break is expected');
|
||
}
|
||
|
||
state.line += 1;
|
||
state.lineStart = state.position;
|
||
}
|
||
|
||
function skipSeparationSpace(state, allowComments, checkIndent) {
|
||
var lineBreaks = 0,
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
while (ch !== 0) {
|
||
while (is_WHITE_SPACE(ch)) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
if (allowComments && ch === 0x23/* # */) {
|
||
do {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
} while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
|
||
}
|
||
|
||
if (is_EOL(ch)) {
|
||
readLineBreak(state);
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
lineBreaks++;
|
||
state.lineIndent = 0;
|
||
|
||
while (ch === 0x20/* Space */) {
|
||
state.lineIndent++;
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
} else {
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
||
throwWarning(state, 'deficient indentation');
|
||
}
|
||
|
||
return lineBreaks;
|
||
}
|
||
|
||
function testDocumentSeparator(state) {
|
||
var _position = state.position,
|
||
ch;
|
||
|
||
ch = state.input.charCodeAt(_position);
|
||
|
||
// Condition state.position === state.lineStart is tested
|
||
// in parent on each call, for efficiency. No needs to test here again.
|
||
if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
|
||
ch === state.input.charCodeAt(_position + 1) &&
|
||
ch === state.input.charCodeAt(_position + 2)) {
|
||
|
||
_position += 3;
|
||
|
||
ch = state.input.charCodeAt(_position);
|
||
|
||
if (ch === 0 || is_WS_OR_EOL(ch)) {
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
function writeFoldedLines(state, count) {
|
||
if (count === 1) {
|
||
state.result += ' ';
|
||
} else if (count > 1) {
|
||
state.result += common.repeat('\n', count - 1);
|
||
}
|
||
}
|
||
|
||
|
||
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
||
var preceding,
|
||
following,
|
||
captureStart,
|
||
captureEnd,
|
||
hasPendingContent,
|
||
_line,
|
||
_lineStart,
|
||
_lineIndent,
|
||
_kind = state.kind,
|
||
_result = state.result,
|
||
ch;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (is_WS_OR_EOL(ch) ||
|
||
is_FLOW_INDICATOR(ch) ||
|
||
ch === 0x23/* # */ ||
|
||
ch === 0x26/* & */ ||
|
||
ch === 0x2A/* * */ ||
|
||
ch === 0x21/* ! */ ||
|
||
ch === 0x7C/* | */ ||
|
||
ch === 0x3E/* > */ ||
|
||
ch === 0x27/* ' */ ||
|
||
ch === 0x22/* " */ ||
|
||
ch === 0x25/* % */ ||
|
||
ch === 0x40/* @ */ ||
|
||
ch === 0x60/* ` */) {
|
||
return false;
|
||
}
|
||
|
||
if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
|
||
following = state.input.charCodeAt(state.position + 1);
|
||
|
||
if (is_WS_OR_EOL(following) ||
|
||
withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
state.kind = 'scalar';
|
||
state.result = '';
|
||
captureStart = captureEnd = state.position;
|
||
hasPendingContent = false;
|
||
|
||
while (ch !== 0) {
|
||
if (ch === 0x3A/* : */) {
|
||
following = state.input.charCodeAt(state.position + 1);
|
||
|
||
if (is_WS_OR_EOL(following) ||
|
||
withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
||
break;
|
||
}
|
||
|
||
} else if (ch === 0x23/* # */) {
|
||
preceding = state.input.charCodeAt(state.position - 1);
|
||
|
||
if (is_WS_OR_EOL(preceding)) {
|
||
break;
|
||
}
|
||
|
||
} else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
|
||
withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
||
break;
|
||
|
||
} else if (is_EOL(ch)) {
|
||
_line = state.line;
|
||
_lineStart = state.lineStart;
|
||
_lineIndent = state.lineIndent;
|
||
skipSeparationSpace(state, false, -1);
|
||
|
||
if (state.lineIndent >= nodeIndent) {
|
||
hasPendingContent = true;
|
||
ch = state.input.charCodeAt(state.position);
|
||
continue;
|
||
} else {
|
||
state.position = captureEnd;
|
||
state.line = _line;
|
||
state.lineStart = _lineStart;
|
||
state.lineIndent = _lineIndent;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (hasPendingContent) {
|
||
captureSegment(state, captureStart, captureEnd, false);
|
||
writeFoldedLines(state, state.line - _line);
|
||
captureStart = captureEnd = state.position;
|
||
hasPendingContent = false;
|
||
}
|
||
|
||
if (!is_WHITE_SPACE(ch)) {
|
||
captureEnd = state.position + 1;
|
||
}
|
||
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
captureSegment(state, captureStart, captureEnd, false);
|
||
|
||
if (state.result) {
|
||
return true;
|
||
}
|
||
|
||
state.kind = _kind;
|
||
state.result = _result;
|
||
return false;
|
||
}
|
||
|
||
function readSingleQuotedScalar(state, nodeIndent) {
|
||
var ch,
|
||
captureStart, captureEnd;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch !== 0x27/* ' */) {
|
||
return false;
|
||
}
|
||
|
||
state.kind = 'scalar';
|
||
state.result = '';
|
||
state.position++;
|
||
captureStart = captureEnd = state.position;
|
||
|
||
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
||
if (ch === 0x27/* ' */) {
|
||
captureSegment(state, captureStart, state.position, true);
|
||
ch = state.input.charCodeAt(++state.position);
|
||
|
||
if (ch === 0x27/* ' */) {
|
||
captureStart = state.position;
|
||
state.position++;
|
||
captureEnd = state.position;
|
||
} else {
|
||
return true;
|
||
}
|
||
|
||
} else if (is_EOL(ch)) {
|
||
captureSegment(state, captureStart, captureEnd, true);
|
||
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
||
captureStart = captureEnd = state.position;
|
||
|
||
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
||
throwError(state, 'unexpected end of the document within a single quoted scalar');
|
||
|
||
} else {
|
||
state.position++;
|
||
captureEnd = state.position;
|
||
}
|
||
}
|
||
|
||
throwError(state, 'unexpected end of the stream within a single quoted scalar');
|
||
}
|
||
|
||
function readDoubleQuotedScalar(state, nodeIndent) {
|
||
var captureStart,
|
||
captureEnd,
|
||
hexLength,
|
||
hexResult,
|
||
tmp,
|
||
ch;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch !== 0x22/* " */) {
|
||
return false;
|
||
}
|
||
|
||
state.kind = 'scalar';
|
||
state.result = '';
|
||
state.position++;
|
||
captureStart = captureEnd = state.position;
|
||
|
||
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
||
if (ch === 0x22/* " */) {
|
||
captureSegment(state, captureStart, state.position, true);
|
||
state.position++;
|
||
return true;
|
||
|
||
} else if (ch === 0x5C/* \ */) {
|
||
captureSegment(state, captureStart, state.position, true);
|
||
ch = state.input.charCodeAt(++state.position);
|
||
|
||
if (is_EOL(ch)) {
|
||
skipSeparationSpace(state, false, nodeIndent);
|
||
|
||
// TODO: rework to inline fn with no type cast?
|
||
} else if (ch < 256 && simpleEscapeCheck[ch]) {
|
||
state.result += simpleEscapeMap[ch];
|
||
state.position++;
|
||
|
||
} else if ((tmp = escapedHexLen(ch)) > 0) {
|
||
hexLength = tmp;
|
||
hexResult = 0;
|
||
|
||
for (; hexLength > 0; hexLength--) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
|
||
if ((tmp = fromHexCode(ch)) >= 0) {
|
||
hexResult = (hexResult << 4) + tmp;
|
||
|
||
} else {
|
||
throwError(state, 'expected hexadecimal character');
|
||
}
|
||
}
|
||
|
||
state.result += charFromCodepoint(hexResult);
|
||
|
||
state.position++;
|
||
|
||
} else {
|
||
throwError(state, 'unknown escape sequence');
|
||
}
|
||
|
||
captureStart = captureEnd = state.position;
|
||
|
||
} else if (is_EOL(ch)) {
|
||
captureSegment(state, captureStart, captureEnd, true);
|
||
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
||
captureStart = captureEnd = state.position;
|
||
|
||
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
||
throwError(state, 'unexpected end of the document within a double quoted scalar');
|
||
|
||
} else {
|
||
state.position++;
|
||
captureEnd = state.position;
|
||
}
|
||
}
|
||
|
||
throwError(state, 'unexpected end of the stream within a double quoted scalar');
|
||
}
|
||
|
||
function readFlowCollection(state, nodeIndent) {
|
||
var readNext = true,
|
||
_line,
|
||
_tag = state.tag,
|
||
_result,
|
||
_anchor = state.anchor,
|
||
following,
|
||
terminator,
|
||
isPair,
|
||
isExplicitPair,
|
||
isMapping,
|
||
overridableKeys = {},
|
||
keyNode,
|
||
keyTag,
|
||
valueNode,
|
||
ch;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch === 0x5B/* [ */) {
|
||
terminator = 0x5D;/* ] */
|
||
isMapping = false;
|
||
_result = [];
|
||
} else if (ch === 0x7B/* { */) {
|
||
terminator = 0x7D;/* } */
|
||
isMapping = true;
|
||
_result = {};
|
||
} else {
|
||
return false;
|
||
}
|
||
|
||
if (state.anchor !== null) {
|
||
state.anchorMap[state.anchor] = _result;
|
||
}
|
||
|
||
ch = state.input.charCodeAt(++state.position);
|
||
|
||
while (ch !== 0) {
|
||
skipSeparationSpace(state, true, nodeIndent);
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch === terminator) {
|
||
state.position++;
|
||
state.tag = _tag;
|
||
state.anchor = _anchor;
|
||
state.kind = isMapping ? 'mapping' : 'sequence';
|
||
state.result = _result;
|
||
return true;
|
||
} else if (!readNext) {
|
||
throwError(state, 'missed comma between flow collection entries');
|
||
}
|
||
|
||
keyTag = keyNode = valueNode = null;
|
||
isPair = isExplicitPair = false;
|
||
|
||
if (ch === 0x3F/* ? */) {
|
||
following = state.input.charCodeAt(state.position + 1);
|
||
|
||
if (is_WS_OR_EOL(following)) {
|
||
isPair = isExplicitPair = true;
|
||
state.position++;
|
||
skipSeparationSpace(state, true, nodeIndent);
|
||
}
|
||
}
|
||
|
||
_line = state.line;
|
||
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
||
keyTag = state.tag;
|
||
keyNode = state.result;
|
||
skipSeparationSpace(state, true, nodeIndent);
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
|
||
isPair = true;
|
||
ch = state.input.charCodeAt(++state.position);
|
||
skipSeparationSpace(state, true, nodeIndent);
|
||
composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
||
valueNode = state.result;
|
||
}
|
||
|
||
if (isMapping) {
|
||
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
|
||
} else if (isPair) {
|
||
_result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
|
||
} else {
|
||
_result.push(keyNode);
|
||
}
|
||
|
||
skipSeparationSpace(state, true, nodeIndent);
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch === 0x2C/* , */) {
|
||
readNext = true;
|
||
ch = state.input.charCodeAt(++state.position);
|
||
} else {
|
||
readNext = false;
|
||
}
|
||
}
|
||
|
||
throwError(state, 'unexpected end of the stream within a flow collection');
|
||
}
|
||
|
||
function readBlockScalar(state, nodeIndent) {
|
||
var captureStart,
|
||
folding,
|
||
chomping = CHOMPING_CLIP,
|
||
didReadContent = false,
|
||
detectedIndent = false,
|
||
textIndent = nodeIndent,
|
||
emptyLines = 0,
|
||
atMoreIndented = false,
|
||
tmp,
|
||
ch;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch === 0x7C/* | */) {
|
||
folding = false;
|
||
} else if (ch === 0x3E/* > */) {
|
||
folding = true;
|
||
} else {
|
||
return false;
|
||
}
|
||
|
||
state.kind = 'scalar';
|
||
state.result = '';
|
||
|
||
while (ch !== 0) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
|
||
if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
|
||
if (CHOMPING_CLIP === chomping) {
|
||
chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
|
||
} else {
|
||
throwError(state, 'repeat of a chomping mode identifier');
|
||
}
|
||
|
||
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
||
if (tmp === 0) {
|
||
throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
|
||
} else if (!detectedIndent) {
|
||
textIndent = nodeIndent + tmp - 1;
|
||
detectedIndent = true;
|
||
} else {
|
||
throwError(state, 'repeat of an indentation width identifier');
|
||
}
|
||
|
||
} else {
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (is_WHITE_SPACE(ch)) {
|
||
do { ch = state.input.charCodeAt(++state.position); }
|
||
while (is_WHITE_SPACE(ch));
|
||
|
||
if (ch === 0x23/* # */) {
|
||
do { ch = state.input.charCodeAt(++state.position); }
|
||
while (!is_EOL(ch) && (ch !== 0));
|
||
}
|
||
}
|
||
|
||
while (ch !== 0) {
|
||
readLineBreak(state);
|
||
state.lineIndent = 0;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
while ((!detectedIndent || state.lineIndent < textIndent) &&
|
||
(ch === 0x20/* Space */)) {
|
||
state.lineIndent++;
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
if (!detectedIndent && state.lineIndent > textIndent) {
|
||
textIndent = state.lineIndent;
|
||
}
|
||
|
||
if (is_EOL(ch)) {
|
||
emptyLines++;
|
||
continue;
|
||
}
|
||
|
||
// End of the scalar.
|
||
if (state.lineIndent < textIndent) {
|
||
|
||
// Perform the chomping.
|
||
if (chomping === CHOMPING_KEEP) {
|
||
state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
||
} else if (chomping === CHOMPING_CLIP) {
|
||
if (didReadContent) { // i.e. only if the scalar is not empty.
|
||
state.result += '\n';
|
||
}
|
||
}
|
||
|
||
// Break this `while` cycle and go to the funciton's epilogue.
|
||
break;
|
||
}
|
||
|
||
// Folded style: use fancy rules to handle line breaks.
|
||
if (folding) {
|
||
|
||
// Lines starting with white space characters (more-indented lines) are not folded.
|
||
if (is_WHITE_SPACE(ch)) {
|
||
atMoreIndented = true;
|
||
// except for the first content line (cf. Example 8.1)
|
||
state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
||
|
||
// End of more-indented block.
|
||
} else if (atMoreIndented) {
|
||
atMoreIndented = false;
|
||
state.result += common.repeat('\n', emptyLines + 1);
|
||
|
||
// Just one line break - perceive as the same line.
|
||
} else if (emptyLines === 0) {
|
||
if (didReadContent) { // i.e. only if we have already read some scalar content.
|
||
state.result += ' ';
|
||
}
|
||
|
||
// Several line breaks - perceive as different lines.
|
||
} else {
|
||
state.result += common.repeat('\n', emptyLines);
|
||
}
|
||
|
||
// Literal style: just add exact number of line breaks between content lines.
|
||
} else {
|
||
// Keep all line breaks except the header line break.
|
||
state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
||
}
|
||
|
||
didReadContent = true;
|
||
detectedIndent = true;
|
||
emptyLines = 0;
|
||
captureStart = state.position;
|
||
|
||
while (!is_EOL(ch) && (ch !== 0)) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
captureSegment(state, captureStart, state.position, false);
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
function readBlockSequence(state, nodeIndent) {
|
||
var _line,
|
||
_tag = state.tag,
|
||
_anchor = state.anchor,
|
||
_result = [],
|
||
following,
|
||
detected = false,
|
||
ch;
|
||
|
||
if (state.anchor !== null) {
|
||
state.anchorMap[state.anchor] = _result;
|
||
}
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
while (ch !== 0) {
|
||
|
||
if (ch !== 0x2D/* - */) {
|
||
break;
|
||
}
|
||
|
||
following = state.input.charCodeAt(state.position + 1);
|
||
|
||
if (!is_WS_OR_EOL(following)) {
|
||
break;
|
||
}
|
||
|
||
detected = true;
|
||
state.position++;
|
||
|
||
if (skipSeparationSpace(state, true, -1)) {
|
||
if (state.lineIndent <= nodeIndent) {
|
||
_result.push(null);
|
||
ch = state.input.charCodeAt(state.position);
|
||
continue;
|
||
}
|
||
}
|
||
|
||
_line = state.line;
|
||
composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
||
_result.push(state.result);
|
||
skipSeparationSpace(state, true, -1);
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
|
||
throwError(state, 'bad indentation of a sequence entry');
|
||
} else if (state.lineIndent < nodeIndent) {
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (detected) {
|
||
state.tag = _tag;
|
||
state.anchor = _anchor;
|
||
state.kind = 'sequence';
|
||
state.result = _result;
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
function readBlockMapping(state, nodeIndent, flowIndent) {
|
||
var following,
|
||
allowCompact,
|
||
_line,
|
||
_tag = state.tag,
|
||
_anchor = state.anchor,
|
||
_result = {},
|
||
overridableKeys = {},
|
||
keyTag = null,
|
||
keyNode = null,
|
||
valueNode = null,
|
||
atExplicitKey = false,
|
||
detected = false,
|
||
ch;
|
||
|
||
if (state.anchor !== null) {
|
||
state.anchorMap[state.anchor] = _result;
|
||
}
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
while (ch !== 0) {
|
||
following = state.input.charCodeAt(state.position + 1);
|
||
_line = state.line; // Save the current line.
|
||
|
||
//
|
||
// Explicit notation case. There are two separate blocks:
|
||
// first for the key (denoted by "?") and second for the value (denoted by ":")
|
||
//
|
||
if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
|
||
|
||
if (ch === 0x3F/* ? */) {
|
||
if (atExplicitKey) {
|
||
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
||
keyTag = keyNode = valueNode = null;
|
||
}
|
||
|
||
detected = true;
|
||
atExplicitKey = true;
|
||
allowCompact = true;
|
||
|
||
} else if (atExplicitKey) {
|
||
// i.e. 0x3A/* : */ === character after the explicit key.
|
||
atExplicitKey = false;
|
||
allowCompact = true;
|
||
|
||
} else {
|
||
throwError(state, 'incomplete explicit mapping pair; a key node is missed');
|
||
}
|
||
|
||
state.position += 1;
|
||
ch = following;
|
||
|
||
//
|
||
// Implicit notation case. Flow-style node as the key first, then ":", and the value.
|
||
//
|
||
} else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
||
|
||
if (state.line === _line) {
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
while (is_WHITE_SPACE(ch)) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
if (ch === 0x3A/* : */) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
|
||
if (!is_WS_OR_EOL(ch)) {
|
||
throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
|
||
}
|
||
|
||
if (atExplicitKey) {
|
||
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
||
keyTag = keyNode = valueNode = null;
|
||
}
|
||
|
||
detected = true;
|
||
atExplicitKey = false;
|
||
allowCompact = false;
|
||
keyTag = state.tag;
|
||
keyNode = state.result;
|
||
|
||
} else if (detected) {
|
||
throwError(state, 'can not read an implicit mapping pair; a colon is missed');
|
||
|
||
} else {
|
||
state.tag = _tag;
|
||
state.anchor = _anchor;
|
||
return true; // Keep the result of `composeNode`.
|
||
}
|
||
|
||
} else if (detected) {
|
||
throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
|
||
|
||
} else {
|
||
state.tag = _tag;
|
||
state.anchor = _anchor;
|
||
return true; // Keep the result of `composeNode`.
|
||
}
|
||
|
||
} else {
|
||
break; // Reading is done. Go to the epilogue.
|
||
}
|
||
|
||
//
|
||
// Common reading code for both explicit and implicit notations.
|
||
//
|
||
if (state.line === _line || state.lineIndent > nodeIndent) {
|
||
if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
||
if (atExplicitKey) {
|
||
keyNode = state.result;
|
||
} else {
|
||
valueNode = state.result;
|
||
}
|
||
}
|
||
|
||
if (!atExplicitKey) {
|
||
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
|
||
keyTag = keyNode = valueNode = null;
|
||
}
|
||
|
||
skipSeparationSpace(state, true, -1);
|
||
ch = state.input.charCodeAt(state.position);
|
||
}
|
||
|
||
if (state.lineIndent > nodeIndent && (ch !== 0)) {
|
||
throwError(state, 'bad indentation of a mapping entry');
|
||
} else if (state.lineIndent < nodeIndent) {
|
||
break;
|
||
}
|
||
}
|
||
|
||
//
|
||
// Epilogue.
|
||
//
|
||
|
||
// Special case: last mapping's node contains only the key in explicit notation.
|
||
if (atExplicitKey) {
|
||
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
||
}
|
||
|
||
// Expose the resulting mapping.
|
||
if (detected) {
|
||
state.tag = _tag;
|
||
state.anchor = _anchor;
|
||
state.kind = 'mapping';
|
||
state.result = _result;
|
||
}
|
||
|
||
return detected;
|
||
}
|
||
|
||
function readTagProperty(state) {
|
||
var _position,
|
||
isVerbatim = false,
|
||
isNamed = false,
|
||
tagHandle,
|
||
tagName,
|
||
ch;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch !== 0x21/* ! */) { return false; }
|
||
|
||
if (state.tag !== null) {
|
||
throwError(state, 'duplication of a tag property');
|
||
}
|
||
|
||
ch = state.input.charCodeAt(++state.position);
|
||
|
||
if (ch === 0x3C/* < */) {
|
||
isVerbatim = true;
|
||
ch = state.input.charCodeAt(++state.position);
|
||
|
||
} else if (ch === 0x21/* ! */) {
|
||
isNamed = true;
|
||
tagHandle = '!!';
|
||
ch = state.input.charCodeAt(++state.position);
|
||
|
||
} else {
|
||
tagHandle = '!';
|
||
}
|
||
|
||
_position = state.position;
|
||
|
||
if (isVerbatim) {
|
||
do { ch = state.input.charCodeAt(++state.position); }
|
||
while (ch !== 0 && ch !== 0x3E/* > */);
|
||
|
||
if (state.position < state.length) {
|
||
tagName = state.input.slice(_position, state.position);
|
||
ch = state.input.charCodeAt(++state.position);
|
||
} else {
|
||
throwError(state, 'unexpected end of the stream within a verbatim tag');
|
||
}
|
||
} else {
|
||
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
||
|
||
if (ch === 0x21/* ! */) {
|
||
if (!isNamed) {
|
||
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
||
|
||
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
||
throwError(state, 'named tag handle cannot contain such characters');
|
||
}
|
||
|
||
isNamed = true;
|
||
_position = state.position + 1;
|
||
} else {
|
||
throwError(state, 'tag suffix cannot contain exclamation marks');
|
||
}
|
||
}
|
||
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
tagName = state.input.slice(_position, state.position);
|
||
|
||
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
||
throwError(state, 'tag suffix cannot contain flow indicator characters');
|
||
}
|
||
}
|
||
|
||
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
||
throwError(state, 'tag name cannot contain such characters: ' + tagName);
|
||
}
|
||
|
||
if (isVerbatim) {
|
||
state.tag = tagName;
|
||
|
||
} else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
|
||
state.tag = state.tagMap[tagHandle] + tagName;
|
||
|
||
} else if (tagHandle === '!') {
|
||
state.tag = '!' + tagName;
|
||
|
||
} else if (tagHandle === '!!') {
|
||
state.tag = 'tag:yaml.org,2002:' + tagName;
|
||
|
||
} else {
|
||
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
function readAnchorProperty(state) {
|
||
var _position,
|
||
ch;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch !== 0x26/* & */) { return false; }
|
||
|
||
if (state.anchor !== null) {
|
||
throwError(state, 'duplication of an anchor property');
|
||
}
|
||
|
||
ch = state.input.charCodeAt(++state.position);
|
||
_position = state.position;
|
||
|
||
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
if (state.position === _position) {
|
||
throwError(state, 'name of an anchor node must contain at least one character');
|
||
}
|
||
|
||
state.anchor = state.input.slice(_position, state.position);
|
||
return true;
|
||
}
|
||
|
||
function readAlias(state) {
|
||
var _position, alias,
|
||
ch;
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (ch !== 0x2A/* * */) { return false; }
|
||
|
||
ch = state.input.charCodeAt(++state.position);
|
||
_position = state.position;
|
||
|
||
while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
if (state.position === _position) {
|
||
throwError(state, 'name of an alias node must contain at least one character');
|
||
}
|
||
|
||
alias = state.input.slice(_position, state.position);
|
||
|
||
if (!state.anchorMap.hasOwnProperty(alias)) {
|
||
throwError(state, 'unidentified alias "' + alias + '"');
|
||
}
|
||
|
||
state.result = state.anchorMap[alias];
|
||
skipSeparationSpace(state, true, -1);
|
||
return true;
|
||
}
|
||
|
||
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
||
var allowBlockStyles,
|
||
allowBlockScalars,
|
||
allowBlockCollections,
|
||
indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
|
||
atNewLine = false,
|
||
hasContent = false,
|
||
typeIndex,
|
||
typeQuantity,
|
||
type,
|
||
flowIndent,
|
||
blockIndent;
|
||
|
||
if (state.listener !== null) {
|
||
state.listener('open', state);
|
||
}
|
||
|
||
state.tag = null;
|
||
state.anchor = null;
|
||
state.kind = null;
|
||
state.result = null;
|
||
|
||
allowBlockStyles = allowBlockScalars = allowBlockCollections =
|
||
CONTEXT_BLOCK_OUT === nodeContext ||
|
||
CONTEXT_BLOCK_IN === nodeContext;
|
||
|
||
if (allowToSeek) {
|
||
if (skipSeparationSpace(state, true, -1)) {
|
||
atNewLine = true;
|
||
|
||
if (state.lineIndent > parentIndent) {
|
||
indentStatus = 1;
|
||
} else if (state.lineIndent === parentIndent) {
|
||
indentStatus = 0;
|
||
} else if (state.lineIndent < parentIndent) {
|
||
indentStatus = -1;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (indentStatus === 1) {
|
||
while (readTagProperty(state) || readAnchorProperty(state)) {
|
||
if (skipSeparationSpace(state, true, -1)) {
|
||
atNewLine = true;
|
||
allowBlockCollections = allowBlockStyles;
|
||
|
||
if (state.lineIndent > parentIndent) {
|
||
indentStatus = 1;
|
||
} else if (state.lineIndent === parentIndent) {
|
||
indentStatus = 0;
|
||
} else if (state.lineIndent < parentIndent) {
|
||
indentStatus = -1;
|
||
}
|
||
} else {
|
||
allowBlockCollections = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (allowBlockCollections) {
|
||
allowBlockCollections = atNewLine || allowCompact;
|
||
}
|
||
|
||
if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
||
if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
||
flowIndent = parentIndent;
|
||
} else {
|
||
flowIndent = parentIndent + 1;
|
||
}
|
||
|
||
blockIndent = state.position - state.lineStart;
|
||
|
||
if (indentStatus === 1) {
|
||
if (allowBlockCollections &&
|
||
(readBlockSequence(state, blockIndent) ||
|
||
readBlockMapping(state, blockIndent, flowIndent)) ||
|
||
readFlowCollection(state, flowIndent)) {
|
||
hasContent = true;
|
||
} else {
|
||
if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
|
||
readSingleQuotedScalar(state, flowIndent) ||
|
||
readDoubleQuotedScalar(state, flowIndent)) {
|
||
hasContent = true;
|
||
|
||
} else if (readAlias(state)) {
|
||
hasContent = true;
|
||
|
||
if (state.tag !== null || state.anchor !== null) {
|
||
throwError(state, 'alias node should not have any properties');
|
||
}
|
||
|
||
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
||
hasContent = true;
|
||
|
||
if (state.tag === null) {
|
||
state.tag = '?';
|
||
}
|
||
}
|
||
|
||
if (state.anchor !== null) {
|
||
state.anchorMap[state.anchor] = state.result;
|
||
}
|
||
}
|
||
} else if (indentStatus === 0) {
|
||
// Special case: block sequences are allowed to have same indentation level as the parent.
|
||
// http://www.yaml.org/spec/1.2/spec.html#id2799784
|
||
hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
||
}
|
||
}
|
||
|
||
if (state.tag !== null && state.tag !== '!') {
|
||
if (state.tag === '?') {
|
||
for (typeIndex = 0, typeQuantity = state.implicitTypes.length;
|
||
typeIndex < typeQuantity;
|
||
typeIndex += 1) {
|
||
type = state.implicitTypes[typeIndex];
|
||
|
||
// Implicit resolving is not allowed for non-scalar types, and '?'
|
||
// non-specific tag is only assigned to plain scalars. So, it isn't
|
||
// needed to check for 'kind' conformity.
|
||
|
||
if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
|
||
state.result = type.construct(state.result);
|
||
state.tag = type.tag;
|
||
if (state.anchor !== null) {
|
||
state.anchorMap[state.anchor] = state.result;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
} else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
|
||
type = state.typeMap[state.kind || 'fallback'][state.tag];
|
||
|
||
if (state.result !== null && type.kind !== state.kind) {
|
||
throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
|
||
}
|
||
|
||
if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched
|
||
throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
|
||
} else {
|
||
state.result = type.construct(state.result);
|
||
if (state.anchor !== null) {
|
||
state.anchorMap[state.anchor] = state.result;
|
||
}
|
||
}
|
||
} else {
|
||
throwError(state, 'unknown tag !<' + state.tag + '>');
|
||
}
|
||
}
|
||
|
||
if (state.listener !== null) {
|
||
state.listener('close', state);
|
||
}
|
||
return state.tag !== null || state.anchor !== null || hasContent;
|
||
}
|
||
|
||
function readDocument(state) {
|
||
var documentStart = state.position,
|
||
_position,
|
||
directiveName,
|
||
directiveArgs,
|
||
hasDirectives = false,
|
||
ch;
|
||
|
||
state.version = null;
|
||
state.checkLineBreaks = state.legacy;
|
||
state.tagMap = {};
|
||
state.anchorMap = {};
|
||
|
||
while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
||
skipSeparationSpace(state, true, -1);
|
||
|
||
ch = state.input.charCodeAt(state.position);
|
||
|
||
if (state.lineIndent > 0 || ch !== 0x25/* % */) {
|
||
break;
|
||
}
|
||
|
||
hasDirectives = true;
|
||
ch = state.input.charCodeAt(++state.position);
|
||
_position = state.position;
|
||
|
||
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
directiveName = state.input.slice(_position, state.position);
|
||
directiveArgs = [];
|
||
|
||
if (directiveName.length < 1) {
|
||
throwError(state, 'directive name must not be less than one character in length');
|
||
}
|
||
|
||
while (ch !== 0) {
|
||
while (is_WHITE_SPACE(ch)) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
if (ch === 0x23/* # */) {
|
||
do { ch = state.input.charCodeAt(++state.position); }
|
||
while (ch !== 0 && !is_EOL(ch));
|
||
break;
|
||
}
|
||
|
||
if (is_EOL(ch)) { break; }
|
||
|
||
_position = state.position;
|
||
|
||
while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
||
ch = state.input.charCodeAt(++state.position);
|
||
}
|
||
|
||
directiveArgs.push(state.input.slice(_position, state.position));
|
||
}
|
||
|
||
if (ch !== 0) { readLineBreak(state); }
|
||
|
||
if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
|
||
directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
||
} else {
|
||
throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
||
}
|
||
}
|
||
|
||
skipSeparationSpace(state, true, -1);
|
||
|
||
if (state.lineIndent === 0 &&
|
||
state.input.charCodeAt(state.position) === 0x2D/* - */ &&
|
||
state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
|
||
state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
|
||
state.position += 3;
|
||
skipSeparationSpace(state, true, -1);
|
||
|
||
} else if (hasDirectives) {
|
||
throwError(state, 'directives end mark is expected');
|
||
}
|
||
|
||
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
||
skipSeparationSpace(state, true, -1);
|
||
|
||
if (state.checkLineBreaks &&
|
||
PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
||
throwWarning(state, 'non-ASCII line breaks are interpreted as content');
|
||
}
|
||
|
||
state.documents.push(state.result);
|
||
|
||
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
||
|
||
if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
|
||
state.position += 3;
|
||
skipSeparationSpace(state, true, -1);
|
||
}
|
||
return;
|
||
}
|
||
|
||
if (state.position < (state.length - 1)) {
|
||
throwError(state, 'end of the stream or a document separator is expected');
|
||
} else {
|
||
return;
|
||
}
|
||
}
|
||
|
||
|
||
function loadDocuments(input, options) {
|
||
input = String(input);
|
||
options = options || {};
|
||
|
||
if (input.length !== 0) {
|
||
|
||
// Add tailing `\n` if not exists
|
||
if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ &&
|
||
input.charCodeAt(input.length - 1) !== 0x0D/* CR */) {
|
||
input += '\n';
|
||
}
|
||
|
||
// Strip BOM
|
||
if (input.charCodeAt(0) === 0xFEFF) {
|
||
input = input.slice(1);
|
||
}
|
||
}
|
||
|
||
var state = new State(input, options);
|
||
|
||
// Use 0 as string terminator. That significantly simplifies bounds check.
|
||
state.input += '\0';
|
||
|
||
while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
|
||
state.lineIndent += 1;
|
||
state.position += 1;
|
||
}
|
||
|
||
while (state.position < (state.length - 1)) {
|
||
readDocument(state);
|
||
}
|
||
|
||
return state.documents;
|
||
}
|
||
|
||
|
||
function loadAll$1(input, iterator, options) {
|
||
var documents = loadDocuments(input, options), index, length;
|
||
|
||
for (index = 0, length = documents.length; index < length; index += 1) {
|
||
iterator(documents[index]);
|
||
}
|
||
}
|
||
|
||
|
||
function load$1(input, options) {
|
||
var documents = loadDocuments(input, options);
|
||
|
||
if (documents.length === 0) {
|
||
/*eslint-disable no-undefined*/
|
||
return undefined;
|
||
} else if (documents.length === 1) {
|
||
return documents[0];
|
||
}
|
||
throw new YAMLException$1('expected a single document in the stream, but found more');
|
||
}
|
||
|
||
|
||
function safeLoadAll$1(input, output, options) {
|
||
loadAll$1(input, output, common.extend({ schema: DEFAULT_SAFE_SCHEMA$1 }, options));
|
||
}
|
||
|
||
|
||
function safeLoad$1(input, options) {
|
||
return load$1(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA$1 }, options));
|
||
}
|
||
|
||
|
||
var loadAll_1 = loadAll$1;
|
||
var load_1 = load$1;
|
||
var safeLoadAll_1 = safeLoadAll$1;
|
||
var safeLoad_1 = safeLoad$1;
|
||
|
||
var loader$1 = {
|
||
loadAll: loadAll_1,
|
||
load: load_1,
|
||
safeLoadAll: safeLoadAll_1,
|
||
safeLoad: safeLoad_1
|
||
};
|
||
|
||
var common$7 = common$1;
|
||
var YAMLException$5 = exception;
|
||
var DEFAULT_FULL_SCHEMA$2 = default_full;
|
||
var DEFAULT_SAFE_SCHEMA$2 = default_safe;
|
||
|
||
var _toString$2 = Object.prototype.toString;
|
||
var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
||
|
||
var CHAR_TAB = 0x09; /* Tab */
|
||
var CHAR_LINE_FEED = 0x0A; /* LF */
|
||
var CHAR_SPACE = 0x20; /* Space */
|
||
var CHAR_EXCLAMATION = 0x21; /* ! */
|
||
var CHAR_DOUBLE_QUOTE = 0x22; /* " */
|
||
var CHAR_SHARP = 0x23; /* # */
|
||
var CHAR_PERCENT = 0x25; /* % */
|
||
var CHAR_AMPERSAND = 0x26; /* & */
|
||
var CHAR_SINGLE_QUOTE = 0x27; /* ' */
|
||
var CHAR_ASTERISK = 0x2A; /* * */
|
||
var CHAR_COMMA = 0x2C; /* , */
|
||
var CHAR_MINUS = 0x2D; /* - */
|
||
var CHAR_COLON = 0x3A; /* : */
|
||
var CHAR_GREATER_THAN = 0x3E; /* > */
|
||
var CHAR_QUESTION = 0x3F; /* ? */
|
||
var CHAR_COMMERCIAL_AT = 0x40; /* @ */
|
||
var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
|
||
var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
|
||
var CHAR_GRAVE_ACCENT = 0x60; /* ` */
|
||
var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
|
||
var CHAR_VERTICAL_LINE = 0x7C; /* | */
|
||
var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
|
||
|
||
var ESCAPE_SEQUENCES = {};
|
||
|
||
ESCAPE_SEQUENCES[0x00] = '\\0';
|
||
ESCAPE_SEQUENCES[0x07] = '\\a';
|
||
ESCAPE_SEQUENCES[0x08] = '\\b';
|
||
ESCAPE_SEQUENCES[0x09] = '\\t';
|
||
ESCAPE_SEQUENCES[0x0A] = '\\n';
|
||
ESCAPE_SEQUENCES[0x0B] = '\\v';
|
||
ESCAPE_SEQUENCES[0x0C] = '\\f';
|
||
ESCAPE_SEQUENCES[0x0D] = '\\r';
|
||
ESCAPE_SEQUENCES[0x1B] = '\\e';
|
||
ESCAPE_SEQUENCES[0x22] = '\\"';
|
||
ESCAPE_SEQUENCES[0x5C] = '\\\\';
|
||
ESCAPE_SEQUENCES[0x85] = '\\N';
|
||
ESCAPE_SEQUENCES[0xA0] = '\\_';
|
||
ESCAPE_SEQUENCES[0x2028] = '\\L';
|
||
ESCAPE_SEQUENCES[0x2029] = '\\P';
|
||
|
||
var DEPRECATED_BOOLEANS_SYNTAX = [
|
||
'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
|
||
'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
|
||
];
|
||
|
||
function compileStyleMap(schema, map) {
|
||
var result, keys, index, length, tag, style, type;
|
||
|
||
if (map === null) { return {}; }
|
||
|
||
result = {};
|
||
keys = Object.keys(map);
|
||
|
||
for (index = 0, length = keys.length; index < length; index += 1) {
|
||
tag = keys[index];
|
||
style = String(map[tag]);
|
||
|
||
if (tag.slice(0, 2) === '!!') {
|
||
tag = 'tag:yaml.org,2002:' + tag.slice(2);
|
||
}
|
||
type = schema.compiledTypeMap['fallback'][tag];
|
||
|
||
if (type && _hasOwnProperty$3.call(type.styleAliases, style)) {
|
||
style = type.styleAliases[style];
|
||
}
|
||
|
||
result[tag] = style;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
function encodeHex(character) {
|
||
var string, handle, length;
|
||
|
||
string = character.toString(16).toUpperCase();
|
||
|
||
if (character <= 0xFF) {
|
||
handle = 'x';
|
||
length = 2;
|
||
} else if (character <= 0xFFFF) {
|
||
handle = 'u';
|
||
length = 4;
|
||
} else if (character <= 0xFFFFFFFF) {
|
||
handle = 'U';
|
||
length = 8;
|
||
} else {
|
||
throw new YAMLException$5('code point within a string may not be greater than 0xFFFFFFFF');
|
||
}
|
||
|
||
return '\\' + handle + common$7.repeat('0', length - string.length) + string;
|
||
}
|
||
|
||
function State$1(options) {
|
||
this.schema = options['schema'] || DEFAULT_FULL_SCHEMA$2;
|
||
this.indent = Math.max(1, (options['indent'] || 2));
|
||
this.skipInvalid = options['skipInvalid'] || false;
|
||
this.flowLevel = (common$7.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
|
||
this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
|
||
this.sortKeys = options['sortKeys'] || false;
|
||
this.lineWidth = options['lineWidth'] || 80;
|
||
this.noRefs = options['noRefs'] || false;
|
||
this.noCompatMode = options['noCompatMode'] || false;
|
||
|
||
this.implicitTypes = this.schema.compiledImplicit;
|
||
this.explicitTypes = this.schema.compiledExplicit;
|
||
|
||
this.tag = null;
|
||
this.result = '';
|
||
|
||
this.duplicates = [];
|
||
this.usedDuplicates = null;
|
||
}
|
||
|
||
// Indents every line in a string. Empty lines (\n only) are not indented.
|
||
function indentString(string, spaces) {
|
||
var ind = common$7.repeat(' ', spaces),
|
||
position = 0,
|
||
next = -1,
|
||
result = '',
|
||
line,
|
||
length = string.length;
|
||
|
||
while (position < length) {
|
||
next = string.indexOf('\n', position);
|
||
if (next === -1) {
|
||
line = string.slice(position);
|
||
position = length;
|
||
} else {
|
||
line = string.slice(position, next + 1);
|
||
position = next + 1;
|
||
}
|
||
|
||
if (line.length && line !== '\n') { result += ind; }
|
||
|
||
result += line;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
function generateNextLine(state, level) {
|
||
return '\n' + common$7.repeat(' ', state.indent * level);
|
||
}
|
||
|
||
function testImplicitResolving(state, str) {
|
||
var index, length, type;
|
||
|
||
for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
|
||
type = state.implicitTypes[index];
|
||
|
||
if (type.resolve(str)) {
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
// [33] s-white ::= s-space | s-tab
|
||
function isWhitespace(c) {
|
||
return c === CHAR_SPACE || c === CHAR_TAB;
|
||
}
|
||
|
||
// Returns true if the character can be printed without escaping.
|
||
// From YAML 1.2: "any allowed characters known to be non-printable
|
||
// should also be escaped. [However,] This isn’t mandatory"
|
||
// Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
|
||
function isPrintable(c) {
|
||
return (0x00020 <= c && c <= 0x00007E)
|
||
|| ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
|
||
|| ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF /* BOM */)
|
||
|| (0x10000 <= c && c <= 0x10FFFF);
|
||
}
|
||
|
||
// Simplified test for values allowed after the first character in plain style.
|
||
function isPlainSafe(c) {
|
||
// Uses a subset of nb-char - c-flow-indicator - ":" - "#"
|
||
// where nb-char ::= c-printable - b-char - c-byte-order-mark.
|
||
return isPrintable(c) && c !== 0xFEFF
|
||
// - c-flow-indicator
|
||
&& c !== CHAR_COMMA
|
||
&& c !== CHAR_LEFT_SQUARE_BRACKET
|
||
&& c !== CHAR_RIGHT_SQUARE_BRACKET
|
||
&& c !== CHAR_LEFT_CURLY_BRACKET
|
||
&& c !== CHAR_RIGHT_CURLY_BRACKET
|
||
// - ":" - "#"
|
||
&& c !== CHAR_COLON
|
||
&& c !== CHAR_SHARP;
|
||
}
|
||
|
||
// Simplified test for values allowed as the first character in plain style.
|
||
function isPlainSafeFirst(c) {
|
||
// Uses a subset of ns-char - c-indicator
|
||
// where ns-char = nb-char - s-white.
|
||
return isPrintable(c) && c !== 0xFEFF
|
||
&& !isWhitespace(c) // - s-white
|
||
// - (c-indicator ::=
|
||
// “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
|
||
&& c !== CHAR_MINUS
|
||
&& c !== CHAR_QUESTION
|
||
&& c !== CHAR_COLON
|
||
&& c !== CHAR_COMMA
|
||
&& c !== CHAR_LEFT_SQUARE_BRACKET
|
||
&& c !== CHAR_RIGHT_SQUARE_BRACKET
|
||
&& c !== CHAR_LEFT_CURLY_BRACKET
|
||
&& c !== CHAR_RIGHT_CURLY_BRACKET
|
||
// | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
|
||
&& c !== CHAR_SHARP
|
||
&& c !== CHAR_AMPERSAND
|
||
&& c !== CHAR_ASTERISK
|
||
&& c !== CHAR_EXCLAMATION
|
||
&& c !== CHAR_VERTICAL_LINE
|
||
&& c !== CHAR_GREATER_THAN
|
||
&& c !== CHAR_SINGLE_QUOTE
|
||
&& c !== CHAR_DOUBLE_QUOTE
|
||
// | “%” | “@” | “`”)
|
||
&& c !== CHAR_PERCENT
|
||
&& c !== CHAR_COMMERCIAL_AT
|
||
&& c !== CHAR_GRAVE_ACCENT;
|
||
}
|
||
|
||
var STYLE_PLAIN = 1;
|
||
var STYLE_SINGLE = 2;
|
||
var STYLE_LITERAL = 3;
|
||
var STYLE_FOLDED = 4;
|
||
var STYLE_DOUBLE = 5;
|
||
|
||
// Determines which scalar styles are possible and returns the preferred style.
|
||
// lineWidth = -1 => no limit.
|
||
// Pre-conditions: str.length > 0.
|
||
// Post-conditions:
|
||
// STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
|
||
// STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
|
||
// STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
|
||
function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
|
||
var i;
|
||
var char;
|
||
var hasLineBreak = false;
|
||
var hasFoldableLine = false; // only checked if shouldTrackWidth
|
||
var shouldTrackWidth = lineWidth !== -1;
|
||
var previousLineBreak = -1; // count the first line correctly
|
||
var plain = isPlainSafeFirst(string.charCodeAt(0))
|
||
&& !isWhitespace(string.charCodeAt(string.length - 1));
|
||
|
||
if (singleLineOnly) {
|
||
// Case: no block styles.
|
||
// Check for disallowed characters to rule out plain and single.
|
||
for (i = 0; i < string.length; i++) {
|
||
char = string.charCodeAt(i);
|
||
if (!isPrintable(char)) {
|
||
return STYLE_DOUBLE;
|
||
}
|
||
plain = plain && isPlainSafe(char);
|
||
}
|
||
} else {
|
||
// Case: block styles permitted.
|
||
for (i = 0; i < string.length; i++) {
|
||
char = string.charCodeAt(i);
|
||
if (char === CHAR_LINE_FEED) {
|
||
hasLineBreak = true;
|
||
// Check if any line can be folded.
|
||
if (shouldTrackWidth) {
|
||
hasFoldableLine = hasFoldableLine ||
|
||
// Foldable line = too long, and not more-indented.
|
||
(i - previousLineBreak - 1 > lineWidth &&
|
||
string[previousLineBreak + 1] !== ' ');
|
||
previousLineBreak = i;
|
||
}
|
||
} else if (!isPrintable(char)) {
|
||
return STYLE_DOUBLE;
|
||
}
|
||
plain = plain && isPlainSafe(char);
|
||
}
|
||
// in case the end is missing a \n
|
||
hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
|
||
(i - previousLineBreak - 1 > lineWidth &&
|
||
string[previousLineBreak + 1] !== ' '));
|
||
}
|
||
// Although every style can represent \n without escaping, prefer block styles
|
||
// for multiline, since they're more readable and they don't add empty lines.
|
||
// Also prefer folding a super-long line.
|
||
if (!hasLineBreak && !hasFoldableLine) {
|
||
// Strings interpretable as another type have to be quoted;
|
||
// e.g. the string 'true' vs. the boolean true.
|
||
return plain && !testAmbiguousType(string)
|
||
? STYLE_PLAIN : STYLE_SINGLE;
|
||
}
|
||
// Edge case: block indentation indicator can only have one digit.
|
||
if (string[0] === ' ' && indentPerLevel > 9) {
|
||
return STYLE_DOUBLE;
|
||
}
|
||
// At this point we know block styles are valid.
|
||
// Prefer literal style unless we want to fold.
|
||
return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
||
}
|
||
|
||
// Note: line breaking/folding is implemented for only the folded style.
|
||
// NB. We drop the last trailing newline (if any) of a returned block scalar
|
||
// since the dumper adds its own newline. This always works:
|
||
// • No ending newline => unaffected; already using strip "-" chomping.
|
||
// • Ending newline => removed then restored.
|
||
// Importantly, this keeps the "+" chomp indicator from gaining an extra line.
|
||
function writeScalar(state, string, level, iskey) {
|
||
state.dump = (function () {
|
||
if (string.length === 0) {
|
||
return "''";
|
||
}
|
||
if (!state.noCompatMode &&
|
||
DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
|
||
return "'" + string + "'";
|
||
}
|
||
|
||
var indent = state.indent * Math.max(1, level); // no 0-indent scalars
|
||
// As indentation gets deeper, let the width decrease monotonically
|
||
// to the lower bound min(state.lineWidth, 40).
|
||
// Note that this implies
|
||
// state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
|
||
// state.lineWidth > 40 + state.indent: width decreases until the lower bound.
|
||
// This behaves better than a constant minimum width which disallows narrower options,
|
||
// or an indent threshold which causes the width to suddenly increase.
|
||
var lineWidth = state.lineWidth === -1
|
||
? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
||
|
||
// Without knowing if keys are implicit/explicit, assume implicit for safety.
|
||
var singleLineOnly = iskey
|
||
// No block styles in flow mode.
|
||
|| (state.flowLevel > -1 && level >= state.flowLevel);
|
||
function testAmbiguity(string) {
|
||
return testImplicitResolving(state, string);
|
||
}
|
||
|
||
switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
|
||
case STYLE_PLAIN:
|
||
return string;
|
||
case STYLE_SINGLE:
|
||
return "'" + string.replace(/'/g, "''") + "'";
|
||
case STYLE_LITERAL:
|
||
return '|' + blockHeader(string, state.indent)
|
||
+ dropEndingNewline(indentString(string, indent));
|
||
case STYLE_FOLDED:
|
||
return '>' + blockHeader(string, state.indent)
|
||
+ dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
||
case STYLE_DOUBLE:
|
||
return '"' + escapeString(string, lineWidth) + '"';
|
||
default:
|
||
throw new YAMLException$5('impossible error: invalid scalar style');
|
||
}
|
||
}());
|
||
}
|
||
|
||
// Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
|
||
function blockHeader(string, indentPerLevel) {
|
||
var indentIndicator = (string[0] === ' ') ? String(indentPerLevel) : '';
|
||
|
||
// note the special case: the string '\n' counts as a "trailing" empty line.
|
||
var clip = string[string.length - 1] === '\n';
|
||
var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
|
||
var chomp = keep ? '+' : (clip ? '' : '-');
|
||
|
||
return indentIndicator + chomp + '\n';
|
||
}
|
||
|
||
// (See the note for writeScalar.)
|
||
function dropEndingNewline(string) {
|
||
return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
|
||
}
|
||
|
||
// Note: a long line without a suitable break point will exceed the width limit.
|
||
// Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
|
||
function foldString(string, width) {
|
||
// In folded style, $k$ consecutive newlines output as $k+1$ newlines—
|
||
// unless they're before or after a more-indented line, or at the very
|
||
// beginning or end, in which case $k$ maps to $k$.
|
||
// Therefore, parse each chunk as newline(s) followed by a content line.
|
||
var lineRe = /(\n+)([^\n]*)/g;
|
||
|
||
// first line (possibly an empty line)
|
||
var result = (function () {
|
||
var nextLF = string.indexOf('\n');
|
||
nextLF = nextLF !== -1 ? nextLF : string.length;
|
||
lineRe.lastIndex = nextLF;
|
||
return foldLine(string.slice(0, nextLF), width);
|
||
}());
|
||
// If we haven't reached the first content line yet, don't add an extra \n.
|
||
var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
|
||
var moreIndented;
|
||
|
||
// rest of the lines
|
||
var match;
|
||
while ((match = lineRe.exec(string))) {
|
||
var prefix = match[1], line = match[2];
|
||
moreIndented = (line[0] === ' ');
|
||
result += prefix
|
||
+ (!prevMoreIndented && !moreIndented && line !== ''
|
||
? '\n' : '')
|
||
+ foldLine(line, width);
|
||
prevMoreIndented = moreIndented;
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
// Greedy line breaking.
|
||
// Picks the longest line under the limit each time,
|
||
// otherwise settles for the shortest line over the limit.
|
||
// NB. More-indented lines *cannot* be folded, as that would add an extra \n.
|
||
function foldLine(line, width) {
|
||
if (line === '' || line[0] === ' ') { return line; }
|
||
|
||
// Since a more-indented line adds a \n, breaks can't be followed by a space.
|
||
var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
|
||
var match;
|
||
// start is an inclusive index. end, curr, and next are exclusive.
|
||
var start = 0, end, curr = 0, next = 0;
|
||
var result = '';
|
||
|
||
// Invariants: 0 <= start <= length-1.
|
||
// 0 <= curr <= next <= max(0, length-2). curr - start <= width.
|
||
// Inside the loop:
|
||
// A match implies length >= 2, so curr and next are <= length-2.
|
||
while ((match = breakRe.exec(line))) {
|
||
next = match.index;
|
||
// maintain invariant: curr - start <= width
|
||
if (next - start > width) {
|
||
end = (curr > start) ? curr : next; // derive end <= length-2
|
||
result += '\n' + line.slice(start, end);
|
||
// skip the space that was output as \n
|
||
start = end + 1; // derive start <= length-1
|
||
}
|
||
curr = next;
|
||
}
|
||
|
||
// By the invariants, start <= length-1, so there is something left over.
|
||
// It is either the whole string or a part starting from non-whitespace.
|
||
result += '\n';
|
||
// Insert a break if the remainder is too long and there is a break available.
|
||
if (line.length - start > width && curr > start) {
|
||
result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
|
||
} else {
|
||
result += line.slice(start);
|
||
}
|
||
|
||
return result.slice(1); // drop extra \n joiner
|
||
}
|
||
|
||
// Escapes a double-quoted string.
|
||
function escapeString(string) {
|
||
var result = '';
|
||
var char;
|
||
var escapeSeq;
|
||
|
||
for (var i = 0; i < string.length; i++) {
|
||
char = string.charCodeAt(i);
|
||
escapeSeq = ESCAPE_SEQUENCES[char];
|
||
result += !escapeSeq && isPrintable(char)
|
||
? string[i]
|
||
: escapeSeq || encodeHex(char);
|
||
}
|
||
|
||
return result;
|
||
}
|
||
|
||
function writeFlowSequence(state, level, object) {
|
||
var _result = '',
|
||
_tag = state.tag,
|
||
index,
|
||
length;
|
||
|
||
for (index = 0, length = object.length; index < length; index += 1) {
|
||
// Write only valid elements.
|
||
if (writeNode(state, level, object[index], false, false)) {
|
||
if (index !== 0) { _result += ', '; }
|
||
_result += state.dump;
|
||
}
|
||
}
|
||
|
||
state.tag = _tag;
|
||
state.dump = '[' + _result + ']';
|
||
}
|
||
|
||
function writeBlockSequence(state, level, object, compact) {
|
||
var _result = '',
|
||
_tag = state.tag,
|
||
index,
|
||
length;
|
||
|
||
for (index = 0, length = object.length; index < length; index += 1) {
|
||
// Write only valid elements.
|
||
if (writeNode(state, level + 1, object[index], true, true)) {
|
||
if (!compact || index !== 0) {
|
||
_result += generateNextLine(state, level);
|
||
}
|
||
_result += '- ' + state.dump;
|
||
}
|
||
}
|
||
|
||
state.tag = _tag;
|
||
state.dump = _result || '[]'; // Empty sequence if no valid values.
|
||
}
|
||
|
||
function writeFlowMapping(state, level, object) {
|
||
var _result = '',
|
||
_tag = state.tag,
|
||
objectKeyList = Object.keys(object),
|
||
index,
|
||
length,
|
||
objectKey,
|
||
objectValue,
|
||
pairBuffer;
|
||
|
||
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
||
pairBuffer = '';
|
||
|
||
if (index !== 0) { pairBuffer += ', '; }
|
||
|
||
objectKey = objectKeyList[index];
|
||
objectValue = object[objectKey];
|
||
|
||
if (!writeNode(state, level, objectKey, false, false)) {
|
||
continue; // Skip this pair because of invalid key;
|
||
}
|
||
|
||
if (state.dump.length > 1024) { pairBuffer += '? '; }
|
||
|
||
pairBuffer += state.dump + ': ';
|
||
|
||
if (!writeNode(state, level, objectValue, false, false)) {
|
||
continue; // Skip this pair because of invalid value.
|
||
}
|
||
|
||
pairBuffer += state.dump;
|
||
|
||
// Both key and value are valid.
|
||
_result += pairBuffer;
|
||
}
|
||
|
||
state.tag = _tag;
|
||
state.dump = '{' + _result + '}';
|
||
}
|
||
|
||
function writeBlockMapping(state, level, object, compact) {
|
||
var _result = '',
|
||
_tag = state.tag,
|
||
objectKeyList = Object.keys(object),
|
||
index,
|
||
length,
|
||
objectKey,
|
||
objectValue,
|
||
explicitPair,
|
||
pairBuffer;
|
||
|
||
// Allow sorting keys so that the output file is deterministic
|
||
if (state.sortKeys === true) {
|
||
// Default sorting
|
||
objectKeyList.sort();
|
||
} else if (typeof state.sortKeys === 'function') {
|
||
// Custom sort function
|
||
objectKeyList.sort(state.sortKeys);
|
||
} else if (state.sortKeys) {
|
||
// Something is wrong
|
||
throw new YAMLException$5('sortKeys must be a boolean or a function');
|
||
}
|
||
|
||
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
||
pairBuffer = '';
|
||
|
||
if (!compact || index !== 0) {
|
||
pairBuffer += generateNextLine(state, level);
|
||
}
|
||
|
||
objectKey = objectKeyList[index];
|
||
objectValue = object[objectKey];
|
||
|
||
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
||
continue; // Skip this pair because of invalid key.
|
||
}
|
||
|
||
explicitPair = (state.tag !== null && state.tag !== '?') ||
|
||
(state.dump && state.dump.length > 1024);
|
||
|
||
if (explicitPair) {
|
||
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
||
pairBuffer += '?';
|
||
} else {
|
||
pairBuffer += '? ';
|
||
}
|
||
}
|
||
|
||
pairBuffer += state.dump;
|
||
|
||
if (explicitPair) {
|
||
pairBuffer += generateNextLine(state, level);
|
||
}
|
||
|
||
if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
||
continue; // Skip this pair because of invalid value.
|
||
}
|
||
|
||
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
||
pairBuffer += ':';
|
||
} else {
|
||
pairBuffer += ': ';
|
||
}
|
||
|
||
pairBuffer += state.dump;
|
||
|
||
// Both key and value are valid.
|
||
_result += pairBuffer;
|
||
}
|
||
|
||
state.tag = _tag;
|
||
state.dump = _result || '{}'; // Empty mapping if no valid pairs.
|
||
}
|
||
|
||
function detectType(state, object, explicit) {
|
||
var _result, typeList, index, length, type, style;
|
||
|
||
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
||
|
||
for (index = 0, length = typeList.length; index < length; index += 1) {
|
||
type = typeList[index];
|
||
|
||
if ((type.instanceOf || type.predicate) &&
|
||
(!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
|
||
(!type.predicate || type.predicate(object))) {
|
||
|
||
state.tag = explicit ? type.tag : '?';
|
||
|
||
if (type.represent) {
|
||
style = state.styleMap[type.tag] || type.defaultStyle;
|
||
|
||
if (_toString$2.call(type.represent) === '[object Function]') {
|
||
_result = type.represent(object, style);
|
||
} else if (_hasOwnProperty$3.call(type.represent, style)) {
|
||
_result = type.represent[style](object, style);
|
||
} else {
|
||
throw new YAMLException$5('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
|
||
}
|
||
|
||
state.dump = _result;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
// Serializes `object` and writes it to global `result`.
|
||
// Returns true on success, or false on invalid object.
|
||
//
|
||
function writeNode(state, level, object, block, compact, iskey) {
|
||
state.tag = null;
|
||
state.dump = object;
|
||
|
||
if (!detectType(state, object, false)) {
|
||
detectType(state, object, true);
|
||
}
|
||
|
||
var type = _toString$2.call(state.dump);
|
||
|
||
if (block) {
|
||
block = (state.flowLevel < 0 || state.flowLevel > level);
|
||
}
|
||
|
||
var objectOrArray = type === '[object Object]' || type === '[object Array]',
|
||
duplicateIndex,
|
||
duplicate;
|
||
|
||
if (objectOrArray) {
|
||
duplicateIndex = state.duplicates.indexOf(object);
|
||
duplicate = duplicateIndex !== -1;
|
||
}
|
||
|
||
if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
|
||
compact = false;
|
||
}
|
||
|
||
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
||
state.dump = '*ref_' + duplicateIndex;
|
||
} else {
|
||
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
||
state.usedDuplicates[duplicateIndex] = true;
|
||
}
|
||
if (type === '[object Object]') {
|
||
if (block && (Object.keys(state.dump).length !== 0)) {
|
||
writeBlockMapping(state, level, state.dump, compact);
|
||
if (duplicate) {
|
||
state.dump = '&ref_' + duplicateIndex + state.dump;
|
||
}
|
||
} else {
|
||
writeFlowMapping(state, level, state.dump);
|
||
if (duplicate) {
|
||
state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
|
||
}
|
||
}
|
||
} else if (type === '[object Array]') {
|
||
if (block && (state.dump.length !== 0)) {
|
||
writeBlockSequence(state, level, state.dump, compact);
|
||
if (duplicate) {
|
||
state.dump = '&ref_' + duplicateIndex + state.dump;
|
||
}
|
||
} else {
|
||
writeFlowSequence(state, level, state.dump);
|
||
if (duplicate) {
|
||
state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
|
||
}
|
||
}
|
||
} else if (type === '[object String]') {
|
||
if (state.tag !== '?') {
|
||
writeScalar(state, state.dump, level, iskey);
|
||
}
|
||
} else {
|
||
if (state.skipInvalid) { return false; }
|
||
throw new YAMLException$5('unacceptable kind of an object to dump ' + type);
|
||
}
|
||
|
||
if (state.tag !== null && state.tag !== '?') {
|
||
state.dump = '!<' + state.tag + '> ' + state.dump;
|
||
}
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
function getDuplicateReferences(object, state) {
|
||
var objects = [],
|
||
duplicatesIndexes = [],
|
||
index,
|
||
length;
|
||
|
||
inspectNode(object, objects, duplicatesIndexes);
|
||
|
||
for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
|
||
state.duplicates.push(objects[duplicatesIndexes[index]]);
|
||
}
|
||
state.usedDuplicates = new Array(length);
|
||
}
|
||
|
||
function inspectNode(object, objects, duplicatesIndexes) {
|
||
var objectKeyList,
|
||
index,
|
||
length;
|
||
|
||
if (object !== null && typeof object === 'object') {
|
||
index = objects.indexOf(object);
|
||
if (index !== -1) {
|
||
if (duplicatesIndexes.indexOf(index) === -1) {
|
||
duplicatesIndexes.push(index);
|
||
}
|
||
} else {
|
||
objects.push(object);
|
||
|
||
if (Array.isArray(object)) {
|
||
for (index = 0, length = object.length; index < length; index += 1) {
|
||
inspectNode(object[index], objects, duplicatesIndexes);
|
||
}
|
||
} else {
|
||
objectKeyList = Object.keys(object);
|
||
|
||
for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
||
inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function dump$1(input, options) {
|
||
options = options || {};
|
||
|
||
var state = new State$1(options);
|
||
|
||
if (!state.noRefs) { getDuplicateReferences(input, state); }
|
||
|
||
if (writeNode(state, 0, input, true, true)) { return state.dump + '\n'; }
|
||
|
||
return '';
|
||
}
|
||
|
||
function safeDump$1(input, options) {
|
||
return dump$1(input, common$7.extend({ schema: DEFAULT_SAFE_SCHEMA$2 }, options));
|
||
}
|
||
|
||
var dump_1 = dump$1;
|
||
var safeDump_1 = safeDump$1;
|
||
|
||
var dumper$1 = {
|
||
dump: dump_1,
|
||
safeDump: safeDump_1
|
||
};
|
||
|
||
var loader = loader$1;
|
||
var dumper = dumper$1;
|
||
|
||
|
||
function deprecated(name) {
|
||
return function () {
|
||
throw new Error('Function ' + name + ' is deprecated and cannot be used.');
|
||
};
|
||
}
|
||
|
||
|
||
var Type = type;
|
||
var Schema = schema;
|
||
var FAILSAFE_SCHEMA = failsafe;
|
||
var JSON_SCHEMA = json;
|
||
var CORE_SCHEMA = core;
|
||
var DEFAULT_SAFE_SCHEMA = default_safe;
|
||
var DEFAULT_FULL_SCHEMA = default_full;
|
||
var load = loader.load;
|
||
var loadAll = loader.loadAll;
|
||
var safeLoad = loader.safeLoad;
|
||
var safeLoadAll = loader.safeLoadAll;
|
||
var dump = dumper.dump;
|
||
var safeDump = dumper.safeDump;
|
||
var YAMLException = exception;
|
||
|
||
// Deprecated schema names from JS-YAML 2.0.x
|
||
var MINIMAL_SCHEMA = failsafe;
|
||
var SAFE_SCHEMA = default_safe;
|
||
var DEFAULT_SCHEMA = default_full;
|
||
|
||
// Deprecated functions from JS-YAML 1.x.x
|
||
var scan$1 = deprecated('scan');
|
||
var parse$1 = deprecated('parse');
|
||
var compose = deprecated('compose');
|
||
var addConstructor = deprecated('addConstructor');
|
||
|
||
var jsYaml = {
|
||
Type: Type,
|
||
Schema: Schema,
|
||
FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
|
||
JSON_SCHEMA: JSON_SCHEMA,
|
||
CORE_SCHEMA: CORE_SCHEMA,
|
||
DEFAULT_SAFE_SCHEMA: DEFAULT_SAFE_SCHEMA,
|
||
DEFAULT_FULL_SCHEMA: DEFAULT_FULL_SCHEMA,
|
||
load: load,
|
||
loadAll: loadAll,
|
||
safeLoad: safeLoad,
|
||
safeLoadAll: safeLoadAll,
|
||
dump: dump,
|
||
safeDump: safeDump,
|
||
YAMLException: YAMLException,
|
||
MINIMAL_SCHEMA: MINIMAL_SCHEMA,
|
||
SAFE_SCHEMA: SAFE_SCHEMA,
|
||
DEFAULT_SCHEMA: DEFAULT_SCHEMA,
|
||
scan: scan$1,
|
||
parse: parse$1,
|
||
compose: compose,
|
||
addConstructor: addConstructor
|
||
};
|
||
|
||
var yaml = jsYaml;
|
||
|
||
|
||
var index = yaml;
|
||
|
||
var frontMatter = function(dom, data) {
|
||
var localData = {};
|
||
var el = dom.querySelector('script[type="text/front-matter"]');
|
||
if (el) {
|
||
var text = el.textContent;
|
||
localData = index.safeLoad(text);
|
||
}
|
||
|
||
data.title = localData.title ? localData.title : "Untitled";
|
||
data.description = localData.description ? localData.description : "No description.";
|
||
|
||
data.authors = localData.authors ? localData.authors : [];
|
||
|
||
data.authors = data.authors.map(function (author, i) {
|
||
var a = {};
|
||
var name = Object.keys(author)[0];
|
||
if ((typeof author) === "string") {
|
||
name = author;
|
||
} else {
|
||
a.personalURL = author[name];
|
||
}
|
||
var names = name.split(" ");
|
||
a.name = name;
|
||
a.firstName = names.slice(0, names.length - 1).join(" ");
|
||
a.lastName = names[names.length -1];
|
||
if(localData.affiliations[i]) {
|
||
var affiliation = Object.keys(localData.affiliations[i])[0];
|
||
if ((typeof localData.affiliations[i]) === "string") {
|
||
affiliation = localData.affiliations[i];
|
||
} else {
|
||
a.affiliationURL = localData.affiliations[i][affiliation];
|
||
}
|
||
a.affiliation = affiliation;
|
||
}
|
||
return a;
|
||
});
|
||
|
||
|
||
};
|
||
|
||
var bibtexParse = createCommonjsModule(function (module, exports) {
|
||
/* start bibtexParse 0.0.22 */
|
||
|
||
//Original work by Henrik Muehe (c) 2010
|
||
//
|
||
//CommonJS port by Mikola Lysenko 2013
|
||
//
|
||
//Port to Browser lib by ORCID / RCPETERS
|
||
//
|
||
//Issues:
|
||
//no comment handling within strings
|
||
//no string concatenation
|
||
//no variable values yet
|
||
//Grammar implemented here:
|
||
//bibtex -> (string | preamble | comment | entry)*;
|
||
//string -> '@STRING' '{' key_equals_value '}';
|
||
//preamble -> '@PREAMBLE' '{' value '}';
|
||
//comment -> '@COMMENT' '{' value '}';
|
||
//entry -> '@' key '{' key ',' key_value_list '}';
|
||
//key_value_list -> key_equals_value (',' key_equals_value)*;
|
||
//key_equals_value -> key '=' value;
|
||
//value -> value_quotes | value_braces | key;
|
||
//value_quotes -> '"' .*? '"'; // not quite
|
||
//value_braces -> '{' .*? '"'; // not quite
|
||
(function(exports) {
|
||
|
||
function BibtexParser() {
|
||
|
||
this.months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
||
this.notKey = [',','{','}',' ','='];
|
||
this.pos = 0;
|
||
this.input = "";
|
||
this.entries = new Array();
|
||
|
||
this.currentEntry = "";
|
||
|
||
this.setInput = function(t) {
|
||
this.input = t;
|
||
};
|
||
|
||
this.getEntries = function() {
|
||
return this.entries;
|
||
};
|
||
|
||
this.isWhitespace = function(s) {
|
||
return (s == ' ' || s == '\r' || s == '\t' || s == '\n');
|
||
};
|
||
|
||
this.match = function(s, canCommentOut) {
|
||
if (canCommentOut == undefined || canCommentOut == null)
|
||
{ canCommentOut = true; }
|
||
this.skipWhitespace(canCommentOut);
|
||
if (this.input.substring(this.pos, this.pos + s.length) == s) {
|
||
this.pos += s.length;
|
||
} else {
|
||
throw "Token mismatch, expected " + s + ", found "
|
||
+ this.input.substring(this.pos);
|
||
}
|
||
this.skipWhitespace(canCommentOut);
|
||
};
|
||
|
||
this.tryMatch = function(s, canCommentOut) {
|
||
if (canCommentOut == undefined || canCommentOut == null)
|
||
{ canCommentOut = true; }
|
||
this.skipWhitespace(canCommentOut);
|
||
if (this.input.substring(this.pos, this.pos + s.length) == s) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
this.skipWhitespace(canCommentOut);
|
||
};
|
||
|
||
/* when search for a match all text can be ignored, not just white space */
|
||
this.matchAt = function() {
|
||
var this$1 = this;
|
||
|
||
while (this.input.length > this.pos && this.input[this.pos] != '@') {
|
||
this$1.pos++;
|
||
}
|
||
|
||
if (this.input[this.pos] == '@') {
|
||
return true;
|
||
}
|
||
return false;
|
||
};
|
||
|
||
this.skipWhitespace = function(canCommentOut) {
|
||
var this$1 = this;
|
||
|
||
while (this.isWhitespace(this.input[this.pos])) {
|
||
this$1.pos++;
|
||
}
|
||
if (this.input[this.pos] == "%" && canCommentOut == true) {
|
||
while (this.input[this.pos] != "\n") {
|
||
this$1.pos++;
|
||
}
|
||
this.skipWhitespace(canCommentOut);
|
||
}
|
||
};
|
||
|
||
this.value_braces = function() {
|
||
var this$1 = this;
|
||
|
||
var bracecount = 0;
|
||
this.match("{", false);
|
||
var start = this.pos;
|
||
var escaped = false;
|
||
while (true) {
|
||
if (!escaped) {
|
||
if (this$1.input[this$1.pos] == '}') {
|
||
if (bracecount > 0) {
|
||
bracecount--;
|
||
} else {
|
||
var end = this$1.pos;
|
||
this$1.match("}", false);
|
||
return this$1.input.substring(start, end);
|
||
}
|
||
} else if (this$1.input[this$1.pos] == '{') {
|
||
bracecount++;
|
||
} else if (this$1.pos >= this$1.input.length - 1) {
|
||
throw "Unterminated value";
|
||
}
|
||
}
|
||
if (this$1.input[this$1.pos] == '\\' && escaped == false)
|
||
{ escaped = true; }
|
||
else
|
||
{ escaped = false; }
|
||
this$1.pos++;
|
||
}
|
||
};
|
||
|
||
this.value_comment = function() {
|
||
var this$1 = this;
|
||
|
||
var str = '';
|
||
var brcktCnt = 0;
|
||
while (!(this.tryMatch("}", false) && brcktCnt == 0)) {
|
||
str = str + this$1.input[this$1.pos];
|
||
if (this$1.input[this$1.pos] == '{')
|
||
{ brcktCnt++; }
|
||
if (this$1.input[this$1.pos] == '}')
|
||
{ brcktCnt--; }
|
||
if (this$1.pos >= this$1.input.length - 1) {
|
||
throw "Unterminated value:" + this$1.input.substring(start);
|
||
}
|
||
this$1.pos++;
|
||
}
|
||
return str;
|
||
};
|
||
|
||
this.value_quotes = function() {
|
||
var this$1 = this;
|
||
|
||
this.match('"', false);
|
||
var start = this.pos;
|
||
var escaped = false;
|
||
while (true) {
|
||
if (!escaped) {
|
||
if (this$1.input[this$1.pos] == '"') {
|
||
var end = this$1.pos;
|
||
this$1.match('"', false);
|
||
return this$1.input.substring(start, end);
|
||
} else if (this$1.pos >= this$1.input.length - 1) {
|
||
throw "Unterminated value:" + this$1.input.substring(start);
|
||
}
|
||
}
|
||
if (this$1.input[this$1.pos] == '\\' && escaped == false)
|
||
{ escaped = true; }
|
||
else
|
||
{ escaped = false; }
|
||
this$1.pos++;
|
||
}
|
||
};
|
||
|
||
this.single_value = function() {
|
||
var start = this.pos;
|
||
if (this.tryMatch("{")) {
|
||
return this.value_braces();
|
||
} else if (this.tryMatch('"')) {
|
||
return this.value_quotes();
|
||
} else {
|
||
var k = this.key();
|
||
if (k.match("^[0-9]+$"))
|
||
{ return k; }
|
||
else if (this.months.indexOf(k.toLowerCase()) >= 0)
|
||
{ return k.toLowerCase(); }
|
||
else
|
||
{ throw "Value expected:" + this.input.substring(start) + ' for key: ' + k; }
|
||
|
||
}
|
||
};
|
||
|
||
this.value = function() {
|
||
var this$1 = this;
|
||
|
||
var values = [];
|
||
values.push(this.single_value());
|
||
while (this.tryMatch("#")) {
|
||
this$1.match("#");
|
||
values.push(this$1.single_value());
|
||
}
|
||
return values.join("");
|
||
};
|
||
|
||
this.key = function() {
|
||
var this$1 = this;
|
||
|
||
var start = this.pos;
|
||
while (true) {
|
||
if (this$1.pos >= this$1.input.length) {
|
||
throw "Runaway key";
|
||
}
|
||
// а-яА-Я is Cyrillic
|
||
//console.log(this.input[this.pos]);
|
||
if (this$1.notKey.indexOf(this$1.input[this$1.pos]) >= 0) {
|
||
return this$1.input.substring(start, this$1.pos);
|
||
} else {
|
||
this$1.pos++;
|
||
|
||
}
|
||
}
|
||
};
|
||
|
||
this.key_equals_value = function() {
|
||
var key = this.key();
|
||
if (this.tryMatch("=")) {
|
||
this.match("=");
|
||
var val = this.value();
|
||
return [ key, val ];
|
||
} else {
|
||
throw "... = value expected, equals sign missing:"
|
||
+ this.input.substring(this.pos);
|
||
}
|
||
};
|
||
|
||
this.key_value_list = function() {
|
||
var this$1 = this;
|
||
|
||
var kv = this.key_equals_value();
|
||
this.currentEntry['entryTags'] = {};
|
||
this.currentEntry['entryTags'][kv[0]] = kv[1];
|
||
while (this.tryMatch(",")) {
|
||
this$1.match(",");
|
||
// fixes problems with commas at the end of a list
|
||
if (this$1.tryMatch("}")) {
|
||
break;
|
||
}
|
||
|
||
kv = this$1.key_equals_value();
|
||
this$1.currentEntry['entryTags'][kv[0]] = kv[1];
|
||
}
|
||
};
|
||
|
||
this.entry_body = function(d) {
|
||
this.currentEntry = {};
|
||
this.currentEntry['citationKey'] = this.key();
|
||
this.currentEntry['entryType'] = d.substring(1);
|
||
this.match(",");
|
||
this.key_value_list();
|
||
this.entries.push(this.currentEntry);
|
||
};
|
||
|
||
this.directive = function() {
|
||
this.match("@");
|
||
return "@" + this.key();
|
||
};
|
||
|
||
this.preamble = function() {
|
||
this.currentEntry = {};
|
||
this.currentEntry['entryType'] = 'PREAMBLE';
|
||
this.currentEntry['entry'] = this.value_comment();
|
||
this.entries.push(this.currentEntry);
|
||
};
|
||
|
||
this.comment = function() {
|
||
this.currentEntry = {};
|
||
this.currentEntry['entryType'] = 'COMMENT';
|
||
this.currentEntry['entry'] = this.value_comment();
|
||
this.entries.push(this.currentEntry);
|
||
};
|
||
|
||
this.entry = function(d) {
|
||
this.entry_body(d);
|
||
};
|
||
|
||
this.bibtex = function() {
|
||
var this$1 = this;
|
||
|
||
while (this.matchAt()) {
|
||
var d = this$1.directive();
|
||
this$1.match("{");
|
||
if (d == "@STRING") {
|
||
this$1.string();
|
||
} else if (d == "@PREAMBLE") {
|
||
this$1.preamble();
|
||
} else if (d == "@COMMENT") {
|
||
this$1.comment();
|
||
} else {
|
||
this$1.entry(d);
|
||
}
|
||
this$1.match("}");
|
||
}
|
||
};
|
||
}
|
||
|
||
exports.toJSON = function(bibtex) {
|
||
var b = new BibtexParser();
|
||
b.setInput(bibtex);
|
||
b.bibtex();
|
||
return b.entries;
|
||
};
|
||
|
||
/* added during hackathon don't hate on me */
|
||
exports.toBibtex = function(json) {
|
||
var out = '';
|
||
for ( var i in json) {
|
||
out += "@" + json[i].entryType;
|
||
out += '{';
|
||
if (json[i].citationKey)
|
||
{ out += json[i].citationKey + ', '; }
|
||
if (json[i].entry)
|
||
{ out += json[i].entry ; }
|
||
if (json[i].entryTags) {
|
||
var tags = '';
|
||
for (var jdx in json[i].entryTags) {
|
||
if (tags.length != 0)
|
||
{ tags += ', '; }
|
||
tags += jdx + '= {' + json[i].entryTags[jdx] + '}';
|
||
}
|
||
out += tags;
|
||
}
|
||
out += '}\n\n';
|
||
}
|
||
return out;
|
||
|
||
};
|
||
|
||
})(exports);
|
||
|
||
/* end bibtexParse */
|
||
});
|
||
|
||
var bibliography = function(dom, data) {
|
||
var el = dom.querySelector('script[type="text/bibliography"]');
|
||
var citations = [];
|
||
var bibliography = {};
|
||
//TODO If we don't have a local element, make a request for the document.
|
||
if (el) {
|
||
var rawBib = el.textContent;
|
||
var parsed = bibtexParse.toJSON(rawBib);
|
||
if(parsed) {
|
||
parsed.forEach(function (e) {
|
||
for (var k in e.entryTags){
|
||
var val = e.entryTags[k];
|
||
val = val.replace(/[\t\n ]+/g, " ");
|
||
val = val.replace(/{\\["^`\.'acu~Hvs]( )?([a-zA-Z])}/g,
|
||
function (full, x, char) { return char; });
|
||
e.entryTags[k] = val;
|
||
}
|
||
bibliography[e.citationKey] = e.entryTags;
|
||
bibliography[e.citationKey].type = e.entryType;
|
||
});
|
||
}
|
||
|
||
|
||
var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
|
||
citeTags.forEach(function (el) {
|
||
var key = el.getAttribute("key");
|
||
if (key) {
|
||
var citationKeys = key.split(",");
|
||
citationKeys.forEach(function (key) {
|
||
if (citations.indexOf(key) == -1){
|
||
citations.push(key);
|
||
if (!(key in bibliography)){
|
||
console.warn("No bibliography entry found for: " + key);
|
||
}
|
||
}
|
||
});
|
||
}
|
||
});
|
||
}
|
||
data.bibliography = bibliography;
|
||
data.citations = citations;
|
||
};
|
||
|
||
var t0 = new Date;
|
||
var t1 = new Date;
|
||
|
||
function newInterval(floori, offseti, count, field) {
|
||
|
||
function interval(date) {
|
||
return floori(date = new Date(+date)), date;
|
||
}
|
||
|
||
interval.floor = interval;
|
||
|
||
interval.ceil = function(date) {
|
||
return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
|
||
};
|
||
|
||
interval.round = function(date) {
|
||
var d0 = interval(date),
|
||
d1 = interval.ceil(date);
|
||
return date - d0 < d1 - date ? d0 : d1;
|
||
};
|
||
|
||
interval.offset = function(date, step) {
|
||
return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
|
||
};
|
||
|
||
interval.range = function(start, stop, step) {
|
||
var range = [];
|
||
start = interval.ceil(start);
|
||
step = step == null ? 1 : Math.floor(step);
|
||
if (!(start < stop) || !(step > 0)) { return range; } // also handles Invalid Date
|
||
do { range.push(new Date(+start)); } while (offseti(start, step), floori(start), start < stop)
|
||
return range;
|
||
};
|
||
|
||
interval.filter = function(test) {
|
||
return newInterval(function(date) {
|
||
if (date >= date) { while (floori(date), !test(date)) { date.setTime(date - 1); } }
|
||
}, function(date, step) {
|
||
if (date >= date) { while (--step >= 0) { while (offseti(date, 1), !test(date)) {} } } // eslint-disable-line no-empty
|
||
});
|
||
};
|
||
|
||
if (count) {
|
||
interval.count = function(start, end) {
|
||
t0.setTime(+start), t1.setTime(+end);
|
||
floori(t0), floori(t1);
|
||
return Math.floor(count(t0, t1));
|
||
};
|
||
|
||
interval.every = function(step) {
|
||
step = Math.floor(step);
|
||
return !isFinite(step) || !(step > 0) ? null
|
||
: !(step > 1) ? interval
|
||
: interval.filter(field
|
||
? function(d) { return field(d) % step === 0; }
|
||
: function(d) { return interval.count(0, d) % step === 0; });
|
||
};
|
||
}
|
||
|
||
return interval;
|
||
}
|
||
|
||
var millisecond = newInterval(function() {
|
||
// noop
|
||
}, function(date, step) {
|
||
date.setTime(+date + step);
|
||
}, function(start, end) {
|
||
return end - start;
|
||
});
|
||
|
||
// An optimized implementation for this simple case.
|
||
millisecond.every = function(k) {
|
||
k = Math.floor(k);
|
||
if (!isFinite(k) || !(k > 0)) { return null; }
|
||
if (!(k > 1)) { return millisecond; }
|
||
return newInterval(function(date) {
|
||
date.setTime(Math.floor(date / k) * k);
|
||
}, function(date, step) {
|
||
date.setTime(+date + step * k);
|
||
}, function(start, end) {
|
||
return (end - start) / k;
|
||
});
|
||
};
|
||
|
||
var durationSecond = 1e3;
|
||
var durationMinute = 6e4;
|
||
var durationHour = 36e5;
|
||
var durationDay = 864e5;
|
||
var durationWeek = 6048e5;
|
||
|
||
var second = newInterval(function(date) {
|
||
date.setTime(Math.floor(date / durationSecond) * durationSecond);
|
||
}, function(date, step) {
|
||
date.setTime(+date + step * durationSecond);
|
||
}, function(start, end) {
|
||
return (end - start) / durationSecond;
|
||
}, function(date) {
|
||
return date.getUTCSeconds();
|
||
});
|
||
|
||
var minute = newInterval(function(date) {
|
||
date.setTime(Math.floor(date / durationMinute) * durationMinute);
|
||
}, function(date, step) {
|
||
date.setTime(+date + step * durationMinute);
|
||
}, function(start, end) {
|
||
return (end - start) / durationMinute;
|
||
}, function(date) {
|
||
return date.getMinutes();
|
||
});
|
||
|
||
var hour = newInterval(function(date) {
|
||
var offset = date.getTimezoneOffset() * durationMinute % durationHour;
|
||
if (offset < 0) { offset += durationHour; }
|
||
date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
|
||
}, function(date, step) {
|
||
date.setTime(+date + step * durationHour);
|
||
}, function(start, end) {
|
||
return (end - start) / durationHour;
|
||
}, function(date) {
|
||
return date.getHours();
|
||
});
|
||
|
||
var day = newInterval(function(date) {
|
||
date.setHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setDate(date.getDate() + step);
|
||
}, function(start, end) {
|
||
return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
|
||
}, function(date) {
|
||
return date.getDate() - 1;
|
||
});
|
||
|
||
function weekday(i) {
|
||
return newInterval(function(date) {
|
||
date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
|
||
date.setHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setDate(date.getDate() + step * 7);
|
||
}, function(start, end) {
|
||
return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
|
||
});
|
||
}
|
||
|
||
var sunday = weekday(0);
|
||
var monday = weekday(1);
|
||
var tuesday = weekday(2);
|
||
var wednesday = weekday(3);
|
||
var thursday = weekday(4);
|
||
var friday = weekday(5);
|
||
var saturday = weekday(6);
|
||
|
||
var month = newInterval(function(date) {
|
||
date.setDate(1);
|
||
date.setHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setMonth(date.getMonth() + step);
|
||
}, function(start, end) {
|
||
return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
|
||
}, function(date) {
|
||
return date.getMonth();
|
||
});
|
||
|
||
var year = newInterval(function(date) {
|
||
date.setMonth(0, 1);
|
||
date.setHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setFullYear(date.getFullYear() + step);
|
||
}, function(start, end) {
|
||
return end.getFullYear() - start.getFullYear();
|
||
}, function(date) {
|
||
return date.getFullYear();
|
||
});
|
||
|
||
// An optimized implementation for this simple case.
|
||
year.every = function(k) {
|
||
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
|
||
date.setFullYear(Math.floor(date.getFullYear() / k) * k);
|
||
date.setMonth(0, 1);
|
||
date.setHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setFullYear(date.getFullYear() + step * k);
|
||
});
|
||
};
|
||
|
||
var utcMinute = newInterval(function(date) {
|
||
date.setUTCSeconds(0, 0);
|
||
}, function(date, step) {
|
||
date.setTime(+date + step * durationMinute);
|
||
}, function(start, end) {
|
||
return (end - start) / durationMinute;
|
||
}, function(date) {
|
||
return date.getUTCMinutes();
|
||
});
|
||
|
||
var utcHour = newInterval(function(date) {
|
||
date.setUTCMinutes(0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setTime(+date + step * durationHour);
|
||
}, function(start, end) {
|
||
return (end - start) / durationHour;
|
||
}, function(date) {
|
||
return date.getUTCHours();
|
||
});
|
||
|
||
var utcDay = newInterval(function(date) {
|
||
date.setUTCHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setUTCDate(date.getUTCDate() + step);
|
||
}, function(start, end) {
|
||
return (end - start) / durationDay;
|
||
}, function(date) {
|
||
return date.getUTCDate() - 1;
|
||
});
|
||
|
||
function utcWeekday(i) {
|
||
return newInterval(function(date) {
|
||
date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
|
||
date.setUTCHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setUTCDate(date.getUTCDate() + step * 7);
|
||
}, function(start, end) {
|
||
return (end - start) / durationWeek;
|
||
});
|
||
}
|
||
|
||
var utcSunday = utcWeekday(0);
|
||
var utcMonday = utcWeekday(1);
|
||
var utcTuesday = utcWeekday(2);
|
||
var utcWednesday = utcWeekday(3);
|
||
var utcThursday = utcWeekday(4);
|
||
var utcFriday = utcWeekday(5);
|
||
var utcSaturday = utcWeekday(6);
|
||
|
||
var utcMonth = newInterval(function(date) {
|
||
date.setUTCDate(1);
|
||
date.setUTCHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setUTCMonth(date.getUTCMonth() + step);
|
||
}, function(start, end) {
|
||
return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
|
||
}, function(date) {
|
||
return date.getUTCMonth();
|
||
});
|
||
|
||
var utcYear = newInterval(function(date) {
|
||
date.setUTCMonth(0, 1);
|
||
date.setUTCHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setUTCFullYear(date.getUTCFullYear() + step);
|
||
}, function(start, end) {
|
||
return end.getUTCFullYear() - start.getUTCFullYear();
|
||
}, function(date) {
|
||
return date.getUTCFullYear();
|
||
});
|
||
|
||
// An optimized implementation for this simple case.
|
||
utcYear.every = function(k) {
|
||
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
|
||
date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
|
||
date.setUTCMonth(0, 1);
|
||
date.setUTCHours(0, 0, 0, 0);
|
||
}, function(date, step) {
|
||
date.setUTCFullYear(date.getUTCFullYear() + step * k);
|
||
});
|
||
};
|
||
|
||
function localDate(d) {
|
||
if (0 <= d.y && d.y < 100) {
|
||
var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
|
||
date.setFullYear(d.y);
|
||
return date;
|
||
}
|
||
return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
|
||
}
|
||
|
||
function utcDate(d) {
|
||
if (0 <= d.y && d.y < 100) {
|
||
var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
|
||
date.setUTCFullYear(d.y);
|
||
return date;
|
||
}
|
||
return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
|
||
}
|
||
|
||
function newYear(y) {
|
||
return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
|
||
}
|
||
|
||
function formatLocale(locale) {
|
||
var locale_dateTime = locale.dateTime,
|
||
locale_date = locale.date,
|
||
locale_time = locale.time,
|
||
locale_periods = locale.periods,
|
||
locale_weekdays = locale.days,
|
||
locale_shortWeekdays = locale.shortDays,
|
||
locale_months = locale.months,
|
||
locale_shortMonths = locale.shortMonths;
|
||
|
||
var periodRe = formatRe(locale_periods),
|
||
periodLookup = formatLookup(locale_periods),
|
||
weekdayRe = formatRe(locale_weekdays),
|
||
weekdayLookup = formatLookup(locale_weekdays),
|
||
shortWeekdayRe = formatRe(locale_shortWeekdays),
|
||
shortWeekdayLookup = formatLookup(locale_shortWeekdays),
|
||
monthRe = formatRe(locale_months),
|
||
monthLookup = formatLookup(locale_months),
|
||
shortMonthRe = formatRe(locale_shortMonths),
|
||
shortMonthLookup = formatLookup(locale_shortMonths);
|
||
|
||
var formats = {
|
||
"a": formatShortWeekday,
|
||
"A": formatWeekday,
|
||
"b": formatShortMonth,
|
||
"B": formatMonth,
|
||
"c": null,
|
||
"d": formatDayOfMonth,
|
||
"e": formatDayOfMonth,
|
||
"H": formatHour24,
|
||
"I": formatHour12,
|
||
"j": formatDayOfYear,
|
||
"L": formatMilliseconds,
|
||
"m": formatMonthNumber,
|
||
"M": formatMinutes,
|
||
"p": formatPeriod,
|
||
"S": formatSeconds,
|
||
"U": formatWeekNumberSunday,
|
||
"w": formatWeekdayNumber,
|
||
"W": formatWeekNumberMonday,
|
||
"x": null,
|
||
"X": null,
|
||
"y": formatYear,
|
||
"Y": formatFullYear,
|
||
"Z": formatZone,
|
||
"%": formatLiteralPercent
|
||
};
|
||
|
||
var utcFormats = {
|
||
"a": formatUTCShortWeekday,
|
||
"A": formatUTCWeekday,
|
||
"b": formatUTCShortMonth,
|
||
"B": formatUTCMonth,
|
||
"c": null,
|
||
"d": formatUTCDayOfMonth,
|
||
"e": formatUTCDayOfMonth,
|
||
"H": formatUTCHour24,
|
||
"I": formatUTCHour12,
|
||
"j": formatUTCDayOfYear,
|
||
"L": formatUTCMilliseconds,
|
||
"m": formatUTCMonthNumber,
|
||
"M": formatUTCMinutes,
|
||
"p": formatUTCPeriod,
|
||
"S": formatUTCSeconds,
|
||
"U": formatUTCWeekNumberSunday,
|
||
"w": formatUTCWeekdayNumber,
|
||
"W": formatUTCWeekNumberMonday,
|
||
"x": null,
|
||
"X": null,
|
||
"y": formatUTCYear,
|
||
"Y": formatUTCFullYear,
|
||
"Z": formatUTCZone,
|
||
"%": formatLiteralPercent
|
||
};
|
||
|
||
var parses = {
|
||
"a": parseShortWeekday,
|
||
"A": parseWeekday,
|
||
"b": parseShortMonth,
|
||
"B": parseMonth,
|
||
"c": parseLocaleDateTime,
|
||
"d": parseDayOfMonth,
|
||
"e": parseDayOfMonth,
|
||
"H": parseHour24,
|
||
"I": parseHour24,
|
||
"j": parseDayOfYear,
|
||
"L": parseMilliseconds,
|
||
"m": parseMonthNumber,
|
||
"M": parseMinutes,
|
||
"p": parsePeriod,
|
||
"S": parseSeconds,
|
||
"U": parseWeekNumberSunday,
|
||
"w": parseWeekdayNumber,
|
||
"W": parseWeekNumberMonday,
|
||
"x": parseLocaleDate,
|
||
"X": parseLocaleTime,
|
||
"y": parseYear,
|
||
"Y": parseFullYear,
|
||
"Z": parseZone,
|
||
"%": parseLiteralPercent
|
||
};
|
||
|
||
// These recursive directive definitions must be deferred.
|
||
formats.x = newFormat(locale_date, formats);
|
||
formats.X = newFormat(locale_time, formats);
|
||
formats.c = newFormat(locale_dateTime, formats);
|
||
utcFormats.x = newFormat(locale_date, utcFormats);
|
||
utcFormats.X = newFormat(locale_time, utcFormats);
|
||
utcFormats.c = newFormat(locale_dateTime, utcFormats);
|
||
|
||
function newFormat(specifier, formats) {
|
||
return function(date) {
|
||
var string = [],
|
||
i = -1,
|
||
j = 0,
|
||
n = specifier.length,
|
||
c,
|
||
pad,
|
||
format;
|
||
|
||
if (!(date instanceof Date)) { date = new Date(+date); }
|
||
|
||
while (++i < n) {
|
||
if (specifier.charCodeAt(i) === 37) {
|
||
string.push(specifier.slice(j, i));
|
||
if ((pad = pads[c = specifier.charAt(++i)]) != null) { c = specifier.charAt(++i); }
|
||
else { pad = c === "e" ? " " : "0"; }
|
||
if (format = formats[c]) { c = format(date, pad); }
|
||
string.push(c);
|
||
j = i + 1;
|
||
}
|
||
}
|
||
|
||
string.push(specifier.slice(j, i));
|
||
return string.join("");
|
||
};
|
||
}
|
||
|
||
function newParse(specifier, newDate) {
|
||
return function(string) {
|
||
var d = newYear(1900),
|
||
i = parseSpecifier(d, specifier, string += "", 0);
|
||
if (i != string.length) { return null; }
|
||
|
||
// The am-pm flag is 0 for AM, and 1 for PM.
|
||
if ("p" in d) { d.H = d.H % 12 + d.p * 12; }
|
||
|
||
// Convert day-of-week and week-of-year to day-of-year.
|
||
if ("W" in d || "U" in d) {
|
||
if (!("w" in d)) { d.w = "W" in d ? 1 : 0; }
|
||
var day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
|
||
d.m = 0;
|
||
d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$$1 + 5) % 7 : d.w + d.U * 7 - (day$$1 + 6) % 7;
|
||
}
|
||
|
||
// If a time zone is specified, all fields are interpreted as UTC and then
|
||
// offset according to the specified time zone.
|
||
if ("Z" in d) {
|
||
d.H += d.Z / 100 | 0;
|
||
d.M += d.Z % 100;
|
||
return utcDate(d);
|
||
}
|
||
|
||
// Otherwise, all fields are in local time.
|
||
return newDate(d);
|
||
};
|
||
}
|
||
|
||
function parseSpecifier(d, specifier, string, j) {
|
||
var i = 0,
|
||
n = specifier.length,
|
||
m = string.length,
|
||
c,
|
||
parse;
|
||
|
||
while (i < n) {
|
||
if (j >= m) { return -1; }
|
||
c = specifier.charCodeAt(i++);
|
||
if (c === 37) {
|
||
c = specifier.charAt(i++);
|
||
parse = parses[c in pads ? specifier.charAt(i++) : c];
|
||
if (!parse || ((j = parse(d, string, j)) < 0)) { return -1; }
|
||
} else if (c != string.charCodeAt(j++)) {
|
||
return -1;
|
||
}
|
||
}
|
||
|
||
return j;
|
||
}
|
||
|
||
function parsePeriod(d, string, i) {
|
||
var n = periodRe.exec(string.slice(i));
|
||
return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseShortWeekday(d, string, i) {
|
||
var n = shortWeekdayRe.exec(string.slice(i));
|
||
return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseWeekday(d, string, i) {
|
||
var n = weekdayRe.exec(string.slice(i));
|
||
return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseShortMonth(d, string, i) {
|
||
var n = shortMonthRe.exec(string.slice(i));
|
||
return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseMonth(d, string, i) {
|
||
var n = monthRe.exec(string.slice(i));
|
||
return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseLocaleDateTime(d, string, i) {
|
||
return parseSpecifier(d, locale_dateTime, string, i);
|
||
}
|
||
|
||
function parseLocaleDate(d, string, i) {
|
||
return parseSpecifier(d, locale_date, string, i);
|
||
}
|
||
|
||
function parseLocaleTime(d, string, i) {
|
||
return parseSpecifier(d, locale_time, string, i);
|
||
}
|
||
|
||
function formatShortWeekday(d) {
|
||
return locale_shortWeekdays[d.getDay()];
|
||
}
|
||
|
||
function formatWeekday(d) {
|
||
return locale_weekdays[d.getDay()];
|
||
}
|
||
|
||
function formatShortMonth(d) {
|
||
return locale_shortMonths[d.getMonth()];
|
||
}
|
||
|
||
function formatMonth(d) {
|
||
return locale_months[d.getMonth()];
|
||
}
|
||
|
||
function formatPeriod(d) {
|
||
return locale_periods[+(d.getHours() >= 12)];
|
||
}
|
||
|
||
function formatUTCShortWeekday(d) {
|
||
return locale_shortWeekdays[d.getUTCDay()];
|
||
}
|
||
|
||
function formatUTCWeekday(d) {
|
||
return locale_weekdays[d.getUTCDay()];
|
||
}
|
||
|
||
function formatUTCShortMonth(d) {
|
||
return locale_shortMonths[d.getUTCMonth()];
|
||
}
|
||
|
||
function formatUTCMonth(d) {
|
||
return locale_months[d.getUTCMonth()];
|
||
}
|
||
|
||
function formatUTCPeriod(d) {
|
||
return locale_periods[+(d.getUTCHours() >= 12)];
|
||
}
|
||
|
||
return {
|
||
format: function(specifier) {
|
||
var f = newFormat(specifier += "", formats);
|
||
f.toString = function() { return specifier; };
|
||
return f;
|
||
},
|
||
parse: function(specifier) {
|
||
var p = newParse(specifier += "", localDate);
|
||
p.toString = function() { return specifier; };
|
||
return p;
|
||
},
|
||
utcFormat: function(specifier) {
|
||
var f = newFormat(specifier += "", utcFormats);
|
||
f.toString = function() { return specifier; };
|
||
return f;
|
||
},
|
||
utcParse: function(specifier) {
|
||
var p = newParse(specifier, utcDate);
|
||
p.toString = function() { return specifier; };
|
||
return p;
|
||
}
|
||
};
|
||
}
|
||
|
||
var pads = {"-": "", "_": " ", "0": "0"};
|
||
var numberRe = /^\s*\d+/;
|
||
var percentRe = /^%/;
|
||
var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
|
||
|
||
function pad(value, fill, width) {
|
||
var sign = value < 0 ? "-" : "",
|
||
string = (sign ? -value : value) + "",
|
||
length = string.length;
|
||
return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
|
||
}
|
||
|
||
function requote(s) {
|
||
return s.replace(requoteRe, "\\$&");
|
||
}
|
||
|
||
function formatRe(names) {
|
||
return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
|
||
}
|
||
|
||
function formatLookup(names) {
|
||
var map = {}, i = -1, n = names.length;
|
||
while (++i < n) { map[names[i].toLowerCase()] = i; }
|
||
return map;
|
||
}
|
||
|
||
function parseWeekdayNumber(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 1));
|
||
return n ? (d.w = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseWeekNumberSunday(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i));
|
||
return n ? (d.U = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseWeekNumberMonday(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i));
|
||
return n ? (d.W = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseFullYear(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 4));
|
||
return n ? (d.y = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseYear(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 2));
|
||
return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseZone(d, string, i) {
|
||
var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
|
||
return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseMonthNumber(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 2));
|
||
return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseDayOfMonth(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 2));
|
||
return n ? (d.d = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseDayOfYear(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 3));
|
||
return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseHour24(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 2));
|
||
return n ? (d.H = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseMinutes(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 2));
|
||
return n ? (d.M = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseSeconds(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 2));
|
||
return n ? (d.S = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseMilliseconds(d, string, i) {
|
||
var n = numberRe.exec(string.slice(i, i + 3));
|
||
return n ? (d.L = +n[0], i + n[0].length) : -1;
|
||
}
|
||
|
||
function parseLiteralPercent(d, string, i) {
|
||
var n = percentRe.exec(string.slice(i, i + 1));
|
||
return n ? i + n[0].length : -1;
|
||
}
|
||
|
||
function formatDayOfMonth(d, p) {
|
||
return pad(d.getDate(), p, 2);
|
||
}
|
||
|
||
function formatHour24(d, p) {
|
||
return pad(d.getHours(), p, 2);
|
||
}
|
||
|
||
function formatHour12(d, p) {
|
||
return pad(d.getHours() % 12 || 12, p, 2);
|
||
}
|
||
|
||
function formatDayOfYear(d, p) {
|
||
return pad(1 + day.count(year(d), d), p, 3);
|
||
}
|
||
|
||
function formatMilliseconds(d, p) {
|
||
return pad(d.getMilliseconds(), p, 3);
|
||
}
|
||
|
||
function formatMonthNumber(d, p) {
|
||
return pad(d.getMonth() + 1, p, 2);
|
||
}
|
||
|
||
function formatMinutes(d, p) {
|
||
return pad(d.getMinutes(), p, 2);
|
||
}
|
||
|
||
function formatSeconds(d, p) {
|
||
return pad(d.getSeconds(), p, 2);
|
||
}
|
||
|
||
function formatWeekNumberSunday(d, p) {
|
||
return pad(sunday.count(year(d), d), p, 2);
|
||
}
|
||
|
||
function formatWeekdayNumber(d) {
|
||
return d.getDay();
|
||
}
|
||
|
||
function formatWeekNumberMonday(d, p) {
|
||
return pad(monday.count(year(d), d), p, 2);
|
||
}
|
||
|
||
function formatYear(d, p) {
|
||
return pad(d.getFullYear() % 100, p, 2);
|
||
}
|
||
|
||
function formatFullYear(d, p) {
|
||
return pad(d.getFullYear() % 10000, p, 4);
|
||
}
|
||
|
||
function formatZone(d) {
|
||
var z = d.getTimezoneOffset();
|
||
return (z > 0 ? "-" : (z *= -1, "+"))
|
||
+ pad(z / 60 | 0, "0", 2)
|
||
+ pad(z % 60, "0", 2);
|
||
}
|
||
|
||
function formatUTCDayOfMonth(d, p) {
|
||
return pad(d.getUTCDate(), p, 2);
|
||
}
|
||
|
||
function formatUTCHour24(d, p) {
|
||
return pad(d.getUTCHours(), p, 2);
|
||
}
|
||
|
||
function formatUTCHour12(d, p) {
|
||
return pad(d.getUTCHours() % 12 || 12, p, 2);
|
||
}
|
||
|
||
function formatUTCDayOfYear(d, p) {
|
||
return pad(1 + utcDay.count(utcYear(d), d), p, 3);
|
||
}
|
||
|
||
function formatUTCMilliseconds(d, p) {
|
||
return pad(d.getUTCMilliseconds(), p, 3);
|
||
}
|
||
|
||
function formatUTCMonthNumber(d, p) {
|
||
return pad(d.getUTCMonth() + 1, p, 2);
|
||
}
|
||
|
||
function formatUTCMinutes(d, p) {
|
||
return pad(d.getUTCMinutes(), p, 2);
|
||
}
|
||
|
||
function formatUTCSeconds(d, p) {
|
||
return pad(d.getUTCSeconds(), p, 2);
|
||
}
|
||
|
||
function formatUTCWeekNumberSunday(d, p) {
|
||
return pad(utcSunday.count(utcYear(d), d), p, 2);
|
||
}
|
||
|
||
function formatUTCWeekdayNumber(d) {
|
||
return d.getUTCDay();
|
||
}
|
||
|
||
function formatUTCWeekNumberMonday(d, p) {
|
||
return pad(utcMonday.count(utcYear(d), d), p, 2);
|
||
}
|
||
|
||
function formatUTCYear(d, p) {
|
||
return pad(d.getUTCFullYear() % 100, p, 2);
|
||
}
|
||
|
||
function formatUTCFullYear(d, p) {
|
||
return pad(d.getUTCFullYear() % 10000, p, 4);
|
||
}
|
||
|
||
function formatUTCZone() {
|
||
return "+0000";
|
||
}
|
||
|
||
function formatLiteralPercent() {
|
||
return "%";
|
||
}
|
||
|
||
var locale$1;
|
||
var timeFormat;
|
||
var timeParse;
|
||
var utcFormat;
|
||
var utcParse;
|
||
|
||
defaultLocale({
|
||
dateTime: "%x, %X",
|
||
date: "%-m/%-d/%Y",
|
||
time: "%-I:%M:%S %p",
|
||
periods: ["AM", "PM"],
|
||
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
|
||
shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
||
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
|
||
shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
||
});
|
||
|
||
function defaultLocale(definition) {
|
||
locale$1 = formatLocale(definition);
|
||
timeFormat = locale$1.format;
|
||
timeParse = locale$1.parse;
|
||
utcFormat = locale$1.utcFormat;
|
||
utcParse = locale$1.utcParse;
|
||
return locale$1;
|
||
}
|
||
|
||
var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
|
||
|
||
function formatIsoNative(date) {
|
||
return date.toISOString();
|
||
}
|
||
|
||
var formatIso = Date.prototype.toISOString
|
||
? formatIsoNative
|
||
: utcFormat(isoSpecifier);
|
||
|
||
function parseIsoNative(string) {
|
||
var date = new Date(string);
|
||
return isNaN(date) ? null : date;
|
||
}
|
||
|
||
var parseIso = +new Date("2000-01-01T00:00:00.000Z")
|
||
? parseIsoNative
|
||
: utcParse(isoSpecifier);
|
||
|
||
var expandData = function(dom, data) {
|
||
|
||
data.authors = data.authors || [];
|
||
|
||
// paths
|
||
data.url = "http://distill.pub/" + data.distillPath;
|
||
data.githubUrl = "https://github.com/" + data.githubPath;
|
||
|
||
// Homepage
|
||
//data.homepage = !post.noHomepage;
|
||
data.journal = data.journal || {};
|
||
|
||
// Dates
|
||
// TODO: fix updated date
|
||
if (data.publishedDate){//} && data.journal) {
|
||
data.volume = data.publishedDate.getFullYear() - 2015;
|
||
data.issue = data.publishedDate.getMonth() + 1;
|
||
}
|
||
|
||
data.publishedDate = data.publishedDate ? data.publishedDate : new Date("Invalid");
|
||
data.updated = data.updated ? data.updated : new Date("Invalid");
|
||
|
||
data.publishedDateRFC;
|
||
var RFC = timeFormat("%a, %d %b %Y %H:%M:%S %Z");
|
||
var months = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
|
||
var zeroPad = function (n) { return n < 10 ? "0" + n : n; };
|
||
data.publishedDateRFC = RFC(data.publishedDate);
|
||
data.publishedYear = data.publishedDate.getFullYear();
|
||
data.publishedMonth = months[data.publishedDate.getMonth()];
|
||
data.publishedDay = data.publishedDate.getDate();
|
||
data.publishedMonthPadded = zeroPad(data.publishedDate.getMonth() + 1);
|
||
data.publishedDayPadded = zeroPad(data.publishedDate.getDate());
|
||
|
||
if (data.authors.length > 2) {
|
||
data.concatenatedAuthors = data.authors[0].lastName + ", et al.";
|
||
} else if (data.authors.length === 2) {
|
||
data.concatenatedAuthors = data.authors[0].lastName + " & " + data.authors[1].lastName;
|
||
} else if (data.authors.length === 1) {
|
||
data.concatenatedAuthors = data.authors[0].lastName;
|
||
}
|
||
|
||
data.bibtexAuthors = data.authors.map(function(author){
|
||
return author.lastName + ", " + author.firstName;
|
||
}).join(" and ");
|
||
|
||
data.slug = data.authors.length ? data.authors[0].lastName.toLowerCase() + data.publishedYear + data.title.split(" ")[0].toLowerCase() : "Untitled";
|
||
|
||
};
|
||
|
||
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";
|
||
|
||
var meta = function(dom, data) {
|
||
var head = dom.querySelector("head");
|
||
var appendHead = function (html) { return appendHtml(head, html); };
|
||
|
||
function meta(name, content) {
|
||
if (content)
|
||
{ appendHead(("<meta name=\"" + name + "\" content=\"" + content + "\" >")); }
|
||
}
|
||
|
||
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 "));
|
||
|
||
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 "));
|
||
data.authors.forEach(function (a) {
|
||
appendHtml(head, ("\n <meta property=\"article:author\" content=\"" + (a.firstName) + " " + (a.lastName) + "\" />"));
|
||
});
|
||
|
||
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.jpg\"/>\n <meta property=\"og:locale\" content=\"en_US\" />\n <meta property=\"og:site_name\" content=\"Distill\" />\n "));
|
||
|
||
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.jpg\">\n <meta name=\"twitter:image:width\" content=\"560\">\n <meta name=\"twitter:image:height\" content=\"295\">\n "));
|
||
|
||
appendHead("\n <!-- https://scholar.google.com/intl/en/scholar/inclusion.html#indexing -->\n ");
|
||
|
||
meta("citation_title", data.title);
|
||
meta("citation_fulltext_html_url", data.url);
|
||
meta("citation_volume", data.volume);
|
||
meta("citation_issue", data.issue);
|
||
meta("citation_firstpage", data.doiSuffix? ("e" + (data.doiSuffix)) : undefined);
|
||
meta("citation_doi", data.doi);
|
||
|
||
var journal = data.journal || {};
|
||
meta("citation_journal_title", journal.name);
|
||
meta("citation_journal_abbrev", journal.nameAbbrev);
|
||
meta("citation_issn", journal.issn);
|
||
meta("citation_publisher", journal.publisher);
|
||
|
||
if (data.published){
|
||
var zeroPad = function (n) { return n < 10 ? "0" + n : n; };
|
||
var publishedYear = data.published.getFullYear();
|
||
var publishedMonthPadded = zeroPad(data.published.getMonth() + 1);
|
||
var publishedDayPadded = zeroPad(data.published.getDate());
|
||
meta("citation_publication_date", (publishedYear + "/" + publishedMonthPadded + "/" + publishedDayPadded));
|
||
}
|
||
|
||
(data.authors || []).forEach(function (a) {
|
||
meta("citation_author", ((a.lastName) + ", " + (a.firstName)));
|
||
meta("citation_author_institution", a.affiliation);
|
||
});
|
||
|
||
if (data.citations) {
|
||
data.citations.forEach(function (key) {
|
||
var d = data.bibliography[key];
|
||
if(!d) {
|
||
console.warn("No bibliography data fround for " + key);
|
||
} else {
|
||
meta("citation_reference", citation_meta_content(data.bibliography[key]) );
|
||
}
|
||
});
|
||
}
|
||
};
|
||
|
||
function appendHtml(el, html) {
|
||
el.innerHTML += html;
|
||
}
|
||
|
||
function citation_meta_content(ref){
|
||
var content = "citation_title=" + (ref.title) + ";";
|
||
ref.author.split(" and ").forEach(function (author) {
|
||
content += "citation_author=" + (author.trim()) + ";";
|
||
});
|
||
if ("journal" in ref){
|
||
content += "citation_journal_title=" + (ref.journal) + ";";
|
||
}
|
||
if ("volume" in ref) {
|
||
content += "citation_volume=" + (ref.volume) + ";";
|
||
}
|
||
if ("issue" in ref || "number" in ref){
|
||
content += "citation_number=" + (ref.issue || ref.number) + ";";
|
||
}
|
||
/*content += `citation_first_page=${};`;
|
||
content += `citation_publication_date=${};`;*/
|
||
return content;
|
||
}
|
||
|
||
var logo = "<svg viewBox=\"-607 419 64 64\">\n <path 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";
|
||
|
||
var html$1 = "\n<style>\ndt-header {\n display: block;\n position: relative;\n height: 60px;\n background-color: hsl(223, 9%, 25%);\n width: 100%;\n box-sizing: border-box;\n z-index: 2;\n color: rgba(0, 0, 0, 0.8);\n border-bottom: 1px solid rgba(0, 0, 0, 0.08);\n box-shadow: 0 1px 6px rgba(0, 0, 0, 0.05);\n}\ndt-header .content {\n height: 70px;\n}\ndt-header a {\n font-size: 16px;\n height: 60px;\n line-height: 60px;\n text-decoration: none;\n color: rgba(255, 255, 255, 0.8);\n}\ndt-header svg {\n width: 24px;\n position: relative;\n top: 4px;\n margin-right: 2px;\n}\n\n@media(min-width: 1080px) {\n dt-header {\n height: 70px;\n }\n dt-header a {\n height: 70px;\n line-height: 70px;\n }\n}\n\ndt-header svg path {\n fill: none;\n stroke: rgba(255, 255, 255, 0.8);\n stroke-width: 3px;\n}\ndt-header .logo {\n font-size: 13px;\n font-weight: 300;\n text-transform: uppercase;\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";
|
||
|
||
var header = function(dom, data) {
|
||
var el = dom.querySelector("dt-header");
|
||
if(el) {
|
||
el.innerHTML = html$1;
|
||
} else {
|
||
var header = dom.createElement("dt-header");
|
||
header.innerHTML = html$1;
|
||
var b = dom.querySelector("body");
|
||
b.insertBefore(header, b.firstChild);
|
||
}
|
||
};
|
||
|
||
var mustache = createCommonjsModule(function (module, exports) {
|
||
/*!
|
||
* mustache.js - Logic-less {{mustache}} templates with JavaScript
|
||
* http://github.com/janl/mustache.js
|
||
*/
|
||
|
||
/*global define: false Mustache: true*/
|
||
|
||
(function defineMustache (global, factory) {
|
||
if ('object' === 'object' && exports && typeof exports.nodeName !== 'string') {
|
||
factory(exports); // CommonJS
|
||
} else if (typeof undefined === 'function' && undefined.amd) {
|
||
undefined(['exports'], factory); // AMD
|
||
} else {
|
||
global.Mustache = {};
|
||
factory(global.Mustache); // script, wsh, asp
|
||
}
|
||
}(commonjsGlobal, function mustacheFactory (mustache) {
|
||
|
||
var objectToString = Object.prototype.toString;
|
||
var isArray = Array.isArray || function isArrayPolyfill (object) {
|
||
return objectToString.call(object) === '[object Array]';
|
||
};
|
||
|
||
function isFunction (object) {
|
||
return typeof object === 'function';
|
||
}
|
||
|
||
/**
|
||
* More correct typeof string handling array
|
||
* which normally returns typeof 'object'
|
||
*/
|
||
function typeStr (obj) {
|
||
return isArray(obj) ? 'array' : typeof obj;
|
||
}
|
||
|
||
function escapeRegExp (string) {
|
||
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
|
||
}
|
||
|
||
/**
|
||
* Null safe way of checking whether or not an object,
|
||
* including its prototype, has a given property
|
||
*/
|
||
function hasProperty (obj, propName) {
|
||
return obj != null && typeof obj === 'object' && (propName in obj);
|
||
}
|
||
|
||
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
|
||
// See https://github.com/janl/mustache.js/issues/189
|
||
var regExpTest = RegExp.prototype.test;
|
||
function testRegExp (re, string) {
|
||
return regExpTest.call(re, string);
|
||
}
|
||
|
||
var nonSpaceRe = /\S/;
|
||
function isWhitespace (string) {
|
||
return !testRegExp(nonSpaceRe, string);
|
||
}
|
||
|
||
var entityMap = {
|
||
'&': '&',
|
||
'<': '<',
|
||
'>': '>',
|
||
'"': '"',
|
||
"'": ''',
|
||
'/': '/',
|
||
'`': '`',
|
||
'=': '='
|
||
};
|
||
|
||
function escapeHtml (string) {
|
||
return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
|
||
return entityMap[s];
|
||
});
|
||
}
|
||
|
||
var whiteRe = /\s*/;
|
||
var spaceRe = /\s+/;
|
||
var equalsRe = /\s*=/;
|
||
var curlyRe = /\s*\}/;
|
||
var tagRe = /#|\^|\/|>|\{|&|=|!/;
|
||
|
||
/**
|
||
* Breaks up the given `template` string into a tree of tokens. If the `tags`
|
||
* argument is given here it must be an array with two string values: the
|
||
* opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
|
||
* course, the default is to use mustaches (i.e. mustache.tags).
|
||
*
|
||
* A token is an array with at least 4 elements. The first element is the
|
||
* mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
|
||
* did not contain a symbol (i.e. {{myValue}}) this element is "name". For
|
||
* all text that appears outside a symbol this element is "text".
|
||
*
|
||
* The second element of a token is its "value". For mustache tags this is
|
||
* whatever else was inside the tag besides the opening symbol. For text tokens
|
||
* this is the text itself.
|
||
*
|
||
* The third and fourth elements of the token are the start and end indices,
|
||
* respectively, of the token in the original template.
|
||
*
|
||
* Tokens that are the root node of a subtree contain two more elements: 1) an
|
||
* array of tokens in the subtree and 2) the index in the original template at
|
||
* which the closing tag for that section begins.
|
||
*/
|
||
function parseTemplate (template, tags) {
|
||
if (!template)
|
||
{ return []; }
|
||
|
||
var sections = []; // Stack to hold section tokens
|
||
var tokens = []; // Buffer to hold the tokens
|
||
var spaces = []; // Indices of whitespace tokens on the current line
|
||
var hasTag = false; // Is there a {{tag}} on the current line?
|
||
var nonSpace = false; // Is there a non-space char on the current line?
|
||
|
||
// Strips all whitespace tokens array for the current line
|
||
// if there was a {{#tag}} on it and otherwise only space.
|
||
function stripSpace () {
|
||
if (hasTag && !nonSpace) {
|
||
while (spaces.length)
|
||
{ delete tokens[spaces.pop()]; }
|
||
} else {
|
||
spaces = [];
|
||
}
|
||
|
||
hasTag = false;
|
||
nonSpace = false;
|
||
}
|
||
|
||
var openingTagRe, closingTagRe, closingCurlyRe;
|
||
function compileTags (tagsToCompile) {
|
||
if (typeof tagsToCompile === 'string')
|
||
{ tagsToCompile = tagsToCompile.split(spaceRe, 2); }
|
||
|
||
if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)
|
||
{ throw new Error('Invalid tags: ' + tagsToCompile); }
|
||
|
||
openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\s*');
|
||
closingTagRe = new RegExp('\\s*' + escapeRegExp(tagsToCompile[1]));
|
||
closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tagsToCompile[1]));
|
||
}
|
||
|
||
compileTags(tags || mustache.tags);
|
||
|
||
var scanner = new Scanner(template);
|
||
|
||
var start, type, value, chr, token, openSection;
|
||
while (!scanner.eos()) {
|
||
start = scanner.pos;
|
||
|
||
// Match any text between tags.
|
||
value = scanner.scanUntil(openingTagRe);
|
||
|
||
if (value) {
|
||
for (var i = 0, valueLength = value.length; i < valueLength; ++i) {
|
||
chr = value.charAt(i);
|
||
|
||
if (isWhitespace(chr)) {
|
||
spaces.push(tokens.length);
|
||
} else {
|
||
nonSpace = true;
|
||
}
|
||
|
||
tokens.push([ 'text', chr, start, start + 1 ]);
|
||
start += 1;
|
||
|
||
// Check for whitespace on the current line.
|
||
if (chr === '\n')
|
||
{ stripSpace(); }
|
||
}
|
||
}
|
||
|
||
// Match the opening tag.
|
||
if (!scanner.scan(openingTagRe))
|
||
{ break; }
|
||
|
||
hasTag = true;
|
||
|
||
// Get the tag type.
|
||
type = scanner.scan(tagRe) || 'name';
|
||
scanner.scan(whiteRe);
|
||
|
||
// Get the tag value.
|
||
if (type === '=') {
|
||
value = scanner.scanUntil(equalsRe);
|
||
scanner.scan(equalsRe);
|
||
scanner.scanUntil(closingTagRe);
|
||
} else if (type === '{') {
|
||
value = scanner.scanUntil(closingCurlyRe);
|
||
scanner.scan(curlyRe);
|
||
scanner.scanUntil(closingTagRe);
|
||
type = '&';
|
||
} else {
|
||
value = scanner.scanUntil(closingTagRe);
|
||
}
|
||
|
||
// Match the closing tag.
|
||
if (!scanner.scan(closingTagRe))
|
||
{ throw new Error('Unclosed tag at ' + scanner.pos); }
|
||
|
||
token = [ type, value, start, scanner.pos ];
|
||
tokens.push(token);
|
||
|
||
if (type === '#' || type === '^') {
|
||
sections.push(token);
|
||
} else if (type === '/') {
|
||
// Check section nesting.
|
||
openSection = sections.pop();
|
||
|
||
if (!openSection)
|
||
{ throw new Error('Unopened section "' + value + '" at ' + start); }
|
||
|
||
if (openSection[1] !== value)
|
||
{ throw new Error('Unclosed section "' + openSection[1] + '" at ' + start); }
|
||
} else if (type === 'name' || type === '{' || type === '&') {
|
||
nonSpace = true;
|
||
} else if (type === '=') {
|
||
// Set the tags for the next time around.
|
||
compileTags(value);
|
||
}
|
||
}
|
||
|
||
// Make sure there are no open sections when we're done.
|
||
openSection = sections.pop();
|
||
|
||
if (openSection)
|
||
{ throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos); }
|
||
|
||
return nestTokens(squashTokens(tokens));
|
||
}
|
||
|
||
/**
|
||
* Combines the values of consecutive text tokens in the given `tokens` array
|
||
* to a single token.
|
||
*/
|
||
function squashTokens (tokens) {
|
||
var squashedTokens = [];
|
||
|
||
var token, lastToken;
|
||
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
|
||
token = tokens[i];
|
||
|
||
if (token) {
|
||
if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
|
||
lastToken[1] += token[1];
|
||
lastToken[3] = token[3];
|
||
} else {
|
||
squashedTokens.push(token);
|
||
lastToken = token;
|
||
}
|
||
}
|
||
}
|
||
|
||
return squashedTokens;
|
||
}
|
||
|
||
/**
|
||
* Forms the given array of `tokens` into a nested tree structure where
|
||
* tokens that represent a section have two additional items: 1) an array of
|
||
* all tokens that appear in that section and 2) the index in the original
|
||
* template that represents the end of that section.
|
||
*/
|
||
function nestTokens (tokens) {
|
||
var nestedTokens = [];
|
||
var collector = nestedTokens;
|
||
var sections = [];
|
||
|
||
var token, section;
|
||
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
|
||
token = tokens[i];
|
||
|
||
switch (token[0]) {
|
||
case '#':
|
||
case '^':
|
||
collector.push(token);
|
||
sections.push(token);
|
||
collector = token[4] = [];
|
||
break;
|
||
case '/':
|
||
section = sections.pop();
|
||
section[5] = token[2];
|
||
collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens;
|
||
break;
|
||
default:
|
||
collector.push(token);
|
||
}
|
||
}
|
||
|
||
return nestedTokens;
|
||
}
|
||
|
||
/**
|
||
* A simple string scanner that is used by the template parser to find
|
||
* tokens in template strings.
|
||
*/
|
||
function Scanner (string) {
|
||
this.string = string;
|
||
this.tail = string;
|
||
this.pos = 0;
|
||
}
|
||
|
||
/**
|
||
* Returns `true` if the tail is empty (end of string).
|
||
*/
|
||
Scanner.prototype.eos = function eos () {
|
||
return this.tail === '';
|
||
};
|
||
|
||
/**
|
||
* Tries to match the given regular expression at the current position.
|
||
* Returns the matched text if it can match, the empty string otherwise.
|
||
*/
|
||
Scanner.prototype.scan = function scan (re) {
|
||
var match = this.tail.match(re);
|
||
|
||
if (!match || match.index !== 0)
|
||
{ return ''; }
|
||
|
||
var string = match[0];
|
||
|
||
this.tail = this.tail.substring(string.length);
|
||
this.pos += string.length;
|
||
|
||
return string;
|
||
};
|
||
|
||
/**
|
||
* Skips all text until the given regular expression can be matched. Returns
|
||
* the skipped string, which is the entire tail if no match can be made.
|
||
*/
|
||
Scanner.prototype.scanUntil = function scanUntil (re) {
|
||
var index = this.tail.search(re), match;
|
||
|
||
switch (index) {
|
||
case -1:
|
||
match = this.tail;
|
||
this.tail = '';
|
||
break;
|
||
case 0:
|
||
match = '';
|
||
break;
|
||
default:
|
||
match = this.tail.substring(0, index);
|
||
this.tail = this.tail.substring(index);
|
||
}
|
||
|
||
this.pos += match.length;
|
||
|
||
return match;
|
||
};
|
||
|
||
/**
|
||
* Represents a rendering context by wrapping a view object and
|
||
* maintaining a reference to the parent context.
|
||
*/
|
||
function Context (view, parentContext) {
|
||
this.view = view;
|
||
this.cache = { '.': this.view };
|
||
this.parent = parentContext;
|
||
}
|
||
|
||
/**
|
||
* Creates a new context using the given view with this context
|
||
* as the parent.
|
||
*/
|
||
Context.prototype.push = function push (view) {
|
||
return new Context(view, this);
|
||
};
|
||
|
||
/**
|
||
* Returns the value of the given name in this context, traversing
|
||
* up the context hierarchy if the value is absent in this context's view.
|
||
*/
|
||
Context.prototype.lookup = function lookup (name) {
|
||
var cache = this.cache;
|
||
|
||
var value;
|
||
if (cache.hasOwnProperty(name)) {
|
||
value = cache[name];
|
||
} else {
|
||
var context = this, names, index, lookupHit = false;
|
||
|
||
while (context) {
|
||
if (name.indexOf('.') > 0) {
|
||
value = context.view;
|
||
names = name.split('.');
|
||
index = 0;
|
||
|
||
/**
|
||
* Using the dot notion path in `name`, we descend through the
|
||
* nested objects.
|
||
*
|
||
* To be certain that the lookup has been successful, we have to
|
||
* check if the last object in the path actually has the property
|
||
* we are looking for. We store the result in `lookupHit`.
|
||
*
|
||
* This is specially necessary for when the value has been set to
|
||
* `undefined` and we want to avoid looking up parent contexts.
|
||
**/
|
||
while (value != null && index < names.length) {
|
||
if (index === names.length - 1)
|
||
{ lookupHit = hasProperty(value, names[index]); }
|
||
|
||
value = value[names[index++]];
|
||
}
|
||
} else {
|
||
value = context.view[name];
|
||
lookupHit = hasProperty(context.view, name);
|
||
}
|
||
|
||
if (lookupHit)
|
||
{ break; }
|
||
|
||
context = context.parent;
|
||
}
|
||
|
||
cache[name] = value;
|
||
}
|
||
|
||
if (isFunction(value))
|
||
{ value = value.call(this.view); }
|
||
|
||
return value;
|
||
};
|
||
|
||
/**
|
||
* A Writer knows how to take a stream of tokens and render them to a
|
||
* string, given a context. It also maintains a cache of templates to
|
||
* avoid the need to parse the same template twice.
|
||
*/
|
||
function Writer () {
|
||
this.cache = {};
|
||
}
|
||
|
||
/**
|
||
* Clears all cached templates in this writer.
|
||
*/
|
||
Writer.prototype.clearCache = function clearCache () {
|
||
this.cache = {};
|
||
};
|
||
|
||
/**
|
||
* Parses and caches the given `template` and returns the array of tokens
|
||
* that is generated from the parse.
|
||
*/
|
||
Writer.prototype.parse = function parse (template, tags) {
|
||
var cache = this.cache;
|
||
var tokens = cache[template];
|
||
|
||
if (tokens == null)
|
||
{ tokens = cache[template] = parseTemplate(template, tags); }
|
||
|
||
return tokens;
|
||
};
|
||
|
||
/**
|
||
* High-level method that is used to render the given `template` with
|
||
* the given `view`.
|
||
*
|
||
* The optional `partials` argument may be an object that contains the
|
||
* names and templates of partials that are used in the template. It may
|
||
* also be a function that is used to load partial templates on the fly
|
||
* that takes a single argument: the name of the partial.
|
||
*/
|
||
Writer.prototype.render = function render (template, view, partials) {
|
||
var tokens = this.parse(template);
|
||
var context = (view instanceof Context) ? view : new Context(view);
|
||
return this.renderTokens(tokens, context, partials, template);
|
||
};
|
||
|
||
/**
|
||
* Low-level method that renders the given array of `tokens` using
|
||
* the given `context` and `partials`.
|
||
*
|
||
* Note: The `originalTemplate` is only ever used to extract the portion
|
||
* of the original template that was contained in a higher-order section.
|
||
* If the template doesn't use higher-order sections, this argument may
|
||
* be omitted.
|
||
*/
|
||
Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate) {
|
||
var this$1 = this;
|
||
|
||
var buffer = '';
|
||
|
||
var token, symbol, value;
|
||
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
|
||
value = undefined;
|
||
token = tokens[i];
|
||
symbol = token[0];
|
||
|
||
if (symbol === '#') { value = this$1.renderSection(token, context, partials, originalTemplate); }
|
||
else if (symbol === '^') { value = this$1.renderInverted(token, context, partials, originalTemplate); }
|
||
else if (symbol === '>') { value = this$1.renderPartial(token, context, partials, originalTemplate); }
|
||
else if (symbol === '&') { value = this$1.unescapedValue(token, context); }
|
||
else if (symbol === 'name') { value = this$1.escapedValue(token, context); }
|
||
else if (symbol === 'text') { value = this$1.rawValue(token); }
|
||
|
||
if (value !== undefined)
|
||
{ buffer += value; }
|
||
}
|
||
|
||
return buffer;
|
||
};
|
||
|
||
Writer.prototype.renderSection = function renderSection (token, context, partials, originalTemplate) {
|
||
var this$1 = this;
|
||
|
||
var self = this;
|
||
var buffer = '';
|
||
var value = context.lookup(token[1]);
|
||
|
||
// This function is used to render an arbitrary template
|
||
// in the current context by higher-order sections.
|
||
function subRender (template) {
|
||
return self.render(template, context, partials);
|
||
}
|
||
|
||
if (!value) { return; }
|
||
|
||
if (isArray(value)) {
|
||
for (var j = 0, valueLength = value.length; j < valueLength; ++j) {
|
||
buffer += this$1.renderTokens(token[4], context.push(value[j]), partials, originalTemplate);
|
||
}
|
||
} else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') {
|
||
buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate);
|
||
} else if (isFunction(value)) {
|
||
if (typeof originalTemplate !== 'string')
|
||
{ throw new Error('Cannot use higher-order sections without the original template'); }
|
||
|
||
// Extract the portion of the original template that the section contains.
|
||
value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender);
|
||
|
||
if (value != null)
|
||
{ buffer += value; }
|
||
} else {
|
||
buffer += this.renderTokens(token[4], context, partials, originalTemplate);
|
||
}
|
||
return buffer;
|
||
};
|
||
|
||
Writer.prototype.renderInverted = function renderInverted (token, context, partials, originalTemplate) {
|
||
var value = context.lookup(token[1]);
|
||
|
||
// Use JavaScript's definition of falsy. Include empty arrays.
|
||
// See https://github.com/janl/mustache.js/issues/186
|
||
if (!value || (isArray(value) && value.length === 0))
|
||
{ return this.renderTokens(token[4], context, partials, originalTemplate); }
|
||
};
|
||
|
||
Writer.prototype.renderPartial = function renderPartial (token, context, partials) {
|
||
if (!partials) { return; }
|
||
|
||
var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
|
||
if (value != null)
|
||
{ return this.renderTokens(this.parse(value), context, partials, value); }
|
||
};
|
||
|
||
Writer.prototype.unescapedValue = function unescapedValue (token, context) {
|
||
var value = context.lookup(token[1]);
|
||
if (value != null)
|
||
{ return value; }
|
||
};
|
||
|
||
Writer.prototype.escapedValue = function escapedValue (token, context) {
|
||
var value = context.lookup(token[1]);
|
||
if (value != null)
|
||
{ return mustache.escape(value); }
|
||
};
|
||
|
||
Writer.prototype.rawValue = function rawValue (token) {
|
||
return token[1];
|
||
};
|
||
|
||
mustache.name = 'mustache.js';
|
||
mustache.version = '2.3.0';
|
||
mustache.tags = [ '{{', '}}' ];
|
||
|
||
// All high-level mustache.* functions use this writer.
|
||
var defaultWriter = new Writer();
|
||
|
||
/**
|
||
* Clears all cached templates in the default writer.
|
||
*/
|
||
mustache.clearCache = function clearCache () {
|
||
return defaultWriter.clearCache();
|
||
};
|
||
|
||
/**
|
||
* Parses and caches the given template in the default writer and returns the
|
||
* array of tokens it contains. Doing this ahead of time avoids the need to
|
||
* parse templates on the fly as they are rendered.
|
||
*/
|
||
mustache.parse = function parse (template, tags) {
|
||
return defaultWriter.parse(template, tags);
|
||
};
|
||
|
||
/**
|
||
* Renders the `template` with the given `view` and `partials` using the
|
||
* default writer.
|
||
*/
|
||
mustache.render = function render (template, view, partials) {
|
||
if (typeof template !== 'string') {
|
||
throw new TypeError('Invalid template! Template should be a "string" ' +
|
||
'but "' + typeStr(template) + '" was given as the first ' +
|
||
'argument for mustache#render(template, view, partials)');
|
||
}
|
||
|
||
return defaultWriter.render(template, view, partials);
|
||
};
|
||
|
||
// This is here for backwards compatibility with 0.4.x.,
|
||
/*eslint-disable */ // eslint wants camel cased function name
|
||
mustache.to_html = function to_html (template, view, partials, send) {
|
||
/*eslint-enable*/
|
||
|
||
var result = mustache.render(template, view, partials);
|
||
|
||
if (isFunction(send)) {
|
||
send(result);
|
||
} else {
|
||
return result;
|
||
}
|
||
};
|
||
|
||
// Export the escaping function so that the user may override it.
|
||
// See https://github.com/janl/mustache.js/issues/244
|
||
mustache.escape = escapeHtml;
|
||
|
||
// Export these mainly for testing, but also for advanced usage.
|
||
mustache.Scanner = Scanner;
|
||
mustache.Context = Context;
|
||
mustache.Writer = Writer;
|
||
|
||
return mustache;
|
||
}));
|
||
});
|
||
|
||
var html$2 = "\n<style>\n dt-byline {\n font-size: 12px;\n line-height: 18px;\n display: block;\n border-top: 1px solid rgba(0, 0, 0, 0.1);\n border-bottom: 1px solid rgba(0, 0, 0, 0.1);\n color: rgba(0, 0, 0, 0.5);\n padding-top: 12px;\n padding-bottom: 12px;\n }\n dt-article.centered dt-byline {\n text-align: center;\n\n }\n dt-byline a {\n text-decoration: none;\n }\n dt-byline .authors {\n text-align: left;\n }\n dt-byline .name {\n text-transform: uppercase;\n }\n dt-byline .date {\n display: block;\n text-align: left;\n }\n dt-byline .year, dt-byline .month {\n display: inline;\n }\n dt-byline .citation {\n display: block;\n text-align: left;\n }\n dt-byline .citation div {\n display: inline;\n }\n\n @media(min-width: 768px) {\n dt-byline {\n }\n }\n\n @media(min-width: 1024px) {\n dt-byline {\n border-bottom: none;\n margin-bottom: 70px;\n }\n\n dt-byline a:hover {\n color: rgba(0, 0, 0, 0.9);\n }\n\n dt-byline .authors {\n display: inline-block;\n }\n\n dt-byline .author {\n display: inline-block;\n margin-right: 12px;\n /*padding-left: 20px;*/\n /*border-left: 1px solid #ddd;*/\n }\n\n dt-byline .affiliation {\n display: block;\n }\n\n dt-byline .author:last-child {\n margin-right: 0;\n }\n\n dt-byline .name {\n display: block;\n }\n\n dt-byline .date {\n border-left: 1px solid rgba(0, 0, 0, 0.1);\n padding-left: 15px;\n margin-left: 15px;\n display: inline-block;\n }\n dt-byline .year, dt-byline .month {\n display: block;\n }\n\n dt-byline .citation {\n border-left: 1px solid rgba(0, 0, 0, 0.15);\n padding-left: 15px;\n margin-left: 15px;\n display: inline-block;\n }\n dt-byline .citation div {\n display: block;\n }\n }\n</style>\n\n";
|
||
|
||
var template = "\n<div class=\"byline\">\n <div class=\"authors\">\n {{#authors}}\n <div class=\"author\">\n {{#personalURL}}\n <a class=\"name\" href=\"{{personalURL}}\">{{name}}</a>\n {{/personalURL}}\n {{^personalURL}}\n <div class=\"name\">{{name}}</div>\n {{/personalURL}}\n {{#affiliation}}\n {{#affiliationURL}}\n <a class=\"affiliation\" href=\"{{affiliationURL}}\">{{affiliation}}</a>\n {{/affiliationURL}}\n {{^affiliationURL}}\n <div class=\"affiliation\">{{affiliation}}</div>\n {{/affiliationURL}}\n {{/affiliation}}\n </div>\n {{/authors}}\n </div>\n <div class=\"date\">\n <div class=\"month\">{{publishedMonth}}. {{publishedDay}}</div>\n <div class=\"year\">{{publishedYear}}</div>\n </div>\n <a class=\"citation\" href=\"#citation\">\n <div>Citation:</div>\n <div>{{concatenatedAuthors}}, {{publishedYear}}</div>\n </a>\n</div>\n";
|
||
|
||
var byline = function(dom, data) {
|
||
var el = dom.querySelector('dt-byline');
|
||
if (el) {
|
||
el.innerHTML = html$2 + mustache.render(template, data);
|
||
}
|
||
};
|
||
|
||
var html$3 = "\n<style>\n dt-appendix {\n display: block;\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 <a class=\"github-issue\">create an issue on 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 <a class=\"github\">source available on 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";
|
||
|
||
var appendix = function(dom, data) {
|
||
var el = dom.querySelector('dt-appendix');
|
||
if (el) {
|
||
var oldHtml = el.innerHTML;
|
||
el.innerHTML = html$3;
|
||
var div = el.querySelector("div.l-body");
|
||
|
||
if (dom.querySelector("dt-fn")) {
|
||
div.innerHTML = "<h3>Footnotes</h3><dt-fn-list></dt-fn-list>" + div.innerHTML;
|
||
}
|
||
|
||
div.innerHTML = oldHtml + div.innerHTML;
|
||
|
||
|
||
el.querySelector("a.github").setAttribute("href", data.githubUrl);
|
||
el.querySelector("a.github-issue").setAttribute("href", data.githubUrl + "/issues/new");
|
||
el.querySelector(".citation.short").textContent = data.concatenatedAuthors + ", " + '"' + data.title + '", Distill, ' + data.publishedYear + ".";
|
||
var bibtex = "@article{" + data.slug + ",\n";
|
||
bibtex += " author = {" + data.bibtexAuthors + "},\n";
|
||
bibtex += " title = {" + data.title + "},\n";
|
||
bibtex += " journal = {Distill},\n";
|
||
bibtex += " year = {" + data.publishedYear + "},\n";
|
||
bibtex += " note = {" + data.url + "}\n";
|
||
bibtex += "}";
|
||
el.querySelector(".citation.long").textContent = bibtex;
|
||
}
|
||
|
||
};
|
||
|
||
var html$4 = "\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: hsl(223, 9%, 25%);\n text-align: center;\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 fill: none;\n stroke: rgba(255, 255, 255, 0.8);\n stroke-width: 3px;\n}\ndt-footer .logo {\n font-size: 13px;\n font-weight: 300;\n text-transform: uppercase;\n color: rgba(255, 255, 255, 0.8);\n text-decoration: none;\n margin-right: 6px;\n}\n</style>\n\n<div class=\"l-screen-inset\">\n <a href=\"/\" class=\"logo\">\n " + logo + "\n Distill\n </a> is dedicated to clear explanations of machine learning\n</div>\n";
|
||
|
||
var footer = function(dom, data) {
|
||
var el = dom.querySelector("dt-footer");
|
||
if(el) {
|
||
el.innerHTML = html$4;
|
||
} else {
|
||
var footer = dom.createElement("dt-footer");
|
||
footer.innerHTML = html$4;
|
||
var b = dom.querySelector("body");
|
||
b.appendChild(footer);
|
||
}
|
||
};
|
||
|
||
var citation = function(dom, data) {
|
||
var citations = data.citations;
|
||
/*if (data.citations) {
|
||
citations = Object.keys(data.citations).map(c => data.citations[c]);
|
||
citations.sort((a, b) => {
|
||
return a.author.localeCompare(b.author);
|
||
});
|
||
}*/
|
||
|
||
var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
|
||
citeTags.forEach(function (el,n) {
|
||
var key = el.getAttribute("key");
|
||
if (key) {
|
||
var keys = key.split(",");
|
||
var cite_string = inline_cite_short(keys);
|
||
var cite_hover_str = "";
|
||
keys.map(function (key,n) {
|
||
if (n>0) { cite_hover_str += "<br><br>"; }
|
||
cite_hover_str += hover_cite(data.bibliography[key]);
|
||
});
|
||
cite_hover_str = cite_hover_str.replace(/"/g, "'");
|
||
var orig_string = el.innerHTML;
|
||
if (orig_string != "") { orig_string += " "; }
|
||
el.innerHTML = "<span id=\"citation-" + n + "\" data-hover=\"" + cite_hover_str + "\">" + orig_string + cite_string + "</span>";
|
||
}
|
||
});
|
||
|
||
var bibEl = dom.querySelector("dt-bibliography");
|
||
if (bibEl) {
|
||
var ol = dom.createElement("ol");
|
||
citations.forEach(function (key) {
|
||
var el = dom.createElement("li");
|
||
el.innerHTML = bibliography_cite(data.bibliography[key]);
|
||
ol.appendChild(el);
|
||
});
|
||
bibEl.appendChild(ol);
|
||
}
|
||
|
||
function inline_cite_short(keys){
|
||
function cite_string(key){
|
||
if (key in data.bibliography){
|
||
var n = data.citations.indexOf(key)+1;
|
||
return ""+n;
|
||
} else {
|
||
return "?";
|
||
}
|
||
}
|
||
return "["+keys.map(cite_string).join(", ")+"]";
|
||
}
|
||
|
||
function inline_cite_long(keys){
|
||
function cite_string(key){
|
||
if (key in data.bibliography){
|
||
var ent = data.bibliography[key];
|
||
var names = ent.author.split(" and ");
|
||
names = names.map(function (name) { return name.split(",")[0].trim(); });
|
||
var year = ent.year;
|
||
if (names.length == 1) { return names[0] + ", " + year; }
|
||
if (names.length == 2) { return names[0] + " & " + names[1] + ", " + year; }
|
||
if (names.length > 2) { return names[0] + ", et al., " + year; }
|
||
} else {
|
||
return "?";
|
||
}
|
||
}
|
||
return keys.map(cite_string).join(", ");
|
||
}
|
||
|
||
function author_string(ent, template, sep, finalSep){
|
||
var names = ent.author.split(" and ");
|
||
var name_strings = names.map(function (name) {
|
||
var last = name.split(",")[0].trim();
|
||
var firsts = name.split(",")[1];
|
||
var initials = "";
|
||
if (firsts != undefined) {
|
||
initials = firsts.trim().split(" ").map(function (s) { return s.trim()[0]; });
|
||
initials = initials.join(".")+".";
|
||
}
|
||
return template.replace("F", firsts)
|
||
.replace("L", last)
|
||
.replace("I", initials);
|
||
});
|
||
if (names.length > 1) {
|
||
var str = name_strings.slice(0, names.length-1).join(sep);
|
||
str += (finalSep || sep) + name_strings[names.length-1];
|
||
return str;
|
||
} else {
|
||
return name_strings[0];
|
||
}
|
||
}
|
||
|
||
function venue_string(ent) {
|
||
var cite = (ent.journal || ent.booktitle || "");
|
||
if ("volume" in ent){
|
||
var issue = ent.issue || ent.number;
|
||
issue = (issue != undefined)? "("+issue+")" : "";
|
||
cite += ", Vol " + ent.volume + issue;
|
||
}
|
||
if ("pages" in ent){
|
||
cite += ", pp. " + ent.pages;
|
||
}
|
||
cite += ". ";
|
||
if ("publisher" in ent){
|
||
cite += ent.publisher + ".";
|
||
}
|
||
return cite;
|
||
}
|
||
|
||
function link_string(ent){
|
||
if ("url" in ent){
|
||
if (ent.url.slice(-4) == ".pdf"){
|
||
var label = "PDF";
|
||
} else if (ent.url.slice(-5) == ".html") {
|
||
var label = "HTML";
|
||
}
|
||
return ("  <a href=\"" + (ent.url) + "\">[" + (label||"link") + "]</a>");
|
||
}/* else if ("doi" in ent){
|
||
return `  <a href="https://doi.org/${ent.doi}" >[DOI]</a>`;
|
||
}*/ else {
|
||
return "";
|
||
}
|
||
}
|
||
function doi_string(ent, new_line){
|
||
if ("doi" in ent) {
|
||
return ((new_line?"<br>":"") + " <a href=\"https://doi.org/" + (ent.doi) + "\" style=\"text-decoration:inherit;\">DOI: " + (ent.doi) + "</a>");
|
||
} else {
|
||
return "";
|
||
}
|
||
}
|
||
|
||
function bibliography_cite(ent, fancy){
|
||
if (ent){
|
||
var cite = author_string(ent, "L, I", ", ", " and ");
|
||
cite += ", " + ent.year + ". ";
|
||
cite += "<b>" + ent.title + "</b>. ";
|
||
cite += venue_string(ent);
|
||
cite += doi_string(ent);
|
||
cite += link_string(ent);
|
||
return cite
|
||
} else {
|
||
return "?";
|
||
}
|
||
}
|
||
|
||
function hover_cite(ent){
|
||
if (ent){
|
||
var cite = "";
|
||
cite += "<b>" + ent.title + "</b>";
|
||
cite += link_string(ent);
|
||
cite += "<br>";
|
||
cite += author_string(ent, "I L", ", ") + ".<br>";
|
||
cite += venue_string(ent).trim() + " " + ent.year + ". ";
|
||
cite += doi_string(ent, true);
|
||
return cite
|
||
} else {
|
||
return "?";
|
||
}
|
||
}
|
||
|
||
|
||
//https://scholar.google.com/scholar?q=allintitle%3ADocument+author%3Aolah
|
||
function get_GS_URL(ent){
|
||
if (ent){
|
||
var names = ent.author.split(" and ");
|
||
names = names.map(function (name) { return name.split(",")[0].trim(); });
|
||
var title = ent.title.split(" ");//.replace(/[,:]/, "")
|
||
var url = "http://search.labs.crossref.org/dois?";//""https://scholar.google.com/scholar?"
|
||
url += uris({q: names.join(" ") + " " + title.join(" ")});
|
||
}
|
||
|
||
}
|
||
};
|
||
|
||
var footnote = function(dom, data) {
|
||
|
||
var fnTags = [].slice.apply(dom.querySelectorAll("dt-fn"));
|
||
var fnContent = [];
|
||
fnTags.forEach(function (el,n) {
|
||
var content = el.innerHTML;
|
||
fnContent.push(content);
|
||
n = (n+1)+"";
|
||
var key = "fn-"+n;
|
||
var escaped_content = content.replace(/"/g, "'");
|
||
el.innerHTML = "<sup><span id=\"" + key + "\" data-hover=\"" + escaped_content + "\" style=\"cursor:pointer\">" + n + "</span></sup>";
|
||
});
|
||
|
||
var fnList = dom.querySelector("dt-fn-list");
|
||
if (fnList) {
|
||
var ol = dom.createElement("ol");
|
||
fnContent.forEach(function (content) {
|
||
var el = dom.createElement("li");
|
||
el.innerHTML = content;
|
||
ol.appendChild(el);
|
||
});
|
||
fnList.appendChild(ol);
|
||
}
|
||
|
||
};
|
||
|
||
var marked = createCommonjsModule(function (module, exports) {
|
||
/**
|
||
* marked - a markdown parser
|
||
* Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
|
||
* https://github.com/chjj/marked
|
||
*/
|
||
|
||
(function() {
|
||
|
||
/**
|
||
* Block-Level Grammar
|
||
*/
|
||
|
||
var block = {
|
||
newline: /^\n+/,
|
||
code: /^( {4}[^\n]+\n*)+/,
|
||
fences: noop,
|
||
hr: /^( *[-*_]){3,} *(?:\n+|$)/,
|
||
heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
|
||
nptable: noop,
|
||
lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
|
||
blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
|
||
list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
|
||
html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
|
||
def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
|
||
table: noop,
|
||
paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
|
||
text: /^[^\n]+/
|
||
};
|
||
|
||
block.bullet = /(?:[*+-]|\d+\.)/;
|
||
block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
|
||
block.item = replace(block.item, 'gm')
|
||
(/bull/g, block.bullet)
|
||
();
|
||
|
||
block.list = replace(block.list)
|
||
(/bull/g, block.bullet)
|
||
('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
|
||
('def', '\\n+(?=' + block.def.source + ')')
|
||
();
|
||
|
||
block.blockquote = replace(block.blockquote)
|
||
('def', block.def)
|
||
();
|
||
|
||
block._tag = '(?!(?:'
|
||
+ 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
|
||
+ '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
|
||
+ '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
|
||
|
||
block.html = replace(block.html)
|
||
('comment', /<!--[\s\S]*?-->/)
|
||
('closed', /<(tag)[\s\S]+?<\/\1>/)
|
||
('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
|
||
(/tag/g, block._tag)
|
||
();
|
||
|
||
block.paragraph = replace(block.paragraph)
|
||
('hr', block.hr)
|
||
('heading', block.heading)
|
||
('lheading', block.lheading)
|
||
('blockquote', block.blockquote)
|
||
('tag', '<' + block._tag)
|
||
('def', block.def)
|
||
();
|
||
|
||
/**
|
||
* Normal Block Grammar
|
||
*/
|
||
|
||
block.normal = merge({}, block);
|
||
|
||
/**
|
||
* GFM Block Grammar
|
||
*/
|
||
|
||
block.gfm = merge({}, block.normal, {
|
||
fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
|
||
paragraph: /^/,
|
||
heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
|
||
});
|
||
|
||
block.gfm.paragraph = replace(block.paragraph)
|
||
('(?!', '(?!'
|
||
+ block.gfm.fences.source.replace('\\1', '\\2') + '|'
|
||
+ block.list.source.replace('\\1', '\\3') + '|')
|
||
();
|
||
|
||
/**
|
||
* GFM + Tables Block Grammar
|
||
*/
|
||
|
||
block.tables = merge({}, block.gfm, {
|
||
nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
|
||
table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
|
||
});
|
||
|
||
/**
|
||
* Block Lexer
|
||
*/
|
||
|
||
function Lexer(options) {
|
||
this.tokens = [];
|
||
this.tokens.links = {};
|
||
this.options = options || marked.defaults;
|
||
this.rules = block.normal;
|
||
|
||
if (this.options.gfm) {
|
||
if (this.options.tables) {
|
||
this.rules = block.tables;
|
||
} else {
|
||
this.rules = block.gfm;
|
||
}
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Expose Block Rules
|
||
*/
|
||
|
||
Lexer.rules = block;
|
||
|
||
/**
|
||
* Static Lex Method
|
||
*/
|
||
|
||
Lexer.lex = function(src, options) {
|
||
var lexer = new Lexer(options);
|
||
return lexer.lex(src);
|
||
};
|
||
|
||
/**
|
||
* Preprocessing
|
||
*/
|
||
|
||
Lexer.prototype.lex = function(src) {
|
||
src = src
|
||
.replace(/\r\n|\r/g, '\n')
|
||
.replace(/\t/g, ' ')
|
||
.replace(/\u00a0/g, ' ')
|
||
.replace(/\u2424/g, '\n');
|
||
|
||
return this.token(src, true);
|
||
};
|
||
|
||
/**
|
||
* Lexing
|
||
*/
|
||
|
||
Lexer.prototype.token = function(src, top, bq) {
|
||
var this$1 = this;
|
||
|
||
var src = src.replace(/^ +$/gm, '')
|
||
, next
|
||
, loose
|
||
, cap
|
||
, bull
|
||
, b
|
||
, item
|
||
, space
|
||
, i
|
||
, l;
|
||
|
||
while (src) {
|
||
// newline
|
||
if (cap = this$1.rules.newline.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
if (cap[0].length > 1) {
|
||
this$1.tokens.push({
|
||
type: 'space'
|
||
});
|
||
}
|
||
}
|
||
|
||
// code
|
||
if (cap = this$1.rules.code.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
cap = cap[0].replace(/^ {4}/gm, '');
|
||
this$1.tokens.push({
|
||
type: 'code',
|
||
text: !this$1.options.pedantic
|
||
? cap.replace(/\n+$/, '')
|
||
: cap
|
||
});
|
||
continue;
|
||
}
|
||
|
||
// fences (gfm)
|
||
if (cap = this$1.rules.fences.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
this$1.tokens.push({
|
||
type: 'code',
|
||
lang: cap[2],
|
||
text: cap[3] || ''
|
||
});
|
||
continue;
|
||
}
|
||
|
||
// heading
|
||
if (cap = this$1.rules.heading.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
this$1.tokens.push({
|
||
type: 'heading',
|
||
depth: cap[1].length,
|
||
text: cap[2]
|
||
});
|
||
continue;
|
||
}
|
||
|
||
// table no leading pipe (gfm)
|
||
if (top && (cap = this$1.rules.nptable.exec(src))) {
|
||
src = src.substring(cap[0].length);
|
||
|
||
item = {
|
||
type: 'table',
|
||
header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
|
||
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
||
cells: cap[3].replace(/\n$/, '').split('\n')
|
||
};
|
||
|
||
for (i = 0; i < item.align.length; i++) {
|
||
if (/^ *-+: *$/.test(item.align[i])) {
|
||
item.align[i] = 'right';
|
||
} else if (/^ *:-+: *$/.test(item.align[i])) {
|
||
item.align[i] = 'center';
|
||
} else if (/^ *:-+ *$/.test(item.align[i])) {
|
||
item.align[i] = 'left';
|
||
} else {
|
||
item.align[i] = null;
|
||
}
|
||
}
|
||
|
||
for (i = 0; i < item.cells.length; i++) {
|
||
item.cells[i] = item.cells[i].split(/ *\| */);
|
||
}
|
||
|
||
this$1.tokens.push(item);
|
||
|
||
continue;
|
||
}
|
||
|
||
// lheading
|
||
if (cap = this$1.rules.lheading.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
this$1.tokens.push({
|
||
type: 'heading',
|
||
depth: cap[2] === '=' ? 1 : 2,
|
||
text: cap[1]
|
||
});
|
||
continue;
|
||
}
|
||
|
||
// hr
|
||
if (cap = this$1.rules.hr.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
this$1.tokens.push({
|
||
type: 'hr'
|
||
});
|
||
continue;
|
||
}
|
||
|
||
// blockquote
|
||
if (cap = this$1.rules.blockquote.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
|
||
this$1.tokens.push({
|
||
type: 'blockquote_start'
|
||
});
|
||
|
||
cap = cap[0].replace(/^ *> ?/gm, '');
|
||
|
||
// Pass `top` to keep the current
|
||
// "toplevel" state. This is exactly
|
||
// how markdown.pl works.
|
||
this$1.token(cap, top, true);
|
||
|
||
this$1.tokens.push({
|
||
type: 'blockquote_end'
|
||
});
|
||
|
||
continue;
|
||
}
|
||
|
||
// list
|
||
if (cap = this$1.rules.list.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
bull = cap[2];
|
||
|
||
this$1.tokens.push({
|
||
type: 'list_start',
|
||
ordered: bull.length > 1
|
||
});
|
||
|
||
// Get each top-level item.
|
||
cap = cap[0].match(this$1.rules.item);
|
||
|
||
next = false;
|
||
l = cap.length;
|
||
i = 0;
|
||
|
||
for (; i < l; i++) {
|
||
item = cap[i];
|
||
|
||
// Remove the list item's bullet
|
||
// so it is seen as the next token.
|
||
space = item.length;
|
||
item = item.replace(/^ *([*+-]|\d+\.) +/, '');
|
||
|
||
// Outdent whatever the
|
||
// list item contains. Hacky.
|
||
if (~item.indexOf('\n ')) {
|
||
space -= item.length;
|
||
item = !this$1.options.pedantic
|
||
? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
|
||
: item.replace(/^ {1,4}/gm, '');
|
||
}
|
||
|
||
// Determine whether the next list item belongs here.
|
||
// Backpedal if it does not belong in this list.
|
||
if (this$1.options.smartLists && i !== l - 1) {
|
||
b = block.bullet.exec(cap[i + 1])[0];
|
||
if (bull !== b && !(bull.length > 1 && b.length > 1)) {
|
||
src = cap.slice(i + 1).join('\n') + src;
|
||
i = l - 1;
|
||
}
|
||
}
|
||
|
||
// Determine whether item is loose or not.
|
||
// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
|
||
// for discount behavior.
|
||
loose = next || /\n\n(?!\s*$)/.test(item);
|
||
if (i !== l - 1) {
|
||
next = item.charAt(item.length - 1) === '\n';
|
||
if (!loose) { loose = next; }
|
||
}
|
||
|
||
this$1.tokens.push({
|
||
type: loose
|
||
? 'loose_item_start'
|
||
: 'list_item_start'
|
||
});
|
||
|
||
// Recurse.
|
||
this$1.token(item, false, bq);
|
||
|
||
this$1.tokens.push({
|
||
type: 'list_item_end'
|
||
});
|
||
}
|
||
|
||
this$1.tokens.push({
|
||
type: 'list_end'
|
||
});
|
||
|
||
continue;
|
||
}
|
||
|
||
// html
|
||
if (cap = this$1.rules.html.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
this$1.tokens.push({
|
||
type: this$1.options.sanitize
|
||
? 'paragraph'
|
||
: 'html',
|
||
pre: !this$1.options.sanitizer
|
||
&& (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
|
||
text: cap[0]
|
||
});
|
||
continue;
|
||
}
|
||
|
||
// def
|
||
if ((!bq && top) && (cap = this$1.rules.def.exec(src))) {
|
||
src = src.substring(cap[0].length);
|
||
this$1.tokens.links[cap[1].toLowerCase()] = {
|
||
href: cap[2],
|
||
title: cap[3]
|
||
};
|
||
continue;
|
||
}
|
||
|
||
// table (gfm)
|
||
if (top && (cap = this$1.rules.table.exec(src))) {
|
||
src = src.substring(cap[0].length);
|
||
|
||
item = {
|
||
type: 'table',
|
||
header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
|
||
align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
|
||
cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
|
||
};
|
||
|
||
for (i = 0; i < item.align.length; i++) {
|
||
if (/^ *-+: *$/.test(item.align[i])) {
|
||
item.align[i] = 'right';
|
||
} else if (/^ *:-+: *$/.test(item.align[i])) {
|
||
item.align[i] = 'center';
|
||
} else if (/^ *:-+ *$/.test(item.align[i])) {
|
||
item.align[i] = 'left';
|
||
} else {
|
||
item.align[i] = null;
|
||
}
|
||
}
|
||
|
||
for (i = 0; i < item.cells.length; i++) {
|
||
item.cells[i] = item.cells[i]
|
||
.replace(/^ *\| *| *\| *$/g, '')
|
||
.split(/ *\| */);
|
||
}
|
||
|
||
this$1.tokens.push(item);
|
||
|
||
continue;
|
||
}
|
||
|
||
// top-level paragraph
|
||
if (top && (cap = this$1.rules.paragraph.exec(src))) {
|
||
src = src.substring(cap[0].length);
|
||
this$1.tokens.push({
|
||
type: 'paragraph',
|
||
text: cap[1].charAt(cap[1].length - 1) === '\n'
|
||
? cap[1].slice(0, -1)
|
||
: cap[1]
|
||
});
|
||
continue;
|
||
}
|
||
|
||
// text
|
||
if (cap = this$1.rules.text.exec(src)) {
|
||
// Top-level should never reach here.
|
||
src = src.substring(cap[0].length);
|
||
this$1.tokens.push({
|
||
type: 'text',
|
||
text: cap[0]
|
||
});
|
||
continue;
|
||
}
|
||
|
||
if (src) {
|
||
throw new
|
||
Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
||
}
|
||
}
|
||
|
||
return this.tokens;
|
||
};
|
||
|
||
/**
|
||
* Inline-Level Grammar
|
||
*/
|
||
|
||
var inline = {
|
||
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
|
||
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
|
||
url: noop,
|
||
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
|
||
link: /^!?\[(inside)\]\(href\)/,
|
||
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
|
||
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
|
||
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
|
||
em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
|
||
code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
|
||
br: /^ {2,}\n(?!\s*$)/,
|
||
del: noop,
|
||
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
|
||
};
|
||
|
||
inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
|
||
inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
|
||
|
||
inline.link = replace(inline.link)
|
||
('inside', inline._inside)
|
||
('href', inline._href)
|
||
();
|
||
|
||
inline.reflink = replace(inline.reflink)
|
||
('inside', inline._inside)
|
||
();
|
||
|
||
/**
|
||
* Normal Inline Grammar
|
||
*/
|
||
|
||
inline.normal = merge({}, inline);
|
||
|
||
/**
|
||
* Pedantic Inline Grammar
|
||
*/
|
||
|
||
inline.pedantic = merge({}, inline.normal, {
|
||
strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
|
||
em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
|
||
});
|
||
|
||
/**
|
||
* GFM Inline Grammar
|
||
*/
|
||
|
||
inline.gfm = merge({}, inline.normal, {
|
||
escape: replace(inline.escape)('])', '~|])')(),
|
||
url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
|
||
del: /^~~(?=\S)([\s\S]*?\S)~~/,
|
||
text: replace(inline.text)
|
||
(']|', '~]|')
|
||
('|', '|https?://|')
|
||
()
|
||
});
|
||
|
||
/**
|
||
* GFM + Line Breaks Inline Grammar
|
||
*/
|
||
|
||
inline.breaks = merge({}, inline.gfm, {
|
||
br: replace(inline.br)('{2,}', '*')(),
|
||
text: replace(inline.gfm.text)('{2,}', '*')()
|
||
});
|
||
|
||
/**
|
||
* Inline Lexer & Compiler
|
||
*/
|
||
|
||
function InlineLexer(links, options) {
|
||
this.options = options || marked.defaults;
|
||
this.links = links;
|
||
this.rules = inline.normal;
|
||
this.renderer = this.options.renderer || new Renderer;
|
||
this.renderer.options = this.options;
|
||
|
||
if (!this.links) {
|
||
throw new
|
||
Error('Tokens array requires a `links` property.');
|
||
}
|
||
|
||
if (this.options.gfm) {
|
||
if (this.options.breaks) {
|
||
this.rules = inline.breaks;
|
||
} else {
|
||
this.rules = inline.gfm;
|
||
}
|
||
} else if (this.options.pedantic) {
|
||
this.rules = inline.pedantic;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Expose Inline Rules
|
||
*/
|
||
|
||
InlineLexer.rules = inline;
|
||
|
||
/**
|
||
* Static Lexing/Compiling Method
|
||
*/
|
||
|
||
InlineLexer.output = function(src, links, options) {
|
||
var inline = new InlineLexer(links, options);
|
||
return inline.output(src);
|
||
};
|
||
|
||
/**
|
||
* Lexing/Compiling
|
||
*/
|
||
|
||
InlineLexer.prototype.output = function(src) {
|
||
var this$1 = this;
|
||
|
||
var out = ''
|
||
, link
|
||
, text
|
||
, href
|
||
, cap;
|
||
|
||
while (src) {
|
||
// escape
|
||
if (cap = this$1.rules.escape.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
out += cap[1];
|
||
continue;
|
||
}
|
||
|
||
// autolink
|
||
if (cap = this$1.rules.autolink.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
if (cap[2] === '@') {
|
||
text = cap[1].charAt(6) === ':'
|
||
? this$1.mangle(cap[1].substring(7))
|
||
: this$1.mangle(cap[1]);
|
||
href = this$1.mangle('mailto:') + text;
|
||
} else {
|
||
text = escape(cap[1]);
|
||
href = text;
|
||
}
|
||
out += this$1.renderer.link(href, null, text);
|
||
continue;
|
||
}
|
||
|
||
// url (gfm)
|
||
if (!this$1.inLink && (cap = this$1.rules.url.exec(src))) {
|
||
src = src.substring(cap[0].length);
|
||
text = escape(cap[1]);
|
||
href = text;
|
||
out += this$1.renderer.link(href, null, text);
|
||
continue;
|
||
}
|
||
|
||
// tag
|
||
if (cap = this$1.rules.tag.exec(src)) {
|
||
if (!this$1.inLink && /^<a /i.test(cap[0])) {
|
||
this$1.inLink = true;
|
||
} else if (this$1.inLink && /^<\/a>/i.test(cap[0])) {
|
||
this$1.inLink = false;
|
||
}
|
||
src = src.substring(cap[0].length);
|
||
out += this$1.options.sanitize
|
||
? this$1.options.sanitizer
|
||
? this$1.options.sanitizer(cap[0])
|
||
: escape(cap[0])
|
||
: cap[0];
|
||
continue;
|
||
}
|
||
|
||
// link
|
||
if (cap = this$1.rules.link.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
this$1.inLink = true;
|
||
out += this$1.outputLink(cap, {
|
||
href: cap[2],
|
||
title: cap[3]
|
||
});
|
||
this$1.inLink = false;
|
||
continue;
|
||
}
|
||
|
||
// reflink, nolink
|
||
if ((cap = this$1.rules.reflink.exec(src))
|
||
|| (cap = this$1.rules.nolink.exec(src))) {
|
||
src = src.substring(cap[0].length);
|
||
link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
|
||
link = this$1.links[link.toLowerCase()];
|
||
if (!link || !link.href) {
|
||
out += cap[0].charAt(0);
|
||
src = cap[0].substring(1) + src;
|
||
continue;
|
||
}
|
||
this$1.inLink = true;
|
||
out += this$1.outputLink(cap, link);
|
||
this$1.inLink = false;
|
||
continue;
|
||
}
|
||
|
||
// strong
|
||
if (cap = this$1.rules.strong.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
out += this$1.renderer.strong(this$1.output(cap[2] || cap[1]));
|
||
continue;
|
||
}
|
||
|
||
// em
|
||
if (cap = this$1.rules.em.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
out += this$1.renderer.em(this$1.output(cap[2] || cap[1]));
|
||
continue;
|
||
}
|
||
|
||
// code
|
||
if (cap = this$1.rules.code.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
out += this$1.renderer.codespan(escape(cap[2], true));
|
||
continue;
|
||
}
|
||
|
||
// br
|
||
if (cap = this$1.rules.br.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
out += this$1.renderer.br();
|
||
continue;
|
||
}
|
||
|
||
// del (gfm)
|
||
if (cap = this$1.rules.del.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
out += this$1.renderer.del(this$1.output(cap[1]));
|
||
continue;
|
||
}
|
||
|
||
// text
|
||
if (cap = this$1.rules.text.exec(src)) {
|
||
src = src.substring(cap[0].length);
|
||
out += this$1.renderer.text(escape(this$1.smartypants(cap[0])));
|
||
continue;
|
||
}
|
||
|
||
if (src) {
|
||
throw new
|
||
Error('Infinite loop on byte: ' + src.charCodeAt(0));
|
||
}
|
||
}
|
||
|
||
return out;
|
||
};
|
||
|
||
/**
|
||
* Compile Link
|
||
*/
|
||
|
||
InlineLexer.prototype.outputLink = function(cap, link) {
|
||
var href = escape(link.href)
|
||
, title = link.title ? escape(link.title) : null;
|
||
|
||
return cap[0].charAt(0) !== '!'
|
||
? this.renderer.link(href, title, this.output(cap[1]))
|
||
: this.renderer.image(href, title, escape(cap[1]));
|
||
};
|
||
|
||
/**
|
||
* Smartypants Transformations
|
||
*/
|
||
|
||
InlineLexer.prototype.smartypants = function(text) {
|
||
if (!this.options.smartypants) { return text; }
|
||
return text
|
||
// em-dashes
|
||
.replace(/---/g, '\u2014')
|
||
// en-dashes
|
||
.replace(/--/g, '\u2013')
|
||
// opening singles
|
||
.replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
|
||
// closing singles & apostrophes
|
||
.replace(/'/g, '\u2019')
|
||
// opening doubles
|
||
.replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
|
||
// closing doubles
|
||
.replace(/"/g, '\u201d')
|
||
// ellipses
|
||
.replace(/\.{3}/g, '\u2026');
|
||
};
|
||
|
||
/**
|
||
* Mangle Links
|
||
*/
|
||
|
||
InlineLexer.prototype.mangle = function(text) {
|
||
if (!this.options.mangle) { return text; }
|
||
var out = ''
|
||
, l = text.length
|
||
, i = 0
|
||
, ch;
|
||
|
||
for (; i < l; i++) {
|
||
ch = text.charCodeAt(i);
|
||
if (Math.random() > 0.5) {
|
||
ch = 'x' + ch.toString(16);
|
||
}
|
||
out += '&#' + ch + ';';
|
||
}
|
||
|
||
return out;
|
||
};
|
||
|
||
/**
|
||
* Renderer
|
||
*/
|
||
|
||
function Renderer(options) {
|
||
this.options = options || {};
|
||
}
|
||
|
||
Renderer.prototype.code = function(code, lang, escaped) {
|
||
if (this.options.highlight) {
|
||
var out = this.options.highlight(code, lang);
|
||
if (out != null && out !== code) {
|
||
escaped = true;
|
||
code = out;
|
||
}
|
||
}
|
||
|
||
if (!lang) {
|
||
return '<pre><code>'
|
||
+ (escaped ? code : escape(code, true))
|
||
+ '\n</code></pre>';
|
||
}
|
||
|
||
return '<pre><code class="'
|
||
+ this.options.langPrefix
|
||
+ escape(lang, true)
|
||
+ '">'
|
||
+ (escaped ? code : escape(code, true))
|
||
+ '\n</code></pre>\n';
|
||
};
|
||
|
||
Renderer.prototype.blockquote = function(quote) {
|
||
return '<blockquote>\n' + quote + '</blockquote>\n';
|
||
};
|
||
|
||
Renderer.prototype.html = function(html) {
|
||
return html;
|
||
};
|
||
|
||
Renderer.prototype.heading = function(text, level, raw) {
|
||
return '<h'
|
||
+ level
|
||
+ ' id="'
|
||
+ this.options.headerPrefix
|
||
+ raw.toLowerCase().replace(/[^\w]+/g, '-')
|
||
+ '">'
|
||
+ text
|
||
+ '</h'
|
||
+ level
|
||
+ '>\n';
|
||
};
|
||
|
||
Renderer.prototype.hr = function() {
|
||
return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
|
||
};
|
||
|
||
Renderer.prototype.list = function(body, ordered) {
|
||
var type = ordered ? 'ol' : 'ul';
|
||
return '<' + type + '>\n' + body + '</' + type + '>\n';
|
||
};
|
||
|
||
Renderer.prototype.listitem = function(text) {
|
||
return '<li>' + text + '</li>\n';
|
||
};
|
||
|
||
Renderer.prototype.paragraph = function(text) {
|
||
return '<p>' + text + '</p>\n';
|
||
};
|
||
|
||
Renderer.prototype.table = function(header, body) {
|
||
return '<table>\n'
|
||
+ '<thead>\n'
|
||
+ header
|
||
+ '</thead>\n'
|
||
+ '<tbody>\n'
|
||
+ body
|
||
+ '</tbody>\n'
|
||
+ '</table>\n';
|
||
};
|
||
|
||
Renderer.prototype.tablerow = function(content) {
|
||
return '<tr>\n' + content + '</tr>\n';
|
||
};
|
||
|
||
Renderer.prototype.tablecell = function(content, flags) {
|
||
var type = flags.header ? 'th' : 'td';
|
||
var tag = flags.align
|
||
? '<' + type + ' style="text-align:' + flags.align + '">'
|
||
: '<' + type + '>';
|
||
return tag + content + '</' + type + '>\n';
|
||
};
|
||
|
||
// span level renderer
|
||
Renderer.prototype.strong = function(text) {
|
||
return '<strong>' + text + '</strong>';
|
||
};
|
||
|
||
Renderer.prototype.em = function(text) {
|
||
return '<em>' + text + '</em>';
|
||
};
|
||
|
||
Renderer.prototype.codespan = function(text) {
|
||
return '<code>' + text + '</code>';
|
||
};
|
||
|
||
Renderer.prototype.br = function() {
|
||
return this.options.xhtml ? '<br/>' : '<br>';
|
||
};
|
||
|
||
Renderer.prototype.del = function(text) {
|
||
return '<del>' + text + '</del>';
|
||
};
|
||
|
||
Renderer.prototype.link = function(href, title, text) {
|
||
if (this.options.sanitize) {
|
||
try {
|
||
var prot = decodeURIComponent(unescape(href))
|
||
.replace(/[^\w:]/g, '')
|
||
.toLowerCase();
|
||
} catch (e) {
|
||
return '';
|
||
}
|
||
if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
|
||
return '';
|
||
}
|
||
}
|
||
var out = '<a href="' + href + '"';
|
||
if (title) {
|
||
out += ' title="' + title + '"';
|
||
}
|
||
out += '>' + text + '</a>';
|
||
return out;
|
||
};
|
||
|
||
Renderer.prototype.image = function(href, title, text) {
|
||
var out = '<img src="' + href + '" alt="' + text + '"';
|
||
if (title) {
|
||
out += ' title="' + title + '"';
|
||
}
|
||
out += this.options.xhtml ? '/>' : '>';
|
||
return out;
|
||
};
|
||
|
||
Renderer.prototype.text = function(text) {
|
||
return text;
|
||
};
|
||
|
||
/**
|
||
* Parsing & Compiling
|
||
*/
|
||
|
||
function Parser(options) {
|
||
this.tokens = [];
|
||
this.token = null;
|
||
this.options = options || marked.defaults;
|
||
this.options.renderer = this.options.renderer || new Renderer;
|
||
this.renderer = this.options.renderer;
|
||
this.renderer.options = this.options;
|
||
}
|
||
|
||
/**
|
||
* Static Parse Method
|
||
*/
|
||
|
||
Parser.parse = function(src, options, renderer) {
|
||
var parser = new Parser(options, renderer);
|
||
return parser.parse(src);
|
||
};
|
||
|
||
/**
|
||
* Parse Loop
|
||
*/
|
||
|
||
Parser.prototype.parse = function(src) {
|
||
var this$1 = this;
|
||
|
||
this.inline = new InlineLexer(src.links, this.options, this.renderer);
|
||
this.tokens = src.reverse();
|
||
|
||
var out = '';
|
||
while (this.next()) {
|
||
out += this$1.tok();
|
||
}
|
||
|
||
return out;
|
||
};
|
||
|
||
/**
|
||
* Next Token
|
||
*/
|
||
|
||
Parser.prototype.next = function() {
|
||
return this.token = this.tokens.pop();
|
||
};
|
||
|
||
/**
|
||
* Preview Next Token
|
||
*/
|
||
|
||
Parser.prototype.peek = function() {
|
||
return this.tokens[this.tokens.length - 1] || 0;
|
||
};
|
||
|
||
/**
|
||
* Parse Text Tokens
|
||
*/
|
||
|
||
Parser.prototype.parseText = function() {
|
||
var this$1 = this;
|
||
|
||
var body = this.token.text;
|
||
|
||
while (this.peek().type === 'text') {
|
||
body += '\n' + this$1.next().text;
|
||
}
|
||
|
||
return this.inline.output(body);
|
||
};
|
||
|
||
/**
|
||
* Parse Current Token
|
||
*/
|
||
|
||
Parser.prototype.tok = function() {
|
||
var this$1 = this;
|
||
|
||
switch (this.token.type) {
|
||
case 'space': {
|
||
return '';
|
||
}
|
||
case 'hr': {
|
||
return this.renderer.hr();
|
||
}
|
||
case 'heading': {
|
||
return this.renderer.heading(
|
||
this.inline.output(this.token.text),
|
||
this.token.depth,
|
||
this.token.text);
|
||
}
|
||
case 'code': {
|
||
return this.renderer.code(this.token.text,
|
||
this.token.lang,
|
||
this.token.escaped);
|
||
}
|
||
case 'table': {
|
||
var header = ''
|
||
, body = ''
|
||
, i
|
||
, row
|
||
, cell
|
||
, flags
|
||
, j;
|
||
|
||
// header
|
||
cell = '';
|
||
for (i = 0; i < this.token.header.length; i++) {
|
||
flags = { header: true, align: this$1.token.align[i] };
|
||
cell += this$1.renderer.tablecell(
|
||
this$1.inline.output(this$1.token.header[i]),
|
||
{ header: true, align: this$1.token.align[i] }
|
||
);
|
||
}
|
||
header += this.renderer.tablerow(cell);
|
||
|
||
for (i = 0; i < this.token.cells.length; i++) {
|
||
row = this$1.token.cells[i];
|
||
|
||
cell = '';
|
||
for (j = 0; j < row.length; j++) {
|
||
cell += this$1.renderer.tablecell(
|
||
this$1.inline.output(row[j]),
|
||
{ header: false, align: this$1.token.align[j] }
|
||
);
|
||
}
|
||
|
||
body += this$1.renderer.tablerow(cell);
|
||
}
|
||
return this.renderer.table(header, body);
|
||
}
|
||
case 'blockquote_start': {
|
||
var body = '';
|
||
|
||
while (this.next().type !== 'blockquote_end') {
|
||
body += this$1.tok();
|
||
}
|
||
|
||
return this.renderer.blockquote(body);
|
||
}
|
||
case 'list_start': {
|
||
var body = ''
|
||
, ordered = this.token.ordered;
|
||
|
||
while (this.next().type !== 'list_end') {
|
||
body += this$1.tok();
|
||
}
|
||
|
||
return this.renderer.list(body, ordered);
|
||
}
|
||
case 'list_item_start': {
|
||
var body = '';
|
||
|
||
while (this.next().type !== 'list_item_end') {
|
||
body += this$1.token.type === 'text'
|
||
? this$1.parseText()
|
||
: this$1.tok();
|
||
}
|
||
|
||
return this.renderer.listitem(body);
|
||
}
|
||
case 'loose_item_start': {
|
||
var body = '';
|
||
|
||
while (this.next().type !== 'list_item_end') {
|
||
body += this$1.tok();
|
||
}
|
||
|
||
return this.renderer.listitem(body);
|
||
}
|
||
case 'html': {
|
||
var html = !this.token.pre && !this.options.pedantic
|
||
? this.inline.output(this.token.text)
|
||
: this.token.text;
|
||
return this.renderer.html(html);
|
||
}
|
||
case 'paragraph': {
|
||
return this.renderer.paragraph(this.inline.output(this.token.text));
|
||
}
|
||
case 'text': {
|
||
return this.renderer.paragraph(this.parseText());
|
||
}
|
||
}
|
||
};
|
||
|
||
/**
|
||
* Helpers
|
||
*/
|
||
|
||
function escape(html, encode) {
|
||
return html
|
||
.replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&')
|
||
.replace(/</g, '<')
|
||
.replace(/>/g, '>')
|
||
.replace(/"/g, '"')
|
||
.replace(/'/g, ''');
|
||
}
|
||
|
||
function unescape(html) {
|
||
// explicitly match decimal, hex, and named HTML entities
|
||
return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
|
||
n = n.toLowerCase();
|
||
if (n === 'colon') { return ':'; }
|
||
if (n.charAt(0) === '#') {
|
||
return n.charAt(1) === 'x'
|
||
? String.fromCharCode(parseInt(n.substring(2), 16))
|
||
: String.fromCharCode(+n.substring(1));
|
||
}
|
||
return '';
|
||
});
|
||
}
|
||
|
||
function replace(regex, opt) {
|
||
regex = regex.source;
|
||
opt = opt || '';
|
||
return function self(name, val) {
|
||
if (!name) { return new RegExp(regex, opt); }
|
||
val = val.source || val;
|
||
val = val.replace(/(^|[^\[])\^/g, '$1');
|
||
regex = regex.replace(name, val);
|
||
return self;
|
||
};
|
||
}
|
||
|
||
function noop() {}
|
||
noop.exec = noop;
|
||
|
||
function merge(obj) {
|
||
var arguments$1 = arguments;
|
||
|
||
var i = 1
|
||
, target
|
||
, key;
|
||
|
||
for (; i < arguments.length; i++) {
|
||
target = arguments$1[i];
|
||
for (key in target) {
|
||
if (Object.prototype.hasOwnProperty.call(target, key)) {
|
||
obj[key] = target[key];
|
||
}
|
||
}
|
||
}
|
||
|
||
return obj;
|
||
}
|
||
|
||
|
||
/**
|
||
* Marked
|
||
*/
|
||
|
||
function marked(src, opt, callback) {
|
||
if (callback || typeof opt === 'function') {
|
||
if (!callback) {
|
||
callback = opt;
|
||
opt = null;
|
||
}
|
||
|
||
opt = merge({}, marked.defaults, opt || {});
|
||
|
||
var highlight = opt.highlight
|
||
, tokens
|
||
, pending
|
||
, i = 0;
|
||
|
||
try {
|
||
tokens = Lexer.lex(src, opt);
|
||
} catch (e) {
|
||
return callback(e);
|
||
}
|
||
|
||
pending = tokens.length;
|
||
|
||
var done = function(err) {
|
||
if (err) {
|
||
opt.highlight = highlight;
|
||
return callback(err);
|
||
}
|
||
|
||
var out;
|
||
|
||
try {
|
||
out = Parser.parse(tokens, opt);
|
||
} catch (e) {
|
||
err = e;
|
||
}
|
||
|
||
opt.highlight = highlight;
|
||
|
||
return err
|
||
? callback(err)
|
||
: callback(null, out);
|
||
};
|
||
|
||
if (!highlight || highlight.length < 3) {
|
||
return done();
|
||
}
|
||
|
||
delete opt.highlight;
|
||
|
||
if (!pending) { return done(); }
|
||
|
||
for (; i < tokens.length; i++) {
|
||
(function(token) {
|
||
if (token.type !== 'code') {
|
||
return --pending || done();
|
||
}
|
||
return highlight(token.text, token.lang, function(err, code) {
|
||
if (err) { return done(err); }
|
||
if (code == null || code === token.text) {
|
||
return --pending || done();
|
||
}
|
||
token.text = code;
|
||
token.escaped = true;
|
||
--pending || done();
|
||
});
|
||
})(tokens[i]);
|
||
}
|
||
|
||
return;
|
||
}
|
||
try {
|
||
if (opt) { opt = merge({}, marked.defaults, opt); }
|
||
return Parser.parse(Lexer.lex(src, opt), opt);
|
||
} catch (e) {
|
||
e.message += '\nPlease report this to https://github.com/chjj/marked.';
|
||
if ((opt || marked.defaults).silent) {
|
||
return '<p>An error occured:</p><pre>'
|
||
+ escape(e.message + '', true)
|
||
+ '</pre>';
|
||
}
|
||
throw e;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Options
|
||
*/
|
||
|
||
marked.options =
|
||
marked.setOptions = function(opt) {
|
||
merge(marked.defaults, opt);
|
||
return marked;
|
||
};
|
||
|
||
marked.defaults = {
|
||
gfm: true,
|
||
tables: true,
|
||
breaks: false,
|
||
pedantic: false,
|
||
sanitize: false,
|
||
sanitizer: null,
|
||
mangle: true,
|
||
smartLists: false,
|
||
silent: false,
|
||
highlight: null,
|
||
langPrefix: 'lang-',
|
||
smartypants: false,
|
||
headerPrefix: '',
|
||
renderer: new Renderer,
|
||
xhtml: false
|
||
};
|
||
|
||
/**
|
||
* Expose
|
||
*/
|
||
|
||
marked.Parser = Parser;
|
||
marked.parser = Parser.parse;
|
||
|
||
marked.Renderer = Renderer;
|
||
|
||
marked.Lexer = Lexer;
|
||
marked.lexer = Lexer.lex;
|
||
|
||
marked.InlineLexer = InlineLexer;
|
||
marked.inlineLexer = InlineLexer.output;
|
||
|
||
marked.parse = marked;
|
||
|
||
if ('object' !== 'undefined' && 'object' === 'object') {
|
||
module.exports = marked;
|
||
} else if (typeof undefined === 'function' && undefined.amd) {
|
||
undefined(function() { return marked; });
|
||
} else {
|
||
this.marked = marked;
|
||
}
|
||
|
||
}).call(function() {
|
||
return this || (typeof window !== 'undefined' ? window : commonjsGlobal);
|
||
}());
|
||
});
|
||
|
||
marked.setOptions({
|
||
gfm: true,
|
||
smartypants: true
|
||
});
|
||
|
||
var markdown = function(dom, data) {
|
||
var markdownElements = [].slice.call(dom.querySelectorAll('[markdown]'));
|
||
markdownElements.forEach(function (el) {
|
||
var content = el.innerHTML;
|
||
// Set default indents
|
||
content = content.replace(/\n/, "");
|
||
var tabs = content.match(/\s*/);
|
||
content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
|
||
content = content.trim();
|
||
|
||
el.innerHTML = marked(content);
|
||
});
|
||
};
|
||
|
||
var prism = createCommonjsModule(function (module) {
|
||
/* **********************************************
|
||
Begin prism-core.js
|
||
********************************************** */
|
||
|
||
var _self = (typeof window !== 'undefined')
|
||
? window // if in browser
|
||
: (
|
||
(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
|
||
? self // if in worker
|
||
: {} // if in node js
|
||
);
|
||
|
||
/**
|
||
* Prism: Lightweight, robust, elegant syntax highlighting
|
||
* MIT license http://www.opensource.org/licenses/mit-license.php/
|
||
* @author Lea Verou http://lea.verou.me
|
||
*/
|
||
|
||
var Prism = (function(){
|
||
|
||
// Private helper vars
|
||
var lang = /\blang(?:uage)?-(\w+)\b/i;
|
||
var uniqueId = 0;
|
||
|
||
var _ = _self.Prism = {
|
||
util: {
|
||
encode: function (tokens) {
|
||
if (tokens instanceof Token) {
|
||
return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
|
||
} else if (_.util.type(tokens) === 'Array') {
|
||
return tokens.map(_.util.encode);
|
||
} else {
|
||
return tokens.replace(/&/g, '&').replace(/</g, '<').replace(/\u00a0/g, ' ');
|
||
}
|
||
},
|
||
|
||
type: function (o) {
|
||
return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
|
||
},
|
||
|
||
objId: function (obj) {
|
||
if (!obj['__id']) {
|
||
Object.defineProperty(obj, '__id', { value: ++uniqueId });
|
||
}
|
||
return obj['__id'];
|
||
},
|
||
|
||
// Deep clone a language definition (e.g. to extend it)
|
||
clone: function (o) {
|
||
var type = _.util.type(o);
|
||
|
||
switch (type) {
|
||
case 'Object':
|
||
var clone = {};
|
||
|
||
for (var key in o) {
|
||
if (o.hasOwnProperty(key)) {
|
||
clone[key] = _.util.clone(o[key]);
|
||
}
|
||
}
|
||
|
||
return clone;
|
||
|
||
case 'Array':
|
||
// Check for existence for IE8
|
||
return o.map && o.map(function(v) { return _.util.clone(v); });
|
||
}
|
||
|
||
return o;
|
||
}
|
||
},
|
||
|
||
languages: {
|
||
extend: function (id, redef) {
|
||
var lang = _.util.clone(_.languages[id]);
|
||
|
||
for (var key in redef) {
|
||
lang[key] = redef[key];
|
||
}
|
||
|
||
return lang;
|
||
},
|
||
|
||
/**
|
||
* Insert a token before another token in a language literal
|
||
* As this needs to recreate the object (we cannot actually insert before keys in object literals),
|
||
* we cannot just provide an object, we need anobject and a key.
|
||
* @param inside The key (or language id) of the parent
|
||
* @param before The key to insert before. If not provided, the function appends instead.
|
||
* @param insert Object with the key/value pairs to insert
|
||
* @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
|
||
*/
|
||
insertBefore: function (inside, before, insert, root) {
|
||
root = root || _.languages;
|
||
var grammar = root[inside];
|
||
|
||
if (arguments.length == 2) {
|
||
insert = arguments[1];
|
||
|
||
for (var newToken in insert) {
|
||
if (insert.hasOwnProperty(newToken)) {
|
||
grammar[newToken] = insert[newToken];
|
||
}
|
||
}
|
||
|
||
return grammar;
|
||
}
|
||
|
||
var ret = {};
|
||
|
||
for (var token in grammar) {
|
||
|
||
if (grammar.hasOwnProperty(token)) {
|
||
|
||
if (token == before) {
|
||
|
||
for (var newToken in insert) {
|
||
|
||
if (insert.hasOwnProperty(newToken)) {
|
||
ret[newToken] = insert[newToken];
|
||
}
|
||
}
|
||
}
|
||
|
||
ret[token] = grammar[token];
|
||
}
|
||
}
|
||
|
||
// Update references in other language definitions
|
||
_.languages.DFS(_.languages, function(key, value) {
|
||
if (value === root[inside] && key != inside) {
|
||
this[key] = ret;
|
||
}
|
||
});
|
||
|
||
return root[inside] = ret;
|
||
},
|
||
|
||
// Traverse a language definition with Depth First Search
|
||
DFS: function(o, callback, type, visited) {
|
||
visited = visited || {};
|
||
for (var i in o) {
|
||
if (o.hasOwnProperty(i)) {
|
||
callback.call(o, i, o[i], type || i);
|
||
|
||
if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
|
||
visited[_.util.objId(o[i])] = true;
|
||
_.languages.DFS(o[i], callback, null, visited);
|
||
}
|
||
else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
|
||
visited[_.util.objId(o[i])] = true;
|
||
_.languages.DFS(o[i], callback, i, visited);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
},
|
||
plugins: {},
|
||
|
||
highlightAll: function(async, callback) {
|
||
var env = {
|
||
callback: callback,
|
||
selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
|
||
};
|
||
|
||
_.hooks.run("before-highlightall", env);
|
||
|
||
var elements = env.elements || document.querySelectorAll(env.selector);
|
||
|
||
for (var i=0, element; element = elements[i++];) {
|
||
_.highlightElement(element, async === true, env.callback);
|
||
}
|
||
},
|
||
|
||
highlightElement: function(element, async, callback) {
|
||
// Find language
|
||
var language, grammar, parent = element;
|
||
|
||
while (parent && !lang.test(parent.className)) {
|
||
parent = parent.parentNode;
|
||
}
|
||
|
||
if (parent) {
|
||
language = (parent.className.match(lang) || [,''])[1].toLowerCase();
|
||
grammar = _.languages[language];
|
||
}
|
||
|
||
// Set language on the element, if not present
|
||
element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
|
||
|
||
// Set language on the parent, for styling
|
||
parent = element.parentNode;
|
||
|
||
if (/pre/i.test(parent.nodeName)) {
|
||
parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
|
||
}
|
||
|
||
var code = element.textContent;
|
||
|
||
var env = {
|
||
element: element,
|
||
language: language,
|
||
grammar: grammar,
|
||
code: code
|
||
};
|
||
|
||
_.hooks.run('before-sanity-check', env);
|
||
|
||
if (!env.code || !env.grammar) {
|
||
if (env.code) {
|
||
env.element.textContent = env.code;
|
||
}
|
||
_.hooks.run('complete', env);
|
||
return;
|
||
}
|
||
|
||
_.hooks.run('before-highlight', env);
|
||
|
||
if (async && _self.Worker) {
|
||
var worker = new Worker(_.filename);
|
||
|
||
worker.onmessage = function(evt) {
|
||
env.highlightedCode = evt.data;
|
||
|
||
_.hooks.run('before-insert', env);
|
||
|
||
env.element.innerHTML = env.highlightedCode;
|
||
|
||
callback && callback.call(env.element);
|
||
_.hooks.run('after-highlight', env);
|
||
_.hooks.run('complete', env);
|
||
};
|
||
|
||
worker.postMessage(JSON.stringify({
|
||
language: env.language,
|
||
code: env.code,
|
||
immediateClose: true
|
||
}));
|
||
}
|
||
else {
|
||
env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
|
||
|
||
_.hooks.run('before-insert', env);
|
||
|
||
env.element.innerHTML = env.highlightedCode;
|
||
|
||
callback && callback.call(element);
|
||
|
||
_.hooks.run('after-highlight', env);
|
||
_.hooks.run('complete', env);
|
||
}
|
||
},
|
||
|
||
highlight: function (text, grammar, language) {
|
||
var tokens = _.tokenize(text, grammar);
|
||
return Token.stringify(_.util.encode(tokens), language);
|
||
},
|
||
|
||
tokenize: function(text, grammar, language) {
|
||
var Token = _.Token;
|
||
|
||
var strarr = [text];
|
||
|
||
var rest = grammar.rest;
|
||
|
||
if (rest) {
|
||
for (var token in rest) {
|
||
grammar[token] = rest[token];
|
||
}
|
||
|
||
delete grammar.rest;
|
||
}
|
||
|
||
tokenloop: for (var token in grammar) {
|
||
if(!grammar.hasOwnProperty(token) || !grammar[token]) {
|
||
continue;
|
||
}
|
||
|
||
var patterns = grammar[token];
|
||
patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
|
||
|
||
for (var j = 0; j < patterns.length; ++j) {
|
||
var pattern = patterns[j],
|
||
inside = pattern.inside,
|
||
lookbehind = !!pattern.lookbehind,
|
||
greedy = !!pattern.greedy,
|
||
lookbehindLength = 0,
|
||
alias = pattern.alias;
|
||
|
||
if (greedy && !pattern.pattern.global) {
|
||
// Without the global flag, lastIndex won't work
|
||
var flags = pattern.pattern.toString().match(/[imuy]*$/)[0];
|
||
pattern.pattern = RegExp(pattern.pattern.source, flags + "g");
|
||
}
|
||
|
||
pattern = pattern.pattern || pattern;
|
||
|
||
// Don’t cache length as it changes during the loop
|
||
for (var i=0, pos = 0; i<strarr.length; pos += strarr[i].length, ++i) {
|
||
|
||
var str = strarr[i];
|
||
|
||
if (strarr.length > text.length) {
|
||
// Something went terribly wrong, ABORT, ABORT!
|
||
break tokenloop;
|
||
}
|
||
|
||
if (str instanceof Token) {
|
||
continue;
|
||
}
|
||
|
||
pattern.lastIndex = 0;
|
||
|
||
var match = pattern.exec(str),
|
||
delNum = 1;
|
||
|
||
// Greedy patterns can override/remove up to two previously matched tokens
|
||
if (!match && greedy && i != strarr.length - 1) {
|
||
pattern.lastIndex = pos;
|
||
match = pattern.exec(text);
|
||
if (!match) {
|
||
break;
|
||
}
|
||
|
||
var from = match.index + (lookbehind ? match[1].length : 0),
|
||
to = match.index + match[0].length,
|
||
k = i,
|
||
p = pos;
|
||
|
||
for (var len = strarr.length; k < len && p < to; ++k) {
|
||
p += strarr[k].length;
|
||
// Move the index i to the element in strarr that is closest to from
|
||
if (from >= p) {
|
||
++i;
|
||
pos = p;
|
||
}
|
||
}
|
||
|
||
/*
|
||
* If strarr[i] is a Token, then the match starts inside another Token, which is invalid
|
||
* If strarr[k - 1] is greedy we are in conflict with another greedy pattern
|
||
*/
|
||
if (strarr[i] instanceof Token || strarr[k - 1].greedy) {
|
||
continue;
|
||
}
|
||
|
||
// Number of tokens to delete and replace with the new match
|
||
delNum = k - i;
|
||
str = text.slice(pos, p);
|
||
match.index -= pos;
|
||
}
|
||
|
||
if (!match) {
|
||
continue;
|
||
}
|
||
|
||
if(lookbehind) {
|
||
lookbehindLength = match[1].length;
|
||
}
|
||
|
||
var from = match.index + lookbehindLength,
|
||
match = match[0].slice(lookbehindLength),
|
||
to = from + match.length,
|
||
before = str.slice(0, from),
|
||
after = str.slice(to);
|
||
|
||
var args = [i, delNum];
|
||
|
||
if (before) {
|
||
args.push(before);
|
||
}
|
||
|
||
var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
|
||
|
||
args.push(wrapped);
|
||
|
||
if (after) {
|
||
args.push(after);
|
||
}
|
||
|
||
Array.prototype.splice.apply(strarr, args);
|
||
}
|
||
}
|
||
}
|
||
|
||
return strarr;
|
||
},
|
||
|
||
hooks: {
|
||
all: {},
|
||
|
||
add: function (name, callback) {
|
||
var hooks = _.hooks.all;
|
||
|
||
hooks[name] = hooks[name] || [];
|
||
|
||
hooks[name].push(callback);
|
||
},
|
||
|
||
run: function (name, env) {
|
||
var callbacks = _.hooks.all[name];
|
||
|
||
if (!callbacks || !callbacks.length) {
|
||
return;
|
||
}
|
||
|
||
for (var i=0, callback; callback = callbacks[i++];) {
|
||
callback(env);
|
||
}
|
||
}
|
||
}
|
||
};
|
||
|
||
var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
|
||
this.type = type;
|
||
this.content = content;
|
||
this.alias = alias;
|
||
// Copy of the full string this token was created from
|
||
this.length = (matchedStr || "").length|0;
|
||
this.greedy = !!greedy;
|
||
};
|
||
|
||
Token.stringify = function(o, language, parent) {
|
||
if (typeof o == 'string') {
|
||
return o;
|
||
}
|
||
|
||
if (_.util.type(o) === 'Array') {
|
||
return o.map(function(element) {
|
||
return Token.stringify(element, language, o);
|
||
}).join('');
|
||
}
|
||
|
||
var env = {
|
||
type: o.type,
|
||
content: Token.stringify(o.content, language, parent),
|
||
tag: 'span',
|
||
classes: ['token', o.type],
|
||
attributes: {},
|
||
language: language,
|
||
parent: parent
|
||
};
|
||
|
||
if (env.type == 'comment') {
|
||
env.attributes['spellcheck'] = 'true';
|
||
}
|
||
|
||
if (o.alias) {
|
||
var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
|
||
Array.prototype.push.apply(env.classes, aliases);
|
||
}
|
||
|
||
_.hooks.run('wrap', env);
|
||
|
||
var attributes = Object.keys(env.attributes).map(function(name) {
|
||
return name + '="' + (env.attributes[name] || '').replace(/"/g, '"') + '"';
|
||
}).join(' ');
|
||
|
||
return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
|
||
|
||
};
|
||
|
||
if (!_self.document) {
|
||
if (!_self.addEventListener) {
|
||
// in Node.js
|
||
return _self.Prism;
|
||
}
|
||
// In worker
|
||
_self.addEventListener('message', function(evt) {
|
||
var message = JSON.parse(evt.data),
|
||
lang = message.language,
|
||
code = message.code,
|
||
immediateClose = message.immediateClose;
|
||
|
||
_self.postMessage(_.highlight(code, _.languages[lang], lang));
|
||
if (immediateClose) {
|
||
_self.close();
|
||
}
|
||
}, false);
|
||
|
||
return _self.Prism;
|
||
}
|
||
|
||
//Get current script and highlight
|
||
var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
|
||
|
||
if (script) {
|
||
_.filename = script.src;
|
||
|
||
if (document.addEventListener && !script.hasAttribute('data-manual')) {
|
||
if(document.readyState !== "loading") {
|
||
if (window.requestAnimationFrame) {
|
||
window.requestAnimationFrame(_.highlightAll);
|
||
} else {
|
||
window.setTimeout(_.highlightAll, 16);
|
||
}
|
||
}
|
||
else {
|
||
document.addEventListener('DOMContentLoaded', _.highlightAll);
|
||
}
|
||
}
|
||
}
|
||
|
||
return _self.Prism;
|
||
|
||
})();
|
||
|
||
if ('object' !== 'undefined' && module.exports) {
|
||
module.exports = Prism;
|
||
}
|
||
|
||
// hack for components to work correctly in node.js
|
||
if (typeof commonjsGlobal !== 'undefined') {
|
||
commonjsGlobal.Prism = Prism;
|
||
}
|
||
|
||
|
||
/* **********************************************
|
||
Begin prism-markup.js
|
||
********************************************** */
|
||
|
||
Prism.languages.markup = {
|
||
'comment': /<!--[\w\W]*?-->/,
|
||
'prolog': /<\?[\w\W]+?\?>/,
|
||
'doctype': /<!DOCTYPE[\w\W]+?>/i,
|
||
'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
|
||
'tag': {
|
||
pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
|
||
inside: {
|
||
'tag': {
|
||
pattern: /^<\/?[^\s>\/]+/i,
|
||
inside: {
|
||
'punctuation': /^<\/?/,
|
||
'namespace': /^[^\s>\/:]+:/
|
||
}
|
||
},
|
||
'attr-value': {
|
||
pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
|
||
inside: {
|
||
'punctuation': /[=>"']/
|
||
}
|
||
},
|
||
'punctuation': /\/?>/,
|
||
'attr-name': {
|
||
pattern: /[^\s>\/]+/,
|
||
inside: {
|
||
'namespace': /^[^\s>\/:]+:/
|
||
}
|
||
}
|
||
|
||
}
|
||
},
|
||
'entity': /&#?[\da-z]{1,8};/i
|
||
};
|
||
|
||
// Plugin to make entity title show the real entity, idea by Roman Komarov
|
||
Prism.hooks.add('wrap', function(env) {
|
||
|
||
if (env.type === 'entity') {
|
||
env.attributes['title'] = env.content.replace(/&/, '&');
|
||
}
|
||
});
|
||
|
||
Prism.languages.xml = Prism.languages.markup;
|
||
Prism.languages.html = Prism.languages.markup;
|
||
Prism.languages.mathml = Prism.languages.markup;
|
||
Prism.languages.svg = Prism.languages.markup;
|
||
|
||
|
||
/* **********************************************
|
||
Begin prism-css.js
|
||
********************************************** */
|
||
|
||
Prism.languages.css = {
|
||
'comment': /\/\*[\w\W]*?\*\//,
|
||
'atrule': {
|
||
pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
|
||
inside: {
|
||
'rule': /@[\w-]+/
|
||
// See rest below
|
||
}
|
||
},
|
||
'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
|
||
'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
|
||
'string': {
|
||
pattern: /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
|
||
greedy: true
|
||
},
|
||
'property': /(\b|\B)[\w-]+(?=\s*:)/i,
|
||
'important': /\B!important\b/i,
|
||
'function': /[-a-z0-9]+(?=\()/i,
|
||
'punctuation': /[(){};:]/
|
||
};
|
||
|
||
Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
|
||
|
||
if (Prism.languages.markup) {
|
||
Prism.languages.insertBefore('markup', 'tag', {
|
||
'style': {
|
||
pattern: /(<style[\w\W]*?>)[\w\W]*?(?=<\/style>)/i,
|
||
lookbehind: true,
|
||
inside: Prism.languages.css,
|
||
alias: 'language-css'
|
||
}
|
||
});
|
||
|
||
Prism.languages.insertBefore('inside', 'attr-value', {
|
||
'style-attr': {
|
||
pattern: /\s*style=("|').*?\1/i,
|
||
inside: {
|
||
'attr-name': {
|
||
pattern: /^\s*style/i,
|
||
inside: Prism.languages.markup.tag.inside
|
||
},
|
||
'punctuation': /^\s*=\s*['"]|['"]\s*$/,
|
||
'attr-value': {
|
||
pattern: /.+/i,
|
||
inside: Prism.languages.css
|
||
}
|
||
},
|
||
alias: 'language-css'
|
||
}
|
||
}, Prism.languages.markup.tag);
|
||
}
|
||
|
||
/* **********************************************
|
||
Begin prism-clike.js
|
||
********************************************** */
|
||
|
||
Prism.languages.clike = {
|
||
'comment': [
|
||
{
|
||
pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
|
||
lookbehind: true
|
||
},
|
||
{
|
||
pattern: /(^|[^\\:])\/\/.*/,
|
||
lookbehind: true
|
||
}
|
||
],
|
||
'string': {
|
||
pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
|
||
greedy: true
|
||
},
|
||
'class-name': {
|
||
pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
|
||
lookbehind: true,
|
||
inside: {
|
||
punctuation: /(\.|\\)/
|
||
}
|
||
},
|
||
'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
|
||
'boolean': /\b(true|false)\b/,
|
||
'function': /[a-z0-9_]+(?=\()/i,
|
||
'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
|
||
'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
|
||
'punctuation': /[{}[\];(),.:]/
|
||
};
|
||
|
||
|
||
/* **********************************************
|
||
Begin prism-javascript.js
|
||
********************************************** */
|
||
|
||
Prism.languages.javascript = Prism.languages.extend('clike', {
|
||
'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/,
|
||
'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
|
||
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
|
||
'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i,
|
||
'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*\*?|\/|~|\^|%|\.{3}/
|
||
});
|
||
|
||
Prism.languages.insertBefore('javascript', 'keyword', {
|
||
'regex': {
|
||
pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
|
||
lookbehind: true,
|
||
greedy: true
|
||
}
|
||
});
|
||
|
||
Prism.languages.insertBefore('javascript', 'string', {
|
||
'template-string': {
|
||
pattern: /`(?:\\\\|\\?[^\\])*?`/,
|
||
greedy: true,
|
||
inside: {
|
||
'interpolation': {
|
||
pattern: /\$\{[^}]+\}/,
|
||
inside: {
|
||
'interpolation-punctuation': {
|
||
pattern: /^\$\{|\}$/,
|
||
alias: 'punctuation'
|
||
},
|
||
rest: Prism.languages.javascript
|
||
}
|
||
},
|
||
'string': /[\s\S]+/
|
||
}
|
||
}
|
||
});
|
||
|
||
if (Prism.languages.markup) {
|
||
Prism.languages.insertBefore('markup', 'tag', {
|
||
'script': {
|
||
pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
|
||
lookbehind: true,
|
||
inside: Prism.languages.javascript,
|
||
alias: 'language-javascript'
|
||
}
|
||
});
|
||
}
|
||
|
||
Prism.languages.js = Prism.languages.javascript;
|
||
|
||
/* **********************************************
|
||
Begin prism-file-highlight.js
|
||
********************************************** */
|
||
|
||
(function () {
|
||
if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) {
|
||
return;
|
||
}
|
||
|
||
self.Prism.fileHighlight = function() {
|
||
|
||
var Extensions = {
|
||
'js': 'javascript',
|
||
'py': 'python',
|
||
'rb': 'ruby',
|
||
'ps1': 'powershell',
|
||
'psm1': 'powershell',
|
||
'sh': 'bash',
|
||
'bat': 'batch',
|
||
'h': 'c',
|
||
'tex': 'latex'
|
||
};
|
||
|
||
if(Array.prototype.forEach) { // Check to prevent error in IE8
|
||
Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function (pre) {
|
||
var src = pre.getAttribute('data-src');
|
||
|
||
var language, parent = pre;
|
||
var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
|
||
while (parent && !lang.test(parent.className)) {
|
||
parent = parent.parentNode;
|
||
}
|
||
|
||
if (parent) {
|
||
language = (pre.className.match(lang) || [, ''])[1];
|
||
}
|
||
|
||
if (!language) {
|
||
var extension = (src.match(/\.(\w+)$/) || [, ''])[1];
|
||
language = Extensions[extension] || extension;
|
||
}
|
||
|
||
var code = document.createElement('code');
|
||
code.className = 'language-' + language;
|
||
|
||
pre.textContent = '';
|
||
|
||
code.textContent = 'Loading…';
|
||
|
||
pre.appendChild(code);
|
||
|
||
var xhr = new XMLHttpRequest();
|
||
|
||
xhr.open('GET', src, true);
|
||
|
||
xhr.onreadystatechange = function () {
|
||
if (xhr.readyState == 4) {
|
||
|
||
if (xhr.status < 400 && xhr.responseText) {
|
||
code.textContent = xhr.responseText;
|
||
|
||
Prism.highlightElement(code);
|
||
}
|
||
else if (xhr.status >= 400) {
|
||
code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
|
||
}
|
||
else {
|
||
code.textContent = '✖ Error: File does not exist or is empty';
|
||
}
|
||
}
|
||
};
|
||
|
||
xhr.send(null);
|
||
});
|
||
}
|
||
|
||
};
|
||
|
||
document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight);
|
||
|
||
})();
|
||
});
|
||
|
||
var code$1 = function(dom, data) {
|
||
var codeElements = [].slice.call(dom.querySelectorAll("dt-code"));
|
||
codeElements.forEach(function (el) {
|
||
var content = el.textContent;
|
||
el.innerHTML = "";
|
||
var language = el.getAttribute("language");
|
||
var c = dom.createElement("code");
|
||
if (el.getAttribute("block") === "") {
|
||
// Let's normalize the tab indents
|
||
content = content.replace(/\n/, "");
|
||
var tabs = content.match(/\s*/);
|
||
content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
|
||
content = content.trim();
|
||
var p = dom.createElement("pre");
|
||
p.appendChild(c);
|
||
el.appendChild(p);
|
||
} else {
|
||
el.appendChild(c);
|
||
}
|
||
var highlighted = content;
|
||
if (prism.languages[language]) {
|
||
c.setAttribute("class", "language-" + language);
|
||
highlighted = prism.highlight(content, prism.languages[language]);
|
||
}
|
||
c.innerHTML = highlighted;
|
||
});
|
||
};
|
||
|
||
var code$2 = "// DistillHoverBox\n//=====================================\n\nfunction DistillHoverBox(key, pos){\n\n if (!(key in DistillHoverBox.contentMap)){\n console.error(\"No DistillHoverBox content registered for key\", key);\n }\n if (key in DistillHoverBox.liveBoxes) {\n console.error(\"There already exists a DistillHoverBox for key\", key);\n } else {\n for (var k in DistillHoverBox.liveBoxes)\n DistillHoverBox.liveBoxes[k].remove();\n DistillHoverBox.liveBoxes[key] = this;\n }\n this.key = key;\n\n var pretty = window.innerWidth > 600;\n\n var padding = pretty? 18 : 12;\n var outer_padding = pretty ? 18 : 0;\n var bbox = document.querySelector(\"body\").getBoundingClientRect();\n var left = pos[0] - bbox.left, top = pos[1] - bbox.top;\n var width = Math.min(window.innerWidth-2*outer_padding, 648);\n left = Math.min(left, window.innerWidth-width-outer_padding);\n width = width - 2*padding;\n\n var str = `<div style=\"position: absolute;\n background-color: #FFF;\n opacity: 0.95;\n width: ${width}px;\n top: ${top}px;\n left: ${left}px;\n padding: ${padding}px;\n border-radius: ${pretty? 3 : 0}px;\n box-shadow: 0px 0px 18px 3px #777;\n z-index: ${1e6}\" >\n ${DistillHoverBox.contentMap[key]}\n </div>`;\n\n this.div = appendBody(str);\n\n DistillHoverBox.bind (this.div, key);\n}\n\nDistillHoverBox.prototype.remove = function remove(){\n if (this.div) this.div.remove();\n if (this.timeout) clearTimeout(this.timeout);\n delete DistillHoverBox.liveBoxes[this.key];\n}\n\nDistillHoverBox.prototype.stopTimeout = function stopTimeout() {\n if (this.timeout) clearTimeout(this.timeout);\n}\n\nDistillHoverBox.prototype.extendTimeout = function extendTimeout(T) {\n //console.log(\"extend\", T)\n var this_ = this;\n this.stopTimeout();\n this.timeout = setTimeout(() => this_.remove(), T);\n}\n\nDistillHoverBox.liveBoxes = {};\nDistillHoverBox.contentMap = {};\n\nDistillHoverBox.bind = function bind(node, key) {\n if (typeof node == \"string\"){\n node = document.querySelector(node);\n }\n node.addEventListener(\"mouseover\", () => {\n var bbox = node.getBoundingClientRect();\n if (!(key in DistillHoverBox.liveBoxes)){\n new DistillHoverBox(key, [bbox.right, bbox.bottom]);\n }\n DistillHoverBox.liveBoxes[key].stopTimeout();\n });\n node.addEventListener(\"mouseout\", () => {\n if (key in DistillHoverBox.liveBoxes){\n DistillHoverBox.liveBoxes[key].extendTimeout(250);\n }\n });\n\n}\n\n\nfunction appendBody(str){\n var node = nodeFromString(str);\n var body = document.querySelector(\"body\");\n body.appendChild(node);\n return node;\n}\n\nfunction nodeFromString(str) {\n var div = document.createElement(\"div\");\n div.innerHTML = str;\n return div.firstChild;\n}\n\nvar hover_es = document.querySelectorAll(\"span[data-hover]\");\nhover_es = [].slice.apply(hover_es);\nhover_es.forEach((e,n) => {\n var key = \"hover-\"+n;\n var content = e.getAttribute(\"data-hover\");\n DistillHoverBox.contentMap[key] = content;\n DistillHoverBox.bind(e, key);\n});\n";
|
||
|
||
var hoverBox = function(dom) {
|
||
var s = dom.createElement("script");
|
||
s.textContent = code$2;
|
||
dom.querySelector("body").appendChild(s);
|
||
};
|
||
|
||
//import xml from "xml";
|
||
|
||
var generateCrossref = function(data) {
|
||
|
||
if (data.published == undefined) {
|
||
//console.warn("Can't generate XML for post ", data.title, "with data", data);
|
||
//return "";
|
||
data.published = new Date("invalid");
|
||
}
|
||
|
||
var date = data.published;
|
||
var batch_timestamp = Math.floor(Date.now() / 1000);
|
||
var batch_id = data.authors.length ? data.authors[0].lastName.toLowerCase().slice(0,20) : "Anonymous";
|
||
batch_id += "_" + date.getFullYear();
|
||
batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp;
|
||
// generate XML
|
||
var crf_data =
|
||
{doi_batch : [
|
||
|
||
{ _attr: {
|
||
version: "4.3.7",
|
||
xmlns: "http://www.crossref.org/schema/4.3.7",
|
||
"xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
|
||
"xsi:schemaLocation": "http://www.crossref.org/schema/4.3.7 http://www.crossref.org/schemas/crossref4.3.7.xsd",
|
||
}},
|
||
|
||
{ head: [
|
||
{doi_batch_id: batch_id},
|
||
{timestamp: batch_timestamp},
|
||
{depositor: [
|
||
{depositor_name: data.journal.depositorName},
|
||
{email_address: data.journal.email} ]},
|
||
{registrant: "Distill"} ]},
|
||
|
||
{body: [
|
||
{journal: [
|
||
|
||
{journal_metadata: [
|
||
{full_title: data.journal.full_title || data.journal.title},
|
||
{abbrev_title: data.journal.abbrev_title || data.journal.title || data.journal.full_title},
|
||
{doi_data: [
|
||
{doi: data.journal.doi},
|
||
{resource: data.journal.url} ]} ]},
|
||
|
||
{journal_issue: [
|
||
{publication_date: [
|
||
{month: date.getMonth()+1},
|
||
{year: date.getFullYear()} ]},
|
||
{journal_volume: [
|
||
{volume: data.volume} ]},
|
||
{issue: data.issue} ]},
|
||
|
||
{journal_article: [
|
||
{titles: [
|
||
{title: data.title} ]},
|
||
{ contributors:
|
||
data.authors.map(function (author, ind) { return (
|
||
{person_name: [
|
||
{ _attr: {
|
||
contributor_role: "author",
|
||
sequence: (ind == 0)? "first" : "additional"
|
||
}},
|
||
{given_name: author.firstName},
|
||
{surname: author.lastName},
|
||
{affiliation: author.affiliation}
|
||
// TODO: ORCID?
|
||
]}
|
||
); })
|
||
},
|
||
{publication_date: [
|
||
{month: date.getMonth()+1},
|
||
{day: date.getDate()},
|
||
{year: date.getFullYear()}
|
||
]},
|
||
{ publisher_item: [
|
||
{item_number: data.doi}
|
||
]},
|
||
{doi_data: [
|
||
{doi: data.doi},
|
||
//{timestamp: ""},
|
||
{resource: data.url} ]},
|
||
{citation_list:
|
||
data.citations.map(function (key) { return citation_xml(key, data.bibliography[key]); })
|
||
}
|
||
|
||
]} ]} ]} ]};
|
||
|
||
return xml(crf_data);
|
||
};
|
||
|
||
function citation_xml(key, ent){
|
||
if (ent == undefined) { return {}; }
|
||
var info = [];
|
||
info.push({_attr: {key: key}});
|
||
if ("title" in ent)
|
||
{ info.push({article_title: ent.title}); }
|
||
if ("author" in ent)
|
||
{ info.push({author: ent.author.split(" and ")[0].split(",")[0].trim()}); }
|
||
if ("journal" in ent)
|
||
{ info.push({journal_title: ent.journal}); }
|
||
if ("booktitle" in ent)
|
||
{ info.push({volume_title: ent.booktitle}); }
|
||
if ("volume" in ent)
|
||
{ info.push({volume: ent.volume}); }
|
||
if ("issue" in ent)
|
||
{ info.push({issue: ent.issue}); }
|
||
if ("doi" in ent)
|
||
{ info.push({doi: ent.doi}); }
|
||
return {citation: info}
|
||
}
|
||
|
||
function xml(obj) {
|
||
//console.log(typeof(obj), obj)
|
||
if (typeof obj === 'string') { return obj; }
|
||
if (typeof obj === 'number') { return ""+obj; }
|
||
var keys = Object.keys(obj);
|
||
if (keys.length != 1) { console.error("can't interpret ", obj, "as xml"); }
|
||
var name = keys[0];
|
||
var full_content = obj[name];
|
||
var attr = {};
|
||
if (Array.isArray(full_content)){
|
||
var content = [];
|
||
for (var i in full_content) {
|
||
var obj = full_content[i];
|
||
var obj_name = Object.keys(obj)[0];
|
||
if ("_attr" == obj_name) {
|
||
attr = obj["_attr"];
|
||
} else {
|
||
//console.log(Object.keys(obj)[0])
|
||
content.push(obj);
|
||
}
|
||
}
|
||
} else {
|
||
content = full_content;
|
||
}
|
||
if (content == undefined){
|
||
content = "undefined";
|
||
}
|
||
|
||
var attr_string = "";
|
||
for (var k in attr) {
|
||
attr_string += " " + k + "=\"" + (attr[k]) + "\"";
|
||
}
|
||
|
||
//console.log(typeof content, Array.isArray(content), content instanceof String, content)
|
||
if (Array.isArray(content)){
|
||
content = content.map(xml);
|
||
content = content.join("\n").split("\n");
|
||
content = content.map(function (s) { return " " + s; }).join("\n");
|
||
var result = "<" + name + attr_string + ">\n" + content + "\n</" + name + ">";
|
||
} else {
|
||
content = xml(content);
|
||
var result = "<" + name + attr_string + ">" + content + "</" + name + ">";
|
||
}
|
||
return result;
|
||
}
|
||
|
||
function renderImmediately(dom) {
|
||
html(dom);
|
||
styles(dom);
|
||
}
|
||
|
||
function renderOnLoad(dom, data) {
|
||
frontMatter(dom, data);
|
||
bibliography(dom, data);
|
||
expandData(dom, data);
|
||
meta(dom, data);
|
||
header(dom, data);
|
||
byline(dom, data);
|
||
appendix(dom, data);
|
||
footer(dom, data);
|
||
markdown(dom, data);
|
||
code$1(dom, data);
|
||
citation(dom, data);
|
||
footnote(dom, data);
|
||
hoverBox(dom, data);
|
||
}
|
||
|
||
// If we are in a browser, render automatically.
|
||
if(window && window.document) {
|
||
var data = {};
|
||
renderImmediately(window.document);
|
||
window.document.addEventListener("DOMContentLoaded", function (event) {
|
||
renderOnLoad(window.document, data);
|
||
generateCrossref(data);
|
||
});
|
||
}
|
||
|
||
// For node
|
||
function render$1(dom, data) {
|
||
renderImmediately(dom);
|
||
renderOnLoad(dom, data);
|
||
// Remove script tag so it doesn't run again
|
||
var s = dom.querySelector('script[src="http://distill.pub/template.js"]');
|
||
if (s) { s.parentElement.removeChild(s); }
|
||
}
|
||
|
||
exports.render = render$1;
|
||
exports.html = html;
|
||
exports.styles = styles;
|
||
exports.frontMatter = frontMatter;
|
||
exports.bibliography = bibliography;
|
||
exports.meta = meta;
|
||
exports.header = header;
|
||
exports.appendix = appendix;
|
||
exports.footer = footer;
|
||
exports.citation = citation;
|
||
exports.markdown = markdown;
|
||
exports.code = code$1;
|
||
exports.generateCrossref = generateCrossref;
|
||
|
||
Object.defineProperty(exports, '__esModule', { value: true });
|
||
|
||
})));
|
||
//# sourceMappingURL=template.js.map
|