UNPKG

264 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3 typeof define === 'function' && define.amd ? define(['exports'], factory) :
4 (factory((global.dl = global.dl || {})));
5}(this, (function (exports) { 'use strict';
6
7var html = function(dom) {
8 if (!dom.querySelector("html").getAttribute("lang")) {
9 dom.querySelector("html").setAttribute("lang", "en");
10 }
11
12 var head = dom.querySelector("head");
13
14 if (!dom.querySelector("meta[charset]")) {
15 var meta = dom.createElement("meta");
16 meta.setAttribute("charset", "utf-8");
17 head.appendChild(meta);
18 }
19 if (!dom.querySelector("meta[name=viewport]")) {
20 var meta$1 = dom.createElement("meta");
21 meta$1.setAttribute("name", "viewport");
22 meta$1.setAttribute("content", "width=device-width, initial-scale=1");
23 head.appendChild(meta$1);
24 }
25};
26
27var base = "html {\n font: 400 16px/1.55em -apple-system, BlinkMacSystemFont, \"Roboto\", Helvetica, sans-serif;\n /*background-color: hsl(223, 9%, 25%);*/\n -ms-text-size-adjust: 100%;\n -webkit-text-size-adjust: 100%;\n text-size-adjust: 100%;\n}\nbody {\n margin: 0;\n /*background-color: hsl(223, 9%, 25%);*/\n}\n\na {\n color: #004276;\n}\n\nfigure {\n margin: 0;\n}\n\nh1 {\n font-family: Cochin, Georgia, serif;\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";
28
29var layout = "/*\n Column: 60px\n Gutter: 24px\n\n Body: 648px\n - 8 columns\n - 7 gutters\n Middle: 816px\n Page: 984px\n - 12 columns\n - 11 gutters\n*/\n\n.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,\ndt-article > dt-code,\ndt-article section > div,\ndt-article section > p,\ndt-article section > h1,\ndt-article section > h2,\ndt-article section > h3,\ndt-article section > h4,\ndt-article section > figure,\ndt-article section > ul,\ndt-article section > dt-byline,\ndt-article section > dt-code {\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 dt-article > dt-code,\n dt-article section > div,\n dt-article section > p,\n dt-article section > h1,\n dt-article section > h2,\n dt-article section > h3,\n dt-article section > h4,\n dt-article section > figure,\n dt-article section > ul,\n dt-article section > dt-byline,\n dt-article section > dt-code {\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 > h2,\n dt-article > h3,\n dt-article > h4,\n dt-article > figure,\n dt-article > ul,\n dt-article > dt-byline,\n dt-article > dt-code,\n dt-article section > div,\n dt-article section > p,\n dt-article section > h2,\n dt-article section > h3,\n dt-article section > h4,\n dt-article section > figure,\n dt-article section > ul,\n dt-article section > dt-byline,\n dt-article section > dt-code {\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-middle-outset,\n dt-article .l-middle-outset {\n width: calc(816px + 96px);\n margin-left: calc(50% - 984px / 2 - 48px);\n margin-right: auto;\n }\n dt-article > h1,\n dt-article section > h1,\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 + 168px);\n width: calc((984px - 648px) / 2 - 24px);\n }\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 - 84px);\n }\n .side.l-body-outset,\n dt-article .side.l-body-outset {\n clear: both;\n float: right;\n margin-top: 0;\n margin-left: 48px;\n margin-right: calc((100vw - 984px + 648px - 48px) / 2);\n width: calc(648px / 2 - 48px + 24px);\n }\n .side.l-middle,\n dt-article .side.l-middle {\n clear: both;\n float: right;\n width: calc(456px - 84px);\n margin-left: 48px;\n margin-right: calc((100vw - 984px) / 2 + 168px);\n }\n .side.l-middle-outset,\n dt-article .side.l-middle-outset {\n clear: both;\n float: right;\n width: 456px;\n margin-left: 48px;\n margin-right: calc((100vw - 984px) / 2 + 168px);\n }\n .side.l-page,\n dt-article .side.l-page {\n clear: both;\n float: right;\n margin-left: 48px;\n width: calc(624px - 84px);\n margin-right: calc((100vw - 984px) / 2);\n }\n .side.l-page-outset,\n dt-article .side.l-page-outset {\n clear: both;\n float: right;\n width: 624px;\n margin-right: calc((100vw - 984px) / 2);\n }\n}\n\n/* Centered */\n\n@media(min-width: 1080px) {\n .centered .l-body,\n .centered.l-body,\n dt-article.centered > div,\n dt-article.centered > p,\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 dt-article.centered > dt-code,\n dt-article.centered section > div,\n dt-article.centered section > p,\n dt-article.centered section > h2,\n dt-article.centered section > h3,\n dt-article.centered section > h4,\n dt-article.centered section > figure,\n dt-article.centered section > ul,\n dt-article.centered section > dt-byline,\n dt-article.centered section > dt-code,\n dt-article section.centered > div,\n dt-article section.centered > p,\n dt-article section.centered > h2,\n dt-article section.centered > h3,\n dt-article section.centered > h4,\n dt-article section.centered > figure,\n dt-article section.centered > ul,\n dt-article section.centered > dt-byline,\n dt-article section.centered > dt-code {\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 dt-article.centered > h1,\n dt-article.centered section > h1,\n dt-article section.centered > h1,\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 .centered .l-middle-outset,\n .centered.l-middle-outset,\n dt-article.centered .l-middle-outset {\n width: calc(816px + 96px);\n margin-left: auto;\n margin-right: auto;\n }\n\n /* page and screen are already centered */\n\n /* Side */\n\n .centered .side.l-body,\n .centered dt-article .side.l-body {\n clear: both;\n float: right;\n margin-top: 0;\n margin-left: 48px;\n margin-right: calc((100vw - 648px) / 2);\n width: calc(4 * 60px + 3 * 24px);\n }\n .centered .side.l-body-outset,\n .centered 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 - 648px) / 2);\n width: calc(4 * 60px + 3 * 24px);\n }\n .centered .side.l-middle,\n .centered dt-article .side.l-middle {\n clear: both;\n float: right;\n width: 396px;\n margin-left: 48px;\n margin-right: calc((100vw - 984px) / 2 + 168px / 2);\n }\n .centered .side.l-middle-outset,\n .centered dt-article .side.l-middle-outset {\n clear: both;\n float: right;\n width: 456px;\n margin-left: 48px;\n margin-right: calc((100vw - 984px) / 2 + 168px);\n }\n .centered .side.l-page,\n .centered dt-article .side.l-page {\n clear: both;\n float: right;\n width: 480px;\n margin-right: calc((100vw - 984px) / 2);\n }\n .centered .side.l-page-outset,\n .centered dt-article .side.l-page-outset {\n clear: both;\n float: right;\n width: 480px;\n margin-right: calc((100vw - 984px) / 2);\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\n}\n\n/* Rows and Columns */\n\n.row {\n display: flex;\n}\n.column {\n flex: 1;\n box-sizing: border-box;\n margin-right: 24px;\n margin-left: 24px;\n}\n.row > .column:first-of-type {\n margin-left: 0;\n}\n.row > .column:last-of-type {\n margin-right: 0;\n}\n";
30
31var article = "dt-article {\n display: block;\n color: rgba(0, 0, 0, 0.8);\n font: 17px/1.55em -apple-system, BlinkMacSystemFont, \"Roboto\", sans-serif;\n padding-bottom: 72px;\n overflow: hidden;\n background: white;\n min-height: calc(100vh - 70px - 182px);\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: 18px;\n font-weight: 400;\n font-size: 40px;\n line-height: 1em;\n font-family: HoeflerText-Regular, Cochin, Georgia, serif;\n}\n@media(min-width: 768px) {\n dt-article h1 {\n font-size: 46px;\n margin-top: 48px;\n margin-bottom: 12px;\n }\n}\n\n@media(min-width: 1080px) {\n .centered h1 {\n text-align: center;\n }\n\n dt-article h1 {\n font-size: 50px;\n letter-spacing: -0.02em;\n }\n\n dt-article > h1:first-of-type,\n dt-article section > h1:first-of-type {\n margin-top: 80px;\n }\n}\n\n\n@media(min-width: 1200px) {\n dt-article h1 {\n font-size: 56px;\n }\n\n dt-article > h1:first-of-type {\n margin-top: 100px;\n }\n}\n\n/* H2 */\n\ndt-article h2 {\n font-family: HoeflerText-Regular, Cochin, Georgia, serif;\n font-weight: 400;\n font-size: 26px;\n line-height: 1.25em;\n margin-top: 36px;\n margin-bottom: 24px;\n}\n\n@media(min-width: 1024px) {\n dt-article h2 {\n margin-top: 48px;\n font-size: 30px;\n }\n}\n\ndt-article h1 + h2 {\n font-weight: 300;\n font-size: 20px;\n line-height: 1.4em;\n margin-top: 8px;\n font-style: normal;\n}\n\n\n@media(min-width: 1080px) {\n .centered h1 + h2 {\n text-align: center;\n }\n dt-article h1 + h2 {\n margin-top: 12px;\n font-size: 24px;\n }\n}\n\n/* H3 */\n\ndt-article h3 {\n font-family: HoeflerText-Regular, Georgia, serif;\n font-weight: 400;\n font-size: 20px;\n line-height: 1.4em;\n margin-top: 36px;\n margin-bottom: 18px;\n font-style: italic;\n}\n\ndt-article h1 + h3 {\n margin-top: 48px;\n}\n\n@media(min-width: 1024px) {\n dt-article h3 {\n font-size: 26px;\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,\ndt-article ul,\ndt-article ol {\n margin-bottom: 24px;\n font-family: Georgia, serif;\n}\n\ndt-article p b,\ndt-article ul b,\ndt-article ol b {\n -webkit-font-smoothing: antialiased;\n}\n\ndt-article a {\n border-bottom: 1px solid rgba(0, 0, 0, 0.4);\n text-decoration: none;\n}\n\ndt-article a:hover {\n border-bottom: 1px solid rgba(0, 0, 0, 0.8);\n}\n\ndt-article .link {\n text-decoration: underline;\n cursor: pointer;\n}\n\ndt-article ul,\ndt-article ol {\n padding-left: 24px;\n}\n\ndt-article li {\n margin-bottom: 24px;\n margin-left: 0;\n padding-left: 0;\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,\ndt-article section > 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";
32
33var code = "/**\n * prism.js default theme for JavaScript, CSS and HTML\n * Based on dabblet (http://dabblet.com)\n * @author Lea Verou\n */\n\ncode {\n white-space: nowrap;\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\npre code {\n display: block;\n background: white;\n border-left: 3px solid rgba(0, 0, 0, 0.05);\n padding: 0 0 0 24px;\n}\n\n\ncode[class*=\"language-\"],\npre[class*=\"language-\"] {\n text-shadow: 0 1px white;\n font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;\n text-align: left;\n white-space: pre;\n word-spacing: normal;\n word-break: normal;\n word-wrap: normal;\n line-height: 1.5;\n\n -moz-tab-size: 4;\n -o-tab-size: 4;\n tab-size: 4;\n\n -webkit-hyphens: none;\n -moz-hyphens: none;\n -ms-hyphens: none;\n hyphens: none;\n}\n\npre[class*=\"language-\"]::-moz-selection, pre[class*=\"language-\"] ::-moz-selection,\ncode[class*=\"language-\"]::-moz-selection, code[class*=\"language-\"] ::-moz-selection {\n text-shadow: none;\n background: #b3d4fc;\n}\n\npre[class*=\"language-\"]::selection, pre[class*=\"language-\"] ::selection,\ncode[class*=\"language-\"]::selection, code[class*=\"language-\"] ::selection {\n text-shadow: none;\n background: #b3d4fc;\n}\n\n@media print {\n code[class*=\"language-\"],\n pre[class*=\"language-\"] {\n text-shadow: none;\n }\n}\n\n/* Code blocks */\npre[class*=\"language-\"] {\n overflow: auto;\n}\n\n:not(pre) > code[class*=\"language-\"],\npre[class*=\"language-\"] {\n}\n\n/* Inline code */\n:not(pre) > code[class*=\"language-\"] {\n white-space: normal;\n}\n\n.token.comment,\n.token.prolog,\n.token.doctype,\n.token.cdata {\n color: slategray;\n}\n\n.token.punctuation {\n color: #999;\n}\n\n.namespace {\n opacity: .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 color: #905;\n}\n\n.token.selector,\n.token.attr-name,\n.token.string,\n.token.char,\n.token.builtin,\n.token.inserted {\n color: #690;\n}\n\n.token.operator,\n.token.entity,\n.token.url,\n.language-css .token.string,\n.style .token.string {\n color: #a67f59;\n background: hsla(0, 0%, 100%, .5);\n}\n\n.token.atrule,\n.token.attr-value,\n.token.keyword {\n color: #07a;\n}\n\n.token.function {\n color: #DD4A68;\n}\n\n.token.regex,\n.token.important,\n.token.variable {\n color: #e90;\n}\n\n.token.important,\n.token.bold {\n font-weight: bold;\n}\n.token.italic {\n font-style: italic;\n}\n\n.token.entity {\n cursor: help;\n}\n";
34
35var print = "\n@media print {\n @page {\n size: 8in 11in;\n }\n html {\n }\n p, code {\n page-break-inside: avoid;\n }\n h2, h3 {\n page-break-after: avoid;\n }\n dt-header {\n visibility: hidden;\n }\n dt-footer {\n display: none!important;\n }\n}\n";
36
37var styles = function(dom) {
38 var s = dom.createElement("style");
39 s.textContent = base + layout + article + code + print;
40 dom.querySelector("head").appendChild(s);
41};
42
43function isNothing(subject) {
44 return (typeof subject === 'undefined') || (subject === null);
45}
46
47
48function isObject(subject) {
49 return (typeof subject === 'object') && (subject !== null);
50}
51
52
53function toArray(sequence) {
54 if (Array.isArray(sequence)) { return sequence; }
55 else if (isNothing(sequence)) { return []; }
56
57 return [ sequence ];
58}
59
60
61function extend(target, source) {
62 var index, length, key, sourceKeys;
63
64 if (source) {
65 sourceKeys = Object.keys(source);
66
67 for (index = 0, length = sourceKeys.length; index < length; index += 1) {
68 key = sourceKeys[index];
69 target[key] = source[key];
70 }
71 }
72
73 return target;
74}
75
76
77function repeat(string, count) {
78 var result = '', cycle;
79
80 for (cycle = 0; cycle < count; cycle += 1) {
81 result += string;
82 }
83
84 return result;
85}
86
87
88function isNegativeZero(number) {
89 return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
90}
91
92
93var isNothing_1 = isNothing;
94var isObject_1 = isObject;
95var toArray_1 = toArray;
96var repeat_1 = repeat;
97var isNegativeZero_1 = isNegativeZero;
98var extend_1 = extend;
99
100var common$1 = {
101 isNothing: isNothing_1,
102 isObject: isObject_1,
103 toArray: toArray_1,
104 repeat: repeat_1,
105 isNegativeZero: isNegativeZero_1,
106 extend: extend_1
107};
108
109// YAML error class. http://stackoverflow.com/questions/8458984
110//
111function YAMLException$2(reason, mark) {
112 // Super constructor
113 Error.call(this);
114
115 // Include stack trace in error object
116 if (Error.captureStackTrace) {
117 // Chrome and NodeJS
118 Error.captureStackTrace(this, this.constructor);
119 } else {
120 // FF, IE 10+ and Safari 6+. Fallback for others
121 this.stack = (new Error()).stack || '';
122 }
123
124 this.name = 'YAMLException';
125 this.reason = reason;
126 this.mark = mark;
127 this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
128}
129
130
131// Inherit from Error
132YAMLException$2.prototype = Object.create(Error.prototype);
133YAMLException$2.prototype.constructor = YAMLException$2;
134
135
136YAMLException$2.prototype.toString = function toString(compact) {
137 var result = this.name + ': ';
138
139 result += this.reason || '(unknown reason)';
140
141 if (!compact && this.mark) {
142 result += ' ' + this.mark.toString();
143 }
144
145 return result;
146};
147
148
149var exception = YAMLException$2;
150
151var common$3 = common$1;
152
153
154function Mark$1(name, buffer, position, line, column) {
155 this.name = name;
156 this.buffer = buffer;
157 this.position = position;
158 this.line = line;
159 this.column = column;
160}
161
162
163Mark$1.prototype.getSnippet = function getSnippet(indent, maxLength) {
164 var this$1 = this;
165
166 var head, start, tail, end, snippet;
167
168 if (!this.buffer) { return null; }
169
170 indent = indent || 4;
171 maxLength = maxLength || 75;
172
173 head = '';
174 start = this.position;
175
176 while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
177 start -= 1;
178 if (this$1.position - start > (maxLength / 2 - 1)) {
179 head = ' ... ';
180 start += 5;
181 break;
182 }
183 }
184
185 tail = '';
186 end = this.position;
187
188 while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
189 end += 1;
190 if (end - this$1.position > (maxLength / 2 - 1)) {
191 tail = ' ... ';
192 end -= 5;
193 break;
194 }
195 }
196
197 snippet = this.buffer.slice(start, end);
198
199 return common$3.repeat(' ', indent) + head + snippet + tail + '\n' +
200 common$3.repeat(' ', indent + this.position - start + head.length) + '^';
201};
202
203
204Mark$1.prototype.toString = function toString(compact) {
205 var snippet, where = '';
206
207 if (this.name) {
208 where += 'in "' + this.name + '" ';
209 }
210
211 where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
212
213 if (!compact) {
214 snippet = this.getSnippet();
215
216 if (snippet) {
217 where += ':\n' + snippet;
218 }
219 }
220
221 return where;
222};
223
224
225var mark = Mark$1;
226
227var YAMLException$4 = exception;
228
229var TYPE_CONSTRUCTOR_OPTIONS = [
230 'kind',
231 'resolve',
232 'construct',
233 'instanceOf',
234 'predicate',
235 'represent',
236 'defaultStyle',
237 'styleAliases'
238];
239
240var YAML_NODE_KINDS = [
241 'scalar',
242 'sequence',
243 'mapping'
244];
245
246function compileStyleAliases(map) {
247 var result = {};
248
249 if (map !== null) {
250 Object.keys(map).forEach(function (style) {
251 map[style].forEach(function (alias) {
252 result[String(alias)] = style;
253 });
254 });
255 }
256
257 return result;
258}
259
260function Type$2(tag, options) {
261 options = options || {};
262
263 Object.keys(options).forEach(function (name) {
264 if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
265 throw new YAMLException$4('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
266 }
267 });
268
269 // TODO: Add tag format check.
270 this.tag = tag;
271 this.kind = options['kind'] || null;
272 this.resolve = options['resolve'] || function () { return true; };
273 this.construct = options['construct'] || function (data) { return data; };
274 this.instanceOf = options['instanceOf'] || null;
275 this.predicate = options['predicate'] || null;
276 this.represent = options['represent'] || null;
277 this.defaultStyle = options['defaultStyle'] || null;
278 this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
279
280 if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
281 throw new YAMLException$4('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
282 }
283}
284
285var type = Type$2;
286
287/*eslint-disable max-len*/
288
289var common$4 = common$1;
290var YAMLException$3 = exception;
291var Type$1 = type;
292
293
294function compileList(schema, name, result) {
295 var exclude = [];
296
297 schema.include.forEach(function (includedSchema) {
298 result = compileList(includedSchema, name, result);
299 });
300
301 schema[name].forEach(function (currentType) {
302 result.forEach(function (previousType, previousIndex) {
303 if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
304 exclude.push(previousIndex);
305 }
306 });
307
308 result.push(currentType);
309 });
310
311 return result.filter(function (type$$1, index) {
312 return exclude.indexOf(index) === -1;
313 });
314}
315
316
317function compileMap(/* lists... */) {
318 var arguments$1 = arguments;
319
320 var result = {
321 scalar: {},
322 sequence: {},
323 mapping: {},
324 fallback: {}
325 }, index, length;
326
327 function collectType(type$$1) {
328 result[type$$1.kind][type$$1.tag] = result['fallback'][type$$1.tag] = type$$1;
329 }
330
331 for (index = 0, length = arguments.length; index < length; index += 1) {
332 arguments$1[index].forEach(collectType);
333 }
334 return result;
335}
336
337
338function Schema$2(definition) {
339 this.include = definition.include || [];
340 this.implicit = definition.implicit || [];
341 this.explicit = definition.explicit || [];
342
343 this.implicit.forEach(function (type$$1) {
344 if (type$$1.loadKind && type$$1.loadKind !== 'scalar') {
345 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.');
346 }
347 });
348
349 this.compiledImplicit = compileList(this, 'implicit', []);
350 this.compiledExplicit = compileList(this, 'explicit', []);
351 this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
352}
353
354
355Schema$2.DEFAULT = null;
356
357
358Schema$2.create = function createSchema() {
359 var schemas, types;
360
361 switch (arguments.length) {
362 case 1:
363 schemas = Schema$2.DEFAULT;
364 types = arguments[0];
365 break;
366
367 case 2:
368 schemas = arguments[0];
369 types = arguments[1];
370 break;
371
372 default:
373 throw new YAMLException$3('Wrong number of arguments for Schema.create function');
374 }
375
376 schemas = common$4.toArray(schemas);
377 types = common$4.toArray(types);
378
379 if (!schemas.every(function (schema) { return schema instanceof Schema$2; })) {
380 throw new YAMLException$3('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
381 }
382
383 if (!types.every(function (type$$1) { return type$$1 instanceof Type$1; })) {
384 throw new YAMLException$3('Specified list of YAML types (or a single Type object) contains a non-Type object.');
385 }
386
387 return new Schema$2({
388 include: schemas,
389 explicit: types
390 });
391};
392
393
394var schema = Schema$2;
395
396var Type$3 = type;
397
398var str = new Type$3('tag:yaml.org,2002:str', {
399 kind: 'scalar',
400 construct: function (data) { return data !== null ? data : ''; }
401});
402
403var Type$4 = type;
404
405var seq = new Type$4('tag:yaml.org,2002:seq', {
406 kind: 'sequence',
407 construct: function (data) { return data !== null ? data : []; }
408});
409
410var Type$5 = type;
411
412var map = new Type$5('tag:yaml.org,2002:map', {
413 kind: 'mapping',
414 construct: function (data) { return data !== null ? data : {}; }
415});
416
417var Schema$5 = schema;
418
419
420var failsafe = new Schema$5({
421 explicit: [
422 str,
423 seq,
424 map
425 ]
426});
427
428var Type$6 = type;
429
430function resolveYamlNull(data) {
431 if (data === null) { return true; }
432
433 var max = data.length;
434
435 return (max === 1 && data === '~') ||
436 (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
437}
438
439function constructYamlNull() {
440 return null;
441}
442
443function isNull(object) {
444 return object === null;
445}
446
447var _null = new Type$6('tag:yaml.org,2002:null', {
448 kind: 'scalar',
449 resolve: resolveYamlNull,
450 construct: constructYamlNull,
451 predicate: isNull,
452 represent: {
453 canonical: function () { return '~'; },
454 lowercase: function () { return 'null'; },
455 uppercase: function () { return 'NULL'; },
456 camelcase: function () { return 'Null'; }
457 },
458 defaultStyle: 'lowercase'
459});
460
461var Type$7 = type;
462
463function resolveYamlBoolean(data) {
464 if (data === null) { return false; }
465
466 var max = data.length;
467
468 return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
469 (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
470}
471
472function constructYamlBoolean(data) {
473 return data === 'true' ||
474 data === 'True' ||
475 data === 'TRUE';
476}
477
478function isBoolean(object) {
479 return Object.prototype.toString.call(object) === '[object Boolean]';
480}
481
482var bool = new Type$7('tag:yaml.org,2002:bool', {
483 kind: 'scalar',
484 resolve: resolveYamlBoolean,
485 construct: constructYamlBoolean,
486 predicate: isBoolean,
487 represent: {
488 lowercase: function (object) { return object ? 'true' : 'false'; },
489 uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
490 camelcase: function (object) { return object ? 'True' : 'False'; }
491 },
492 defaultStyle: 'lowercase'
493});
494
495var common$5 = common$1;
496var Type$8 = type;
497
498function isHexCode(c) {
499 return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
500 ((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
501 ((0x61/* a */ <= c) && (c <= 0x66/* f */));
502}
503
504function isOctCode(c) {
505 return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
506}
507
508function isDecCode(c) {
509 return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
510}
511
512function resolveYamlInteger(data) {
513 if (data === null) { return false; }
514
515 var max = data.length,
516 index = 0,
517 hasDigits = false,
518 ch;
519
520 if (!max) { return false; }
521
522 ch = data[index];
523
524 // sign
525 if (ch === '-' || ch === '+') {
526 ch = data[++index];
527 }
528
529 if (ch === '0') {
530 // 0
531 if (index + 1 === max) { return true; }
532 ch = data[++index];
533
534 // base 2, base 8, base 16
535
536 if (ch === 'b') {
537 // base 2
538 index++;
539
540 for (; index < max; index++) {
541 ch = data[index];
542 if (ch === '_') { continue; }
543 if (ch !== '0' && ch !== '1') { return false; }
544 hasDigits = true;
545 }
546 return hasDigits;
547 }
548
549
550 if (ch === 'x') {
551 // base 16
552 index++;
553
554 for (; index < max; index++) {
555 ch = data[index];
556 if (ch === '_') { continue; }
557 if (!isHexCode(data.charCodeAt(index))) { return false; }
558 hasDigits = true;
559 }
560 return hasDigits;
561 }
562
563 // base 8
564 for (; index < max; index++) {
565 ch = data[index];
566 if (ch === '_') { continue; }
567 if (!isOctCode(data.charCodeAt(index))) { return false; }
568 hasDigits = true;
569 }
570 return hasDigits;
571 }
572
573 // base 10 (except 0) or base 60
574
575 for (; index < max; index++) {
576 ch = data[index];
577 if (ch === '_') { continue; }
578 if (ch === ':') { break; }
579 if (!isDecCode(data.charCodeAt(index))) {
580 return false;
581 }
582 hasDigits = true;
583 }
584
585 if (!hasDigits) { return false; }
586
587 // if !base60 - done;
588 if (ch !== ':') { return true; }
589
590 // base60 almost not used, no needs to optimize
591 return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
592}
593
594function constructYamlInteger(data) {
595 var value = data, sign = 1, ch, base, digits = [];
596
597 if (value.indexOf('_') !== -1) {
598 value = value.replace(/_/g, '');
599 }
600
601 ch = value[0];
602
603 if (ch === '-' || ch === '+') {
604 if (ch === '-') { sign = -1; }
605 value = value.slice(1);
606 ch = value[0];
607 }
608
609 if (value === '0') { return 0; }
610
611 if (ch === '0') {
612 if (value[1] === 'b') { return sign * parseInt(value.slice(2), 2); }
613 if (value[1] === 'x') { return sign * parseInt(value, 16); }
614 return sign * parseInt(value, 8);
615 }
616
617 if (value.indexOf(':') !== -1) {
618 value.split(':').forEach(function (v) {
619 digits.unshift(parseInt(v, 10));
620 });
621
622 value = 0;
623 base = 1;
624
625 digits.forEach(function (d) {
626 value += (d * base);
627 base *= 60;
628 });
629
630 return sign * value;
631
632 }
633
634 return sign * parseInt(value, 10);
635}
636
637function isInteger(object) {
638 return (Object.prototype.toString.call(object)) === '[object Number]' &&
639 (object % 1 === 0 && !common$5.isNegativeZero(object));
640}
641
642var int_1 = new Type$8('tag:yaml.org,2002:int', {
643 kind: 'scalar',
644 resolve: resolveYamlInteger,
645 construct: constructYamlInteger,
646 predicate: isInteger,
647 represent: {
648 binary: function (object) { return '0b' + object.toString(2); },
649 octal: function (object) { return '0' + object.toString(8); },
650 decimal: function (object) { return object.toString(10); },
651 hexadecimal: function (object) { return '0x' + object.toString(16).toUpperCase(); }
652 },
653 defaultStyle: 'decimal',
654 styleAliases: {
655 binary: [ 2, 'bin' ],
656 octal: [ 8, 'oct' ],
657 decimal: [ 10, 'dec' ],
658 hexadecimal: [ 16, 'hex' ]
659 }
660});
661
662var common$6 = common$1;
663var Type$9 = type;
664
665var YAML_FLOAT_PATTERN = new RegExp(
666 '^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?' +
667 '|\\.[0-9_]+(?:[eE][-+][0-9]+)?' +
668 '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
669 '|[-+]?\\.(?:inf|Inf|INF)' +
670 '|\\.(?:nan|NaN|NAN))$');
671
672function resolveYamlFloat(data) {
673 if (data === null) { return false; }
674
675 if (!YAML_FLOAT_PATTERN.test(data)) { return false; }
676
677 return true;
678}
679
680function constructYamlFloat(data) {
681 var value, sign, base, digits;
682
683 value = data.replace(/_/g, '').toLowerCase();
684 sign = value[0] === '-' ? -1 : 1;
685 digits = [];
686
687 if ('+-'.indexOf(value[0]) >= 0) {
688 value = value.slice(1);
689 }
690
691 if (value === '.inf') {
692 return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
693
694 } else if (value === '.nan') {
695 return NaN;
696
697 } else if (value.indexOf(':') >= 0) {
698 value.split(':').forEach(function (v) {
699 digits.unshift(parseFloat(v, 10));
700 });
701
702 value = 0.0;
703 base = 1;
704
705 digits.forEach(function (d) {
706 value += d * base;
707 base *= 60;
708 });
709
710 return sign * value;
711
712 }
713 return sign * parseFloat(value, 10);
714}
715
716
717var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
718
719function representYamlFloat(object, style) {
720 var res;
721
722 if (isNaN(object)) {
723 switch (style) {
724 case 'lowercase': return '.nan';
725 case 'uppercase': return '.NAN';
726 case 'camelcase': return '.NaN';
727 }
728 } else if (Number.POSITIVE_INFINITY === object) {
729 switch (style) {
730 case 'lowercase': return '.inf';
731 case 'uppercase': return '.INF';
732 case 'camelcase': return '.Inf';
733 }
734 } else if (Number.NEGATIVE_INFINITY === object) {
735 switch (style) {
736 case 'lowercase': return '-.inf';
737 case 'uppercase': return '-.INF';
738 case 'camelcase': return '-.Inf';
739 }
740 } else if (common$6.isNegativeZero(object)) {
741 return '-0.0';
742 }
743
744 res = object.toString(10);
745
746 // JS stringifier can build scientific format without dots: 5e-100,
747 // while YAML requres dot: 5.e-100. Fix it with simple hack
748
749 return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
750}
751
752function isFloat(object) {
753 return (Object.prototype.toString.call(object) === '[object Number]') &&
754 (object % 1 !== 0 || common$6.isNegativeZero(object));
755}
756
757var float_1 = new Type$9('tag:yaml.org,2002:float', {
758 kind: 'scalar',
759 resolve: resolveYamlFloat,
760 construct: constructYamlFloat,
761 predicate: isFloat,
762 represent: representYamlFloat,
763 defaultStyle: 'lowercase'
764});
765
766var Schema$4 = schema;
767
768
769var json = new Schema$4({
770 include: [
771 failsafe
772 ],
773 implicit: [
774 _null,
775 bool,
776 int_1,
777 float_1
778 ]
779});
780
781var Schema$3 = schema;
782
783
784var core = new Schema$3({
785 include: [
786 json
787 ]
788});
789
790var Type$10 = type;
791
792var YAML_DATE_REGEXP = new RegExp(
793 '^([0-9][0-9][0-9][0-9])' + // [1] year
794 '-([0-9][0-9])' + // [2] month
795 '-([0-9][0-9])$'); // [3] day
796
797var YAML_TIMESTAMP_REGEXP = new RegExp(
798 '^([0-9][0-9][0-9][0-9])' + // [1] year
799 '-([0-9][0-9]?)' + // [2] month
800 '-([0-9][0-9]?)' + // [3] day
801 '(?:[Tt]|[ \\t]+)' + // ...
802 '([0-9][0-9]?)' + // [4] hour
803 ':([0-9][0-9])' + // [5] minute
804 ':([0-9][0-9])' + // [6] second
805 '(?:\\.([0-9]*))?' + // [7] fraction
806 '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
807 '(?::([0-9][0-9]))?))?$'); // [11] tz_minute
808
809function resolveYamlTimestamp(data) {
810 if (data === null) { return false; }
811 if (YAML_DATE_REGEXP.exec(data) !== null) { return true; }
812 if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) { return true; }
813 return false;
814}
815
816function constructYamlTimestamp(data) {
817 var match, year, month, day, hour, minute, second, fraction = 0,
818 delta = null, tz_hour, tz_minute, date;
819
820 match = YAML_DATE_REGEXP.exec(data);
821 if (match === null) { match = YAML_TIMESTAMP_REGEXP.exec(data); }
822
823 if (match === null) { throw new Error('Date resolve error'); }
824
825 // match: [1] year [2] month [3] day
826
827 year = +(match[1]);
828 month = +(match[2]) - 1; // JS month starts with 0
829 day = +(match[3]);
830
831 if (!match[4]) { // no hour
832 return new Date(Date.UTC(year, month, day));
833 }
834
835 // match: [4] hour [5] minute [6] second [7] fraction
836
837 hour = +(match[4]);
838 minute = +(match[5]);
839 second = +(match[6]);
840
841 if (match[7]) {
842 fraction = match[7].slice(0, 3);
843 while (fraction.length < 3) { // milli-seconds
844 fraction += '0';
845 }
846 fraction = +fraction;
847 }
848
849 // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
850
851 if (match[9]) {
852 tz_hour = +(match[10]);
853 tz_minute = +(match[11] || 0);
854 delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
855 if (match[9] === '-') { delta = -delta; }
856 }
857
858 date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
859
860 if (delta) { date.setTime(date.getTime() - delta); }
861
862 return date;
863}
864
865function representYamlTimestamp(object /*, style*/) {
866 return object.toISOString();
867}
868
869var timestamp = new Type$10('tag:yaml.org,2002:timestamp', {
870 kind: 'scalar',
871 resolve: resolveYamlTimestamp,
872 construct: constructYamlTimestamp,
873 instanceOf: Date,
874 represent: representYamlTimestamp
875});
876
877var Type$11 = type;
878
879function resolveYamlMerge(data) {
880 return data === '<<' || data === null;
881}
882
883var merge = new Type$11('tag:yaml.org,2002:merge', {
884 kind: 'scalar',
885 resolve: resolveYamlMerge
886});
887
888var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
889
890function commonjsRequire () {
891 throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
892}
893
894
895
896function createCommonjsModule(fn, module) {
897 return module = { exports: {} }, fn(module, module.exports), module.exports;
898}
899
900/*eslint-disable no-bitwise*/
901
902var NodeBuffer;
903
904try {
905 // A trick for browserified version, to not include `Buffer` shim
906 var _require = commonjsRequire;
907 NodeBuffer = _require('buffer').Buffer;
908} catch (__) {}
909
910var Type$12 = type;
911
912
913// [ 64, 65, 66 ] -> [ padding, CR, LF ]
914var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
915
916
917function resolveYamlBinary(data) {
918 if (data === null) { return false; }
919
920 var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
921
922 // Convert one by one.
923 for (idx = 0; idx < max; idx++) {
924 code = map.indexOf(data.charAt(idx));
925
926 // Skip CR/LF
927 if (code > 64) { continue; }
928
929 // Fail on illegal characters
930 if (code < 0) { return false; }
931
932 bitlen += 6;
933 }
934
935 // If there are any bits left, source was corrupted
936 return (bitlen % 8) === 0;
937}
938
939function constructYamlBinary(data) {
940 var idx, tailbits,
941 input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
942 max = input.length,
943 map = BASE64_MAP,
944 bits = 0,
945 result = [];
946
947 // Collect by 6*4 bits (3 bytes)
948
949 for (idx = 0; idx < max; idx++) {
950 if ((idx % 4 === 0) && idx) {
951 result.push((bits >> 16) & 0xFF);
952 result.push((bits >> 8) & 0xFF);
953 result.push(bits & 0xFF);
954 }
955
956 bits = (bits << 6) | map.indexOf(input.charAt(idx));
957 }
958
959 // Dump tail
960
961 tailbits = (max % 4) * 6;
962
963 if (tailbits === 0) {
964 result.push((bits >> 16) & 0xFF);
965 result.push((bits >> 8) & 0xFF);
966 result.push(bits & 0xFF);
967 } else if (tailbits === 18) {
968 result.push((bits >> 10) & 0xFF);
969 result.push((bits >> 2) & 0xFF);
970 } else if (tailbits === 12) {
971 result.push((bits >> 4) & 0xFF);
972 }
973
974 // Wrap into Buffer for NodeJS and leave Array for browser
975 if (NodeBuffer) { return new NodeBuffer(result); }
976
977 return result;
978}
979
980function representYamlBinary(object /*, style*/) {
981 var result = '', bits = 0, idx, tail,
982 max = object.length,
983 map = BASE64_MAP;
984
985 // Convert every three bytes to 4 ASCII characters.
986
987 for (idx = 0; idx < max; idx++) {
988 if ((idx % 3 === 0) && idx) {
989 result += map[(bits >> 18) & 0x3F];
990 result += map[(bits >> 12) & 0x3F];
991 result += map[(bits >> 6) & 0x3F];
992 result += map[bits & 0x3F];
993 }
994
995 bits = (bits << 8) + object[idx];
996 }
997
998 // Dump tail
999
1000 tail = max % 3;
1001
1002 if (tail === 0) {
1003 result += map[(bits >> 18) & 0x3F];
1004 result += map[(bits >> 12) & 0x3F];
1005 result += map[(bits >> 6) & 0x3F];
1006 result += map[bits & 0x3F];
1007 } else if (tail === 2) {
1008 result += map[(bits >> 10) & 0x3F];
1009 result += map[(bits >> 4) & 0x3F];
1010 result += map[(bits << 2) & 0x3F];
1011 result += map[64];
1012 } else if (tail === 1) {
1013 result += map[(bits >> 2) & 0x3F];
1014 result += map[(bits << 4) & 0x3F];
1015 result += map[64];
1016 result += map[64];
1017 }
1018
1019 return result;
1020}
1021
1022function isBinary(object) {
1023 return NodeBuffer && NodeBuffer.isBuffer(object);
1024}
1025
1026var binary = new Type$12('tag:yaml.org,2002:binary', {
1027 kind: 'scalar',
1028 resolve: resolveYamlBinary,
1029 construct: constructYamlBinary,
1030 predicate: isBinary,
1031 represent: representYamlBinary
1032});
1033
1034var Type$13 = type;
1035
1036var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1037var _toString = Object.prototype.toString;
1038
1039function resolveYamlOmap(data) {
1040 if (data === null) { return true; }
1041
1042 var objectKeys = [], index, length, pair, pairKey, pairHasKey,
1043 object = data;
1044
1045 for (index = 0, length = object.length; index < length; index += 1) {
1046 pair = object[index];
1047 pairHasKey = false;
1048
1049 if (_toString.call(pair) !== '[object Object]') { return false; }
1050
1051 for (pairKey in pair) {
1052 if (_hasOwnProperty$1.call(pair, pairKey)) {
1053 if (!pairHasKey) { pairHasKey = true; }
1054 else { return false; }
1055 }
1056 }
1057
1058 if (!pairHasKey) { return false; }
1059
1060 if (objectKeys.indexOf(pairKey) === -1) { objectKeys.push(pairKey); }
1061 else { return false; }
1062 }
1063
1064 return true;
1065}
1066
1067function constructYamlOmap(data) {
1068 return data !== null ? data : [];
1069}
1070
1071var omap = new Type$13('tag:yaml.org,2002:omap', {
1072 kind: 'sequence',
1073 resolve: resolveYamlOmap,
1074 construct: constructYamlOmap
1075});
1076
1077var Type$14 = type;
1078
1079var _toString$1 = Object.prototype.toString;
1080
1081function resolveYamlPairs(data) {
1082 if (data === null) { return true; }
1083
1084 var index, length, pair, keys, result,
1085 object = data;
1086
1087 result = new Array(object.length);
1088
1089 for (index = 0, length = object.length; index < length; index += 1) {
1090 pair = object[index];
1091
1092 if (_toString$1.call(pair) !== '[object Object]') { return false; }
1093
1094 keys = Object.keys(pair);
1095
1096 if (keys.length !== 1) { return false; }
1097
1098 result[index] = [ keys[0], pair[keys[0]] ];
1099 }
1100
1101 return true;
1102}
1103
1104function constructYamlPairs(data) {
1105 if (data === null) { return []; }
1106
1107 var index, length, pair, keys, result,
1108 object = data;
1109
1110 result = new Array(object.length);
1111
1112 for (index = 0, length = object.length; index < length; index += 1) {
1113 pair = object[index];
1114
1115 keys = Object.keys(pair);
1116
1117 result[index] = [ keys[0], pair[keys[0]] ];
1118 }
1119
1120 return result;
1121}
1122
1123var pairs = new Type$14('tag:yaml.org,2002:pairs', {
1124 kind: 'sequence',
1125 resolve: resolveYamlPairs,
1126 construct: constructYamlPairs
1127});
1128
1129var Type$15 = type;
1130
1131var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1132
1133function resolveYamlSet(data) {
1134 if (data === null) { return true; }
1135
1136 var key, object = data;
1137
1138 for (key in object) {
1139 if (_hasOwnProperty$2.call(object, key)) {
1140 if (object[key] !== null) { return false; }
1141 }
1142 }
1143
1144 return true;
1145}
1146
1147function constructYamlSet(data) {
1148 return data !== null ? data : {};
1149}
1150
1151var set = new Type$15('tag:yaml.org,2002:set', {
1152 kind: 'mapping',
1153 resolve: resolveYamlSet,
1154 construct: constructYamlSet
1155});
1156
1157var Schema$1 = schema;
1158
1159
1160var default_safe = new Schema$1({
1161 include: [
1162 core
1163 ],
1164 implicit: [
1165 timestamp,
1166 merge
1167 ],
1168 explicit: [
1169 binary,
1170 omap,
1171 pairs,
1172 set
1173 ]
1174});
1175
1176var Type$16 = type;
1177
1178function resolveJavascriptUndefined() {
1179 return true;
1180}
1181
1182function constructJavascriptUndefined() {
1183 /*eslint-disable no-undefined*/
1184 return undefined;
1185}
1186
1187function representJavascriptUndefined() {
1188 return '';
1189}
1190
1191function isUndefined(object) {
1192 return typeof object === 'undefined';
1193}
1194
1195var _undefined = new Type$16('tag:yaml.org,2002:js/undefined', {
1196 kind: 'scalar',
1197 resolve: resolveJavascriptUndefined,
1198 construct: constructJavascriptUndefined,
1199 predicate: isUndefined,
1200 represent: representJavascriptUndefined
1201});
1202
1203var Type$17 = type;
1204
1205function resolveJavascriptRegExp(data) {
1206 if (data === null) { return false; }
1207 if (data.length === 0) { return false; }
1208
1209 var regexp = data,
1210 tail = /\/([gim]*)$/.exec(data),
1211 modifiers = '';
1212
1213 // if regexp starts with '/' it can have modifiers and must be properly closed
1214 // `/foo/gim` - modifiers tail can be maximum 3 chars
1215 if (regexp[0] === '/') {
1216 if (tail) { modifiers = tail[1]; }
1217
1218 if (modifiers.length > 3) { return false; }
1219 // if expression starts with /, is should be properly terminated
1220 if (regexp[regexp.length - modifiers.length - 1] !== '/') { return false; }
1221 }
1222
1223 return true;
1224}
1225
1226function constructJavascriptRegExp(data) {
1227 var regexp = data,
1228 tail = /\/([gim]*)$/.exec(data),
1229 modifiers = '';
1230
1231 // `/foo/gim` - tail can be maximum 4 chars
1232 if (regexp[0] === '/') {
1233 if (tail) { modifiers = tail[1]; }
1234 regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
1235 }
1236
1237 return new RegExp(regexp, modifiers);
1238}
1239
1240function representJavascriptRegExp(object /*, style*/) {
1241 var result = '/' + object.source + '/';
1242
1243 if (object.global) { result += 'g'; }
1244 if (object.multiline) { result += 'm'; }
1245 if (object.ignoreCase) { result += 'i'; }
1246
1247 return result;
1248}
1249
1250function isRegExp(object) {
1251 return Object.prototype.toString.call(object) === '[object RegExp]';
1252}
1253
1254var regexp = new Type$17('tag:yaml.org,2002:js/regexp', {
1255 kind: 'scalar',
1256 resolve: resolveJavascriptRegExp,
1257 construct: constructJavascriptRegExp,
1258 predicate: isRegExp,
1259 represent: representJavascriptRegExp
1260});
1261
1262var esprima;
1263
1264// Browserified version does not have esprima
1265//
1266// 1. For node.js just require module as deps
1267// 2. For browser try to require mudule via external AMD system.
1268// If not found - try to fallback to window.esprima. If not
1269// found too - then fail to parse.
1270//
1271try {
1272 // workaround to exclude package from browserify list.
1273 var _require$1 = commonjsRequire;
1274 esprima = _require$1('esprima');
1275} catch (_) {
1276 /*global window */
1277 if (typeof window !== 'undefined') { esprima = window.esprima; }
1278}
1279
1280var Type$18 = type;
1281
1282function resolveJavascriptFunction(data) {
1283 if (data === null) { return false; }
1284
1285 try {
1286 var source = '(' + data + ')',
1287 ast = esprima.parse(source, { range: true });
1288
1289 if (ast.type !== 'Program' ||
1290 ast.body.length !== 1 ||
1291 ast.body[0].type !== 'ExpressionStatement' ||
1292 ast.body[0].expression.type !== 'FunctionExpression') {
1293 return false;
1294 }
1295
1296 return true;
1297 } catch (err) {
1298 return false;
1299 }
1300}
1301
1302function constructJavascriptFunction(data) {
1303 /*jslint evil:true*/
1304
1305 var source = '(' + data + ')',
1306 ast = esprima.parse(source, { range: true }),
1307 params = [],
1308 body;
1309
1310 if (ast.type !== 'Program' ||
1311 ast.body.length !== 1 ||
1312 ast.body[0].type !== 'ExpressionStatement' ||
1313 ast.body[0].expression.type !== 'FunctionExpression') {
1314 throw new Error('Failed to resolve function');
1315 }
1316
1317 ast.body[0].expression.params.forEach(function (param) {
1318 params.push(param.name);
1319 });
1320
1321 body = ast.body[0].expression.body.range;
1322
1323 // Esprima's ranges include the first '{' and the last '}' characters on
1324 // function expressions. So cut them out.
1325 /*eslint-disable no-new-func*/
1326 return new Function(params, source.slice(body[0] + 1, body[1] - 1));
1327}
1328
1329function representJavascriptFunction(object /*, style*/) {
1330 return object.toString();
1331}
1332
1333function isFunction(object) {
1334 return Object.prototype.toString.call(object) === '[object Function]';
1335}
1336
1337var _function = new Type$18('tag:yaml.org,2002:js/function', {
1338 kind: 'scalar',
1339 resolve: resolveJavascriptFunction,
1340 construct: constructJavascriptFunction,
1341 predicate: isFunction,
1342 represent: representJavascriptFunction
1343});
1344
1345var Schema$6 = schema;
1346
1347
1348var default_full = Schema$6.DEFAULT = new Schema$6({
1349 include: [
1350 default_safe
1351 ],
1352 explicit: [
1353 _undefined,
1354 regexp,
1355 _function
1356 ]
1357});
1358
1359/*eslint-disable max-len,no-use-before-define*/
1360
1361var common = common$1;
1362var YAMLException$1 = exception;
1363var Mark = mark;
1364var DEFAULT_SAFE_SCHEMA$1 = default_safe;
1365var DEFAULT_FULL_SCHEMA$1 = default_full;
1366
1367
1368var _hasOwnProperty = Object.prototype.hasOwnProperty;
1369
1370
1371var CONTEXT_FLOW_IN = 1;
1372var CONTEXT_FLOW_OUT = 2;
1373var CONTEXT_BLOCK_IN = 3;
1374var CONTEXT_BLOCK_OUT = 4;
1375
1376
1377var CHOMPING_CLIP = 1;
1378var CHOMPING_STRIP = 2;
1379var CHOMPING_KEEP = 3;
1380
1381
1382var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
1383var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
1384var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
1385var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
1386var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
1387
1388
1389function is_EOL(c) {
1390 return (c === 0x0A/* LF */) || (c === 0x0D/* CR */);
1391}
1392
1393function is_WHITE_SPACE(c) {
1394 return (c === 0x09/* Tab */) || (c === 0x20/* Space */);
1395}
1396
1397function is_WS_OR_EOL(c) {
1398 return (c === 0x09/* Tab */) ||
1399 (c === 0x20/* Space */) ||
1400 (c === 0x0A/* LF */) ||
1401 (c === 0x0D/* CR */);
1402}
1403
1404function is_FLOW_INDICATOR(c) {
1405 return c === 0x2C/* , */ ||
1406 c === 0x5B/* [ */ ||
1407 c === 0x5D/* ] */ ||
1408 c === 0x7B/* { */ ||
1409 c === 0x7D/* } */;
1410}
1411
1412function fromHexCode(c) {
1413 var lc;
1414
1415 if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
1416 return c - 0x30;
1417 }
1418
1419 /*eslint-disable no-bitwise*/
1420 lc = c | 0x20;
1421
1422 if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) {
1423 return lc - 0x61 + 10;
1424 }
1425
1426 return -1;
1427}
1428
1429function escapedHexLen(c) {
1430 if (c === 0x78/* x */) { return 2; }
1431 if (c === 0x75/* u */) { return 4; }
1432 if (c === 0x55/* U */) { return 8; }
1433 return 0;
1434}
1435
1436function fromDecimalCode(c) {
1437 if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
1438 return c - 0x30;
1439 }
1440
1441 return -1;
1442}
1443
1444function simpleEscapeSequence(c) {
1445 return (c === 0x30/* 0 */) ? '\x00' :
1446 (c === 0x61/* a */) ? '\x07' :
1447 (c === 0x62/* b */) ? '\x08' :
1448 (c === 0x74/* t */) ? '\x09' :
1449 (c === 0x09/* Tab */) ? '\x09' :
1450 (c === 0x6E/* n */) ? '\x0A' :
1451 (c === 0x76/* v */) ? '\x0B' :
1452 (c === 0x66/* f */) ? '\x0C' :
1453 (c === 0x72/* r */) ? '\x0D' :
1454 (c === 0x65/* e */) ? '\x1B' :
1455 (c === 0x20/* Space */) ? ' ' :
1456 (c === 0x22/* " */) ? '\x22' :
1457 (c === 0x2F/* / */) ? '/' :
1458 (c === 0x5C/* \ */) ? '\x5C' :
1459 (c === 0x4E/* N */) ? '\x85' :
1460 (c === 0x5F/* _ */) ? '\xA0' :
1461 (c === 0x4C/* L */) ? '\u2028' :
1462 (c === 0x50/* P */) ? '\u2029' : '';
1463}
1464
1465function charFromCodepoint(c) {
1466 if (c <= 0xFFFF) {
1467 return String.fromCharCode(c);
1468 }
1469 // Encode UTF-16 surrogate pair
1470 // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
1471 return String.fromCharCode(((c - 0x010000) >> 10) + 0xD800,
1472 ((c - 0x010000) & 0x03FF) + 0xDC00);
1473}
1474
1475var simpleEscapeCheck = new Array(256); // integer, for fast access
1476var simpleEscapeMap = new Array(256);
1477for (var i = 0; i < 256; i++) {
1478 simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
1479 simpleEscapeMap[i] = simpleEscapeSequence(i);
1480}
1481
1482
1483function State(input, options) {
1484 this.input = input;
1485
1486 this.filename = options['filename'] || null;
1487 this.schema = options['schema'] || DEFAULT_FULL_SCHEMA$1;
1488 this.onWarning = options['onWarning'] || null;
1489 this.legacy = options['legacy'] || false;
1490 this.json = options['json'] || false;
1491 this.listener = options['listener'] || null;
1492
1493 this.implicitTypes = this.schema.compiledImplicit;
1494 this.typeMap = this.schema.compiledTypeMap;
1495
1496 this.length = input.length;
1497 this.position = 0;
1498 this.line = 0;
1499 this.lineStart = 0;
1500 this.lineIndent = 0;
1501
1502 this.documents = [];
1503
1504 /*
1505 this.version;
1506 this.checkLineBreaks;
1507 this.tagMap;
1508 this.anchorMap;
1509 this.tag;
1510 this.anchor;
1511 this.kind;
1512 this.result;*/
1513
1514}
1515
1516
1517function generateError(state, message) {
1518 return new YAMLException$1(
1519 message,
1520 new Mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
1521}
1522
1523function throwError(state, message) {
1524 throw generateError(state, message);
1525}
1526
1527function throwWarning(state, message) {
1528 if (state.onWarning) {
1529 state.onWarning.call(null, generateError(state, message));
1530 }
1531}
1532
1533
1534var directiveHandlers = {
1535
1536 YAML: function handleYamlDirective(state, name, args) {
1537
1538 var match, major, minor;
1539
1540 if (state.version !== null) {
1541 throwError(state, 'duplication of %YAML directive');
1542 }
1543
1544 if (args.length !== 1) {
1545 throwError(state, 'YAML directive accepts exactly one argument');
1546 }
1547
1548 match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
1549
1550 if (match === null) {
1551 throwError(state, 'ill-formed argument of the YAML directive');
1552 }
1553
1554 major = parseInt(match[1], 10);
1555 minor = parseInt(match[2], 10);
1556
1557 if (major !== 1) {
1558 throwError(state, 'unacceptable YAML version of the document');
1559 }
1560
1561 state.version = args[0];
1562 state.checkLineBreaks = (minor < 2);
1563
1564 if (minor !== 1 && minor !== 2) {
1565 throwWarning(state, 'unsupported YAML version of the document');
1566 }
1567 },
1568
1569 TAG: function handleTagDirective(state, name, args) {
1570
1571 var handle, prefix;
1572
1573 if (args.length !== 2) {
1574 throwError(state, 'TAG directive accepts exactly two arguments');
1575 }
1576
1577 handle = args[0];
1578 prefix = args[1];
1579
1580 if (!PATTERN_TAG_HANDLE.test(handle)) {
1581 throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
1582 }
1583
1584 if (_hasOwnProperty.call(state.tagMap, handle)) {
1585 throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
1586 }
1587
1588 if (!PATTERN_TAG_URI.test(prefix)) {
1589 throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
1590 }
1591
1592 state.tagMap[handle] = prefix;
1593 }
1594};
1595
1596
1597function captureSegment(state, start, end, checkJson) {
1598 var _position, _length, _character, _result;
1599
1600 if (start < end) {
1601 _result = state.input.slice(start, end);
1602
1603 if (checkJson) {
1604 for (_position = 0, _length = _result.length;
1605 _position < _length;
1606 _position += 1) {
1607 _character = _result.charCodeAt(_position);
1608 if (!(_character === 0x09 ||
1609 (0x20 <= _character && _character <= 0x10FFFF))) {
1610 throwError(state, 'expected valid JSON character');
1611 }
1612 }
1613 } else if (PATTERN_NON_PRINTABLE.test(_result)) {
1614 throwError(state, 'the stream contains non-printable characters');
1615 }
1616
1617 state.result += _result;
1618 }
1619}
1620
1621function mergeMappings(state, destination, source, overridableKeys) {
1622 var sourceKeys, key, index, quantity;
1623
1624 if (!common.isObject(source)) {
1625 throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
1626 }
1627
1628 sourceKeys = Object.keys(source);
1629
1630 for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
1631 key = sourceKeys[index];
1632
1633 if (!_hasOwnProperty.call(destination, key)) {
1634 destination[key] = source[key];
1635 overridableKeys[key] = true;
1636 }
1637 }
1638}
1639
1640function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode) {
1641 var index, quantity;
1642
1643 keyNode = String(keyNode);
1644
1645 if (_result === null) {
1646 _result = {};
1647 }
1648
1649 if (keyTag === 'tag:yaml.org,2002:merge') {
1650 if (Array.isArray(valueNode)) {
1651 for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
1652 mergeMappings(state, _result, valueNode[index], overridableKeys);
1653 }
1654 } else {
1655 mergeMappings(state, _result, valueNode, overridableKeys);
1656 }
1657 } else {
1658 if (!state.json &&
1659 !_hasOwnProperty.call(overridableKeys, keyNode) &&
1660 _hasOwnProperty.call(_result, keyNode)) {
1661 throwError(state, 'duplicated mapping key');
1662 }
1663 _result[keyNode] = valueNode;
1664 delete overridableKeys[keyNode];
1665 }
1666
1667 return _result;
1668}
1669
1670function readLineBreak(state) {
1671 var ch;
1672
1673 ch = state.input.charCodeAt(state.position);
1674
1675 if (ch === 0x0A/* LF */) {
1676 state.position++;
1677 } else if (ch === 0x0D/* CR */) {
1678 state.position++;
1679 if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
1680 state.position++;
1681 }
1682 } else {
1683 throwError(state, 'a line break is expected');
1684 }
1685
1686 state.line += 1;
1687 state.lineStart = state.position;
1688}
1689
1690function skipSeparationSpace(state, allowComments, checkIndent) {
1691 var lineBreaks = 0,
1692 ch = state.input.charCodeAt(state.position);
1693
1694 while (ch !== 0) {
1695 while (is_WHITE_SPACE(ch)) {
1696 ch = state.input.charCodeAt(++state.position);
1697 }
1698
1699 if (allowComments && ch === 0x23/* # */) {
1700 do {
1701 ch = state.input.charCodeAt(++state.position);
1702 } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
1703 }
1704
1705 if (is_EOL(ch)) {
1706 readLineBreak(state);
1707
1708 ch = state.input.charCodeAt(state.position);
1709 lineBreaks++;
1710 state.lineIndent = 0;
1711
1712 while (ch === 0x20/* Space */) {
1713 state.lineIndent++;
1714 ch = state.input.charCodeAt(++state.position);
1715 }
1716 } else {
1717 break;
1718 }
1719 }
1720
1721 if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
1722 throwWarning(state, 'deficient indentation');
1723 }
1724
1725 return lineBreaks;
1726}
1727
1728function testDocumentSeparator(state) {
1729 var _position = state.position,
1730 ch;
1731
1732 ch = state.input.charCodeAt(_position);
1733
1734 // Condition state.position === state.lineStart is tested
1735 // in parent on each call, for efficiency. No needs to test here again.
1736 if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
1737 ch === state.input.charCodeAt(_position + 1) &&
1738 ch === state.input.charCodeAt(_position + 2)) {
1739
1740 _position += 3;
1741
1742 ch = state.input.charCodeAt(_position);
1743
1744 if (ch === 0 || is_WS_OR_EOL(ch)) {
1745 return true;
1746 }
1747 }
1748
1749 return false;
1750}
1751
1752function writeFoldedLines(state, count) {
1753 if (count === 1) {
1754 state.result += ' ';
1755 } else if (count > 1) {
1756 state.result += common.repeat('\n', count - 1);
1757 }
1758}
1759
1760
1761function readPlainScalar(state, nodeIndent, withinFlowCollection) {
1762 var preceding,
1763 following,
1764 captureStart,
1765 captureEnd,
1766 hasPendingContent,
1767 _line,
1768 _lineStart,
1769 _lineIndent,
1770 _kind = state.kind,
1771 _result = state.result,
1772 ch;
1773
1774 ch = state.input.charCodeAt(state.position);
1775
1776 if (is_WS_OR_EOL(ch) ||
1777 is_FLOW_INDICATOR(ch) ||
1778 ch === 0x23/* # */ ||
1779 ch === 0x26/* & */ ||
1780 ch === 0x2A/* * */ ||
1781 ch === 0x21/* ! */ ||
1782 ch === 0x7C/* | */ ||
1783 ch === 0x3E/* > */ ||
1784 ch === 0x27/* ' */ ||
1785 ch === 0x22/* " */ ||
1786 ch === 0x25/* % */ ||
1787 ch === 0x40/* @ */ ||
1788 ch === 0x60/* ` */) {
1789 return false;
1790 }
1791
1792 if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
1793 following = state.input.charCodeAt(state.position + 1);
1794
1795 if (is_WS_OR_EOL(following) ||
1796 withinFlowCollection && is_FLOW_INDICATOR(following)) {
1797 return false;
1798 }
1799 }
1800
1801 state.kind = 'scalar';
1802 state.result = '';
1803 captureStart = captureEnd = state.position;
1804 hasPendingContent = false;
1805
1806 while (ch !== 0) {
1807 if (ch === 0x3A/* : */) {
1808 following = state.input.charCodeAt(state.position + 1);
1809
1810 if (is_WS_OR_EOL(following) ||
1811 withinFlowCollection && is_FLOW_INDICATOR(following)) {
1812 break;
1813 }
1814
1815 } else if (ch === 0x23/* # */) {
1816 preceding = state.input.charCodeAt(state.position - 1);
1817
1818 if (is_WS_OR_EOL(preceding)) {
1819 break;
1820 }
1821
1822 } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
1823 withinFlowCollection && is_FLOW_INDICATOR(ch)) {
1824 break;
1825
1826 } else if (is_EOL(ch)) {
1827 _line = state.line;
1828 _lineStart = state.lineStart;
1829 _lineIndent = state.lineIndent;
1830 skipSeparationSpace(state, false, -1);
1831
1832 if (state.lineIndent >= nodeIndent) {
1833 hasPendingContent = true;
1834 ch = state.input.charCodeAt(state.position);
1835 continue;
1836 } else {
1837 state.position = captureEnd;
1838 state.line = _line;
1839 state.lineStart = _lineStart;
1840 state.lineIndent = _lineIndent;
1841 break;
1842 }
1843 }
1844
1845 if (hasPendingContent) {
1846 captureSegment(state, captureStart, captureEnd, false);
1847 writeFoldedLines(state, state.line - _line);
1848 captureStart = captureEnd = state.position;
1849 hasPendingContent = false;
1850 }
1851
1852 if (!is_WHITE_SPACE(ch)) {
1853 captureEnd = state.position + 1;
1854 }
1855
1856 ch = state.input.charCodeAt(++state.position);
1857 }
1858
1859 captureSegment(state, captureStart, captureEnd, false);
1860
1861 if (state.result) {
1862 return true;
1863 }
1864
1865 state.kind = _kind;
1866 state.result = _result;
1867 return false;
1868}
1869
1870function readSingleQuotedScalar(state, nodeIndent) {
1871 var ch,
1872 captureStart, captureEnd;
1873
1874 ch = state.input.charCodeAt(state.position);
1875
1876 if (ch !== 0x27/* ' */) {
1877 return false;
1878 }
1879
1880 state.kind = 'scalar';
1881 state.result = '';
1882 state.position++;
1883 captureStart = captureEnd = state.position;
1884
1885 while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1886 if (ch === 0x27/* ' */) {
1887 captureSegment(state, captureStart, state.position, true);
1888 ch = state.input.charCodeAt(++state.position);
1889
1890 if (ch === 0x27/* ' */) {
1891 captureStart = state.position;
1892 state.position++;
1893 captureEnd = state.position;
1894 } else {
1895 return true;
1896 }
1897
1898 } else if (is_EOL(ch)) {
1899 captureSegment(state, captureStart, captureEnd, true);
1900 writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1901 captureStart = captureEnd = state.position;
1902
1903 } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1904 throwError(state, 'unexpected end of the document within a single quoted scalar');
1905
1906 } else {
1907 state.position++;
1908 captureEnd = state.position;
1909 }
1910 }
1911
1912 throwError(state, 'unexpected end of the stream within a single quoted scalar');
1913}
1914
1915function readDoubleQuotedScalar(state, nodeIndent) {
1916 var captureStart,
1917 captureEnd,
1918 hexLength,
1919 hexResult,
1920 tmp,
1921 ch;
1922
1923 ch = state.input.charCodeAt(state.position);
1924
1925 if (ch !== 0x22/* " */) {
1926 return false;
1927 }
1928
1929 state.kind = 'scalar';
1930 state.result = '';
1931 state.position++;
1932 captureStart = captureEnd = state.position;
1933
1934 while ((ch = state.input.charCodeAt(state.position)) !== 0) {
1935 if (ch === 0x22/* " */) {
1936 captureSegment(state, captureStart, state.position, true);
1937 state.position++;
1938 return true;
1939
1940 } else if (ch === 0x5C/* \ */) {
1941 captureSegment(state, captureStart, state.position, true);
1942 ch = state.input.charCodeAt(++state.position);
1943
1944 if (is_EOL(ch)) {
1945 skipSeparationSpace(state, false, nodeIndent);
1946
1947 // TODO: rework to inline fn with no type cast?
1948 } else if (ch < 256 && simpleEscapeCheck[ch]) {
1949 state.result += simpleEscapeMap[ch];
1950 state.position++;
1951
1952 } else if ((tmp = escapedHexLen(ch)) > 0) {
1953 hexLength = tmp;
1954 hexResult = 0;
1955
1956 for (; hexLength > 0; hexLength--) {
1957 ch = state.input.charCodeAt(++state.position);
1958
1959 if ((tmp = fromHexCode(ch)) >= 0) {
1960 hexResult = (hexResult << 4) + tmp;
1961
1962 } else {
1963 throwError(state, 'expected hexadecimal character');
1964 }
1965 }
1966
1967 state.result += charFromCodepoint(hexResult);
1968
1969 state.position++;
1970
1971 } else {
1972 throwError(state, 'unknown escape sequence');
1973 }
1974
1975 captureStart = captureEnd = state.position;
1976
1977 } else if (is_EOL(ch)) {
1978 captureSegment(state, captureStart, captureEnd, true);
1979 writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
1980 captureStart = captureEnd = state.position;
1981
1982 } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
1983 throwError(state, 'unexpected end of the document within a double quoted scalar');
1984
1985 } else {
1986 state.position++;
1987 captureEnd = state.position;
1988 }
1989 }
1990
1991 throwError(state, 'unexpected end of the stream within a double quoted scalar');
1992}
1993
1994function readFlowCollection(state, nodeIndent) {
1995 var readNext = true,
1996 _line,
1997 _tag = state.tag,
1998 _result,
1999 _anchor = state.anchor,
2000 following,
2001 terminator,
2002 isPair,
2003 isExplicitPair,
2004 isMapping,
2005 overridableKeys = {},
2006 keyNode,
2007 keyTag,
2008 valueNode,
2009 ch;
2010
2011 ch = state.input.charCodeAt(state.position);
2012
2013 if (ch === 0x5B/* [ */) {
2014 terminator = 0x5D;/* ] */
2015 isMapping = false;
2016 _result = [];
2017 } else if (ch === 0x7B/* { */) {
2018 terminator = 0x7D;/* } */
2019 isMapping = true;
2020 _result = {};
2021 } else {
2022 return false;
2023 }
2024
2025 if (state.anchor !== null) {
2026 state.anchorMap[state.anchor] = _result;
2027 }
2028
2029 ch = state.input.charCodeAt(++state.position);
2030
2031 while (ch !== 0) {
2032 skipSeparationSpace(state, true, nodeIndent);
2033
2034 ch = state.input.charCodeAt(state.position);
2035
2036 if (ch === terminator) {
2037 state.position++;
2038 state.tag = _tag;
2039 state.anchor = _anchor;
2040 state.kind = isMapping ? 'mapping' : 'sequence';
2041 state.result = _result;
2042 return true;
2043 } else if (!readNext) {
2044 throwError(state, 'missed comma between flow collection entries');
2045 }
2046
2047 keyTag = keyNode = valueNode = null;
2048 isPair = isExplicitPair = false;
2049
2050 if (ch === 0x3F/* ? */) {
2051 following = state.input.charCodeAt(state.position + 1);
2052
2053 if (is_WS_OR_EOL(following)) {
2054 isPair = isExplicitPair = true;
2055 state.position++;
2056 skipSeparationSpace(state, true, nodeIndent);
2057 }
2058 }
2059
2060 _line = state.line;
2061 composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
2062 keyTag = state.tag;
2063 keyNode = state.result;
2064 skipSeparationSpace(state, true, nodeIndent);
2065
2066 ch = state.input.charCodeAt(state.position);
2067
2068 if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
2069 isPair = true;
2070 ch = state.input.charCodeAt(++state.position);
2071 skipSeparationSpace(state, true, nodeIndent);
2072 composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
2073 valueNode = state.result;
2074 }
2075
2076 if (isMapping) {
2077 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
2078 } else if (isPair) {
2079 _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
2080 } else {
2081 _result.push(keyNode);
2082 }
2083
2084 skipSeparationSpace(state, true, nodeIndent);
2085
2086 ch = state.input.charCodeAt(state.position);
2087
2088 if (ch === 0x2C/* , */) {
2089 readNext = true;
2090 ch = state.input.charCodeAt(++state.position);
2091 } else {
2092 readNext = false;
2093 }
2094 }
2095
2096 throwError(state, 'unexpected end of the stream within a flow collection');
2097}
2098
2099function readBlockScalar(state, nodeIndent) {
2100 var captureStart,
2101 folding,
2102 chomping = CHOMPING_CLIP,
2103 didReadContent = false,
2104 detectedIndent = false,
2105 textIndent = nodeIndent,
2106 emptyLines = 0,
2107 atMoreIndented = false,
2108 tmp,
2109 ch;
2110
2111 ch = state.input.charCodeAt(state.position);
2112
2113 if (ch === 0x7C/* | */) {
2114 folding = false;
2115 } else if (ch === 0x3E/* > */) {
2116 folding = true;
2117 } else {
2118 return false;
2119 }
2120
2121 state.kind = 'scalar';
2122 state.result = '';
2123
2124 while (ch !== 0) {
2125 ch = state.input.charCodeAt(++state.position);
2126
2127 if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
2128 if (CHOMPING_CLIP === chomping) {
2129 chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
2130 } else {
2131 throwError(state, 'repeat of a chomping mode identifier');
2132 }
2133
2134 } else if ((tmp = fromDecimalCode(ch)) >= 0) {
2135 if (tmp === 0) {
2136 throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
2137 } else if (!detectedIndent) {
2138 textIndent = nodeIndent + tmp - 1;
2139 detectedIndent = true;
2140 } else {
2141 throwError(state, 'repeat of an indentation width identifier');
2142 }
2143
2144 } else {
2145 break;
2146 }
2147 }
2148
2149 if (is_WHITE_SPACE(ch)) {
2150 do { ch = state.input.charCodeAt(++state.position); }
2151 while (is_WHITE_SPACE(ch));
2152
2153 if (ch === 0x23/* # */) {
2154 do { ch = state.input.charCodeAt(++state.position); }
2155 while (!is_EOL(ch) && (ch !== 0));
2156 }
2157 }
2158
2159 while (ch !== 0) {
2160 readLineBreak(state);
2161 state.lineIndent = 0;
2162
2163 ch = state.input.charCodeAt(state.position);
2164
2165 while ((!detectedIndent || state.lineIndent < textIndent) &&
2166 (ch === 0x20/* Space */)) {
2167 state.lineIndent++;
2168 ch = state.input.charCodeAt(++state.position);
2169 }
2170
2171 if (!detectedIndent && state.lineIndent > textIndent) {
2172 textIndent = state.lineIndent;
2173 }
2174
2175 if (is_EOL(ch)) {
2176 emptyLines++;
2177 continue;
2178 }
2179
2180 // End of the scalar.
2181 if (state.lineIndent < textIndent) {
2182
2183 // Perform the chomping.
2184 if (chomping === CHOMPING_KEEP) {
2185 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2186 } else if (chomping === CHOMPING_CLIP) {
2187 if (didReadContent) { // i.e. only if the scalar is not empty.
2188 state.result += '\n';
2189 }
2190 }
2191
2192 // Break this `while` cycle and go to the funciton's epilogue.
2193 break;
2194 }
2195
2196 // Folded style: use fancy rules to handle line breaks.
2197 if (folding) {
2198
2199 // Lines starting with white space characters (more-indented lines) are not folded.
2200 if (is_WHITE_SPACE(ch)) {
2201 atMoreIndented = true;
2202 // except for the first content line (cf. Example 8.1)
2203 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2204
2205 // End of more-indented block.
2206 } else if (atMoreIndented) {
2207 atMoreIndented = false;
2208 state.result += common.repeat('\n', emptyLines + 1);
2209
2210 // Just one line break - perceive as the same line.
2211 } else if (emptyLines === 0) {
2212 if (didReadContent) { // i.e. only if we have already read some scalar content.
2213 state.result += ' ';
2214 }
2215
2216 // Several line breaks - perceive as different lines.
2217 } else {
2218 state.result += common.repeat('\n', emptyLines);
2219 }
2220
2221 // Literal style: just add exact number of line breaks between content lines.
2222 } else {
2223 // Keep all line breaks except the header line break.
2224 state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2225 }
2226
2227 didReadContent = true;
2228 detectedIndent = true;
2229 emptyLines = 0;
2230 captureStart = state.position;
2231
2232 while (!is_EOL(ch) && (ch !== 0)) {
2233 ch = state.input.charCodeAt(++state.position);
2234 }
2235
2236 captureSegment(state, captureStart, state.position, false);
2237 }
2238
2239 return true;
2240}
2241
2242function readBlockSequence(state, nodeIndent) {
2243 var _line,
2244 _tag = state.tag,
2245 _anchor = state.anchor,
2246 _result = [],
2247 following,
2248 detected = false,
2249 ch;
2250
2251 if (state.anchor !== null) {
2252 state.anchorMap[state.anchor] = _result;
2253 }
2254
2255 ch = state.input.charCodeAt(state.position);
2256
2257 while (ch !== 0) {
2258
2259 if (ch !== 0x2D/* - */) {
2260 break;
2261 }
2262
2263 following = state.input.charCodeAt(state.position + 1);
2264
2265 if (!is_WS_OR_EOL(following)) {
2266 break;
2267 }
2268
2269 detected = true;
2270 state.position++;
2271
2272 if (skipSeparationSpace(state, true, -1)) {
2273 if (state.lineIndent <= nodeIndent) {
2274 _result.push(null);
2275 ch = state.input.charCodeAt(state.position);
2276 continue;
2277 }
2278 }
2279
2280 _line = state.line;
2281 composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
2282 _result.push(state.result);
2283 skipSeparationSpace(state, true, -1);
2284
2285 ch = state.input.charCodeAt(state.position);
2286
2287 if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
2288 throwError(state, 'bad indentation of a sequence entry');
2289 } else if (state.lineIndent < nodeIndent) {
2290 break;
2291 }
2292 }
2293
2294 if (detected) {
2295 state.tag = _tag;
2296 state.anchor = _anchor;
2297 state.kind = 'sequence';
2298 state.result = _result;
2299 return true;
2300 }
2301 return false;
2302}
2303
2304function readBlockMapping(state, nodeIndent, flowIndent) {
2305 var following,
2306 allowCompact,
2307 _line,
2308 _tag = state.tag,
2309 _anchor = state.anchor,
2310 _result = {},
2311 overridableKeys = {},
2312 keyTag = null,
2313 keyNode = null,
2314 valueNode = null,
2315 atExplicitKey = false,
2316 detected = false,
2317 ch;
2318
2319 if (state.anchor !== null) {
2320 state.anchorMap[state.anchor] = _result;
2321 }
2322
2323 ch = state.input.charCodeAt(state.position);
2324
2325 while (ch !== 0) {
2326 following = state.input.charCodeAt(state.position + 1);
2327 _line = state.line; // Save the current line.
2328
2329 //
2330 // Explicit notation case. There are two separate blocks:
2331 // first for the key (denoted by "?") and second for the value (denoted by ":")
2332 //
2333 if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
2334
2335 if (ch === 0x3F/* ? */) {
2336 if (atExplicitKey) {
2337 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
2338 keyTag = keyNode = valueNode = null;
2339 }
2340
2341 detected = true;
2342 atExplicitKey = true;
2343 allowCompact = true;
2344
2345 } else if (atExplicitKey) {
2346 // i.e. 0x3A/* : */ === character after the explicit key.
2347 atExplicitKey = false;
2348 allowCompact = true;
2349
2350 } else {
2351 throwError(state, 'incomplete explicit mapping pair; a key node is missed');
2352 }
2353
2354 state.position += 1;
2355 ch = following;
2356
2357 //
2358 // Implicit notation case. Flow-style node as the key first, then ":", and the value.
2359 //
2360 } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
2361
2362 if (state.line === _line) {
2363 ch = state.input.charCodeAt(state.position);
2364
2365 while (is_WHITE_SPACE(ch)) {
2366 ch = state.input.charCodeAt(++state.position);
2367 }
2368
2369 if (ch === 0x3A/* : */) {
2370 ch = state.input.charCodeAt(++state.position);
2371
2372 if (!is_WS_OR_EOL(ch)) {
2373 throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
2374 }
2375
2376 if (atExplicitKey) {
2377 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
2378 keyTag = keyNode = valueNode = null;
2379 }
2380
2381 detected = true;
2382 atExplicitKey = false;
2383 allowCompact = false;
2384 keyTag = state.tag;
2385 keyNode = state.result;
2386
2387 } else if (detected) {
2388 throwError(state, 'can not read an implicit mapping pair; a colon is missed');
2389
2390 } else {
2391 state.tag = _tag;
2392 state.anchor = _anchor;
2393 return true; // Keep the result of `composeNode`.
2394 }
2395
2396 } else if (detected) {
2397 throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
2398
2399 } else {
2400 state.tag = _tag;
2401 state.anchor = _anchor;
2402 return true; // Keep the result of `composeNode`.
2403 }
2404
2405 } else {
2406 break; // Reading is done. Go to the epilogue.
2407 }
2408
2409 //
2410 // Common reading code for both explicit and implicit notations.
2411 //
2412 if (state.line === _line || state.lineIndent > nodeIndent) {
2413 if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
2414 if (atExplicitKey) {
2415 keyNode = state.result;
2416 } else {
2417 valueNode = state.result;
2418 }
2419 }
2420
2421 if (!atExplicitKey) {
2422 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
2423 keyTag = keyNode = valueNode = null;
2424 }
2425
2426 skipSeparationSpace(state, true, -1);
2427 ch = state.input.charCodeAt(state.position);
2428 }
2429
2430 if (state.lineIndent > nodeIndent && (ch !== 0)) {
2431 throwError(state, 'bad indentation of a mapping entry');
2432 } else if (state.lineIndent < nodeIndent) {
2433 break;
2434 }
2435 }
2436
2437 //
2438 // Epilogue.
2439 //
2440
2441 // Special case: last mapping's node contains only the key in explicit notation.
2442 if (atExplicitKey) {
2443 storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
2444 }
2445
2446 // Expose the resulting mapping.
2447 if (detected) {
2448 state.tag = _tag;
2449 state.anchor = _anchor;
2450 state.kind = 'mapping';
2451 state.result = _result;
2452 }
2453
2454 return detected;
2455}
2456
2457function readTagProperty(state) {
2458 var _position,
2459 isVerbatim = false,
2460 isNamed = false,
2461 tagHandle,
2462 tagName,
2463 ch;
2464
2465 ch = state.input.charCodeAt(state.position);
2466
2467 if (ch !== 0x21/* ! */) { return false; }
2468
2469 if (state.tag !== null) {
2470 throwError(state, 'duplication of a tag property');
2471 }
2472
2473 ch = state.input.charCodeAt(++state.position);
2474
2475 if (ch === 0x3C/* < */) {
2476 isVerbatim = true;
2477 ch = state.input.charCodeAt(++state.position);
2478
2479 } else if (ch === 0x21/* ! */) {
2480 isNamed = true;
2481 tagHandle = '!!';
2482 ch = state.input.charCodeAt(++state.position);
2483
2484 } else {
2485 tagHandle = '!';
2486 }
2487
2488 _position = state.position;
2489
2490 if (isVerbatim) {
2491 do { ch = state.input.charCodeAt(++state.position); }
2492 while (ch !== 0 && ch !== 0x3E/* > */);
2493
2494 if (state.position < state.length) {
2495 tagName = state.input.slice(_position, state.position);
2496 ch = state.input.charCodeAt(++state.position);
2497 } else {
2498 throwError(state, 'unexpected end of the stream within a verbatim tag');
2499 }
2500 } else {
2501 while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2502
2503 if (ch === 0x21/* ! */) {
2504 if (!isNamed) {
2505 tagHandle = state.input.slice(_position - 1, state.position + 1);
2506
2507 if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
2508 throwError(state, 'named tag handle cannot contain such characters');
2509 }
2510
2511 isNamed = true;
2512 _position = state.position + 1;
2513 } else {
2514 throwError(state, 'tag suffix cannot contain exclamation marks');
2515 }
2516 }
2517
2518 ch = state.input.charCodeAt(++state.position);
2519 }
2520
2521 tagName = state.input.slice(_position, state.position);
2522
2523 if (PATTERN_FLOW_INDICATORS.test(tagName)) {
2524 throwError(state, 'tag suffix cannot contain flow indicator characters');
2525 }
2526 }
2527
2528 if (tagName && !PATTERN_TAG_URI.test(tagName)) {
2529 throwError(state, 'tag name cannot contain such characters: ' + tagName);
2530 }
2531
2532 if (isVerbatim) {
2533 state.tag = tagName;
2534
2535 } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
2536 state.tag = state.tagMap[tagHandle] + tagName;
2537
2538 } else if (tagHandle === '!') {
2539 state.tag = '!' + tagName;
2540
2541 } else if (tagHandle === '!!') {
2542 state.tag = 'tag:yaml.org,2002:' + tagName;
2543
2544 } else {
2545 throwError(state, 'undeclared tag handle "' + tagHandle + '"');
2546 }
2547
2548 return true;
2549}
2550
2551function readAnchorProperty(state) {
2552 var _position,
2553 ch;
2554
2555 ch = state.input.charCodeAt(state.position);
2556
2557 if (ch !== 0x26/* & */) { return false; }
2558
2559 if (state.anchor !== null) {
2560 throwError(state, 'duplication of an anchor property');
2561 }
2562
2563 ch = state.input.charCodeAt(++state.position);
2564 _position = state.position;
2565
2566 while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
2567 ch = state.input.charCodeAt(++state.position);
2568 }
2569
2570 if (state.position === _position) {
2571 throwError(state, 'name of an anchor node must contain at least one character');
2572 }
2573
2574 state.anchor = state.input.slice(_position, state.position);
2575 return true;
2576}
2577
2578function readAlias(state) {
2579 var _position, alias,
2580 ch;
2581
2582 ch = state.input.charCodeAt(state.position);
2583
2584 if (ch !== 0x2A/* * */) { return false; }
2585
2586 ch = state.input.charCodeAt(++state.position);
2587 _position = state.position;
2588
2589 while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
2590 ch = state.input.charCodeAt(++state.position);
2591 }
2592
2593 if (state.position === _position) {
2594 throwError(state, 'name of an alias node must contain at least one character');
2595 }
2596
2597 alias = state.input.slice(_position, state.position);
2598
2599 if (!state.anchorMap.hasOwnProperty(alias)) {
2600 throwError(state, 'unidentified alias "' + alias + '"');
2601 }
2602
2603 state.result = state.anchorMap[alias];
2604 skipSeparationSpace(state, true, -1);
2605 return true;
2606}
2607
2608function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
2609 var allowBlockStyles,
2610 allowBlockScalars,
2611 allowBlockCollections,
2612 indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
2613 atNewLine = false,
2614 hasContent = false,
2615 typeIndex,
2616 typeQuantity,
2617 type,
2618 flowIndent,
2619 blockIndent;
2620
2621 if (state.listener !== null) {
2622 state.listener('open', state);
2623 }
2624
2625 state.tag = null;
2626 state.anchor = null;
2627 state.kind = null;
2628 state.result = null;
2629
2630 allowBlockStyles = allowBlockScalars = allowBlockCollections =
2631 CONTEXT_BLOCK_OUT === nodeContext ||
2632 CONTEXT_BLOCK_IN === nodeContext;
2633
2634 if (allowToSeek) {
2635 if (skipSeparationSpace(state, true, -1)) {
2636 atNewLine = true;
2637
2638 if (state.lineIndent > parentIndent) {
2639 indentStatus = 1;
2640 } else if (state.lineIndent === parentIndent) {
2641 indentStatus = 0;
2642 } else if (state.lineIndent < parentIndent) {
2643 indentStatus = -1;
2644 }
2645 }
2646 }
2647
2648 if (indentStatus === 1) {
2649 while (readTagProperty(state) || readAnchorProperty(state)) {
2650 if (skipSeparationSpace(state, true, -1)) {
2651 atNewLine = true;
2652 allowBlockCollections = allowBlockStyles;
2653
2654 if (state.lineIndent > parentIndent) {
2655 indentStatus = 1;
2656 } else if (state.lineIndent === parentIndent) {
2657 indentStatus = 0;
2658 } else if (state.lineIndent < parentIndent) {
2659 indentStatus = -1;
2660 }
2661 } else {
2662 allowBlockCollections = false;
2663 }
2664 }
2665 }
2666
2667 if (allowBlockCollections) {
2668 allowBlockCollections = atNewLine || allowCompact;
2669 }
2670
2671 if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
2672 if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
2673 flowIndent = parentIndent;
2674 } else {
2675 flowIndent = parentIndent + 1;
2676 }
2677
2678 blockIndent = state.position - state.lineStart;
2679
2680 if (indentStatus === 1) {
2681 if (allowBlockCollections &&
2682 (readBlockSequence(state, blockIndent) ||
2683 readBlockMapping(state, blockIndent, flowIndent)) ||
2684 readFlowCollection(state, flowIndent)) {
2685 hasContent = true;
2686 } else {
2687 if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
2688 readSingleQuotedScalar(state, flowIndent) ||
2689 readDoubleQuotedScalar(state, flowIndent)) {
2690 hasContent = true;
2691
2692 } else if (readAlias(state)) {
2693 hasContent = true;
2694
2695 if (state.tag !== null || state.anchor !== null) {
2696 throwError(state, 'alias node should not have any properties');
2697 }
2698
2699 } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
2700 hasContent = true;
2701
2702 if (state.tag === null) {
2703 state.tag = '?';
2704 }
2705 }
2706
2707 if (state.anchor !== null) {
2708 state.anchorMap[state.anchor] = state.result;
2709 }
2710 }
2711 } else if (indentStatus === 0) {
2712 // Special case: block sequences are allowed to have same indentation level as the parent.
2713 // http://www.yaml.org/spec/1.2/spec.html#id2799784
2714 hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
2715 }
2716 }
2717
2718 if (state.tag !== null && state.tag !== '!') {
2719 if (state.tag === '?') {
2720 for (typeIndex = 0, typeQuantity = state.implicitTypes.length;
2721 typeIndex < typeQuantity;
2722 typeIndex += 1) {
2723 type = state.implicitTypes[typeIndex];
2724
2725 // Implicit resolving is not allowed for non-scalar types, and '?'
2726 // non-specific tag is only assigned to plain scalars. So, it isn't
2727 // needed to check for 'kind' conformity.
2728
2729 if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
2730 state.result = type.construct(state.result);
2731 state.tag = type.tag;
2732 if (state.anchor !== null) {
2733 state.anchorMap[state.anchor] = state.result;
2734 }
2735 break;
2736 }
2737 }
2738 } else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
2739 type = state.typeMap[state.kind || 'fallback'][state.tag];
2740
2741 if (state.result !== null && type.kind !== state.kind) {
2742 throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
2743 }
2744
2745 if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched
2746 throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
2747 } else {
2748 state.result = type.construct(state.result);
2749 if (state.anchor !== null) {
2750 state.anchorMap[state.anchor] = state.result;
2751 }
2752 }
2753 } else {
2754 throwError(state, 'unknown tag !<' + state.tag + '>');
2755 }
2756 }
2757
2758 if (state.listener !== null) {
2759 state.listener('close', state);
2760 }
2761 return state.tag !== null || state.anchor !== null || hasContent;
2762}
2763
2764function readDocument(state) {
2765 var documentStart = state.position,
2766 _position,
2767 directiveName,
2768 directiveArgs,
2769 hasDirectives = false,
2770 ch;
2771
2772 state.version = null;
2773 state.checkLineBreaks = state.legacy;
2774 state.tagMap = {};
2775 state.anchorMap = {};
2776
2777 while ((ch = state.input.charCodeAt(state.position)) !== 0) {
2778 skipSeparationSpace(state, true, -1);
2779
2780 ch = state.input.charCodeAt(state.position);
2781
2782 if (state.lineIndent > 0 || ch !== 0x25/* % */) {
2783 break;
2784 }
2785
2786 hasDirectives = true;
2787 ch = state.input.charCodeAt(++state.position);
2788 _position = state.position;
2789
2790 while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2791 ch = state.input.charCodeAt(++state.position);
2792 }
2793
2794 directiveName = state.input.slice(_position, state.position);
2795 directiveArgs = [];
2796
2797 if (directiveName.length < 1) {
2798 throwError(state, 'directive name must not be less than one character in length');
2799 }
2800
2801 while (ch !== 0) {
2802 while (is_WHITE_SPACE(ch)) {
2803 ch = state.input.charCodeAt(++state.position);
2804 }
2805
2806 if (ch === 0x23/* # */) {
2807 do { ch = state.input.charCodeAt(++state.position); }
2808 while (ch !== 0 && !is_EOL(ch));
2809 break;
2810 }
2811
2812 if (is_EOL(ch)) { break; }
2813
2814 _position = state.position;
2815
2816 while (ch !== 0 && !is_WS_OR_EOL(ch)) {
2817 ch = state.input.charCodeAt(++state.position);
2818 }
2819
2820 directiveArgs.push(state.input.slice(_position, state.position));
2821 }
2822
2823 if (ch !== 0) { readLineBreak(state); }
2824
2825 if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
2826 directiveHandlers[directiveName](state, directiveName, directiveArgs);
2827 } else {
2828 throwWarning(state, 'unknown document directive "' + directiveName + '"');
2829 }
2830 }
2831
2832 skipSeparationSpace(state, true, -1);
2833
2834 if (state.lineIndent === 0 &&
2835 state.input.charCodeAt(state.position) === 0x2D/* - */ &&
2836 state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
2837 state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
2838 state.position += 3;
2839 skipSeparationSpace(state, true, -1);
2840
2841 } else if (hasDirectives) {
2842 throwError(state, 'directives end mark is expected');
2843 }
2844
2845 composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
2846 skipSeparationSpace(state, true, -1);
2847
2848 if (state.checkLineBreaks &&
2849 PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
2850 throwWarning(state, 'non-ASCII line breaks are interpreted as content');
2851 }
2852
2853 state.documents.push(state.result);
2854
2855 if (state.position === state.lineStart && testDocumentSeparator(state)) {
2856
2857 if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
2858 state.position += 3;
2859 skipSeparationSpace(state, true, -1);
2860 }
2861 return;
2862 }
2863
2864 if (state.position < (state.length - 1)) {
2865 throwError(state, 'end of the stream or a document separator is expected');
2866 } else {
2867 return;
2868 }
2869}
2870
2871
2872function loadDocuments(input, options) {
2873 input = String(input);
2874 options = options || {};
2875
2876 if (input.length !== 0) {
2877
2878 // Add tailing `\n` if not exists
2879 if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ &&
2880 input.charCodeAt(input.length - 1) !== 0x0D/* CR */) {
2881 input += '\n';
2882 }
2883
2884 // Strip BOM
2885 if (input.charCodeAt(0) === 0xFEFF) {
2886 input = input.slice(1);
2887 }
2888 }
2889
2890 var state = new State(input, options);
2891
2892 // Use 0 as string terminator. That significantly simplifies bounds check.
2893 state.input += '\0';
2894
2895 while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
2896 state.lineIndent += 1;
2897 state.position += 1;
2898 }
2899
2900 while (state.position < (state.length - 1)) {
2901 readDocument(state);
2902 }
2903
2904 return state.documents;
2905}
2906
2907
2908function loadAll$1(input, iterator, options) {
2909 var documents = loadDocuments(input, options), index, length;
2910
2911 for (index = 0, length = documents.length; index < length; index += 1) {
2912 iterator(documents[index]);
2913 }
2914}
2915
2916
2917function load$1(input, options) {
2918 var documents = loadDocuments(input, options);
2919
2920 if (documents.length === 0) {
2921 /*eslint-disable no-undefined*/
2922 return undefined;
2923 } else if (documents.length === 1) {
2924 return documents[0];
2925 }
2926 throw new YAMLException$1('expected a single document in the stream, but found more');
2927}
2928
2929
2930function safeLoadAll$1(input, output, options) {
2931 loadAll$1(input, output, common.extend({ schema: DEFAULT_SAFE_SCHEMA$1 }, options));
2932}
2933
2934
2935function safeLoad$1(input, options) {
2936 return load$1(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA$1 }, options));
2937}
2938
2939
2940var loadAll_1 = loadAll$1;
2941var load_1 = load$1;
2942var safeLoadAll_1 = safeLoadAll$1;
2943var safeLoad_1 = safeLoad$1;
2944
2945var loader$1 = {
2946 loadAll: loadAll_1,
2947 load: load_1,
2948 safeLoadAll: safeLoadAll_1,
2949 safeLoad: safeLoad_1
2950};
2951
2952/*eslint-disable no-use-before-define*/
2953
2954var common$7 = common$1;
2955var YAMLException$5 = exception;
2956var DEFAULT_FULL_SCHEMA$2 = default_full;
2957var DEFAULT_SAFE_SCHEMA$2 = default_safe;
2958
2959var _toString$2 = Object.prototype.toString;
2960var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
2961
2962var CHAR_TAB = 0x09; /* Tab */
2963var CHAR_LINE_FEED = 0x0A; /* LF */
2964var CHAR_SPACE = 0x20; /* Space */
2965var CHAR_EXCLAMATION = 0x21; /* ! */
2966var CHAR_DOUBLE_QUOTE = 0x22; /* " */
2967var CHAR_SHARP = 0x23; /* # */
2968var CHAR_PERCENT = 0x25; /* % */
2969var CHAR_AMPERSAND = 0x26; /* & */
2970var CHAR_SINGLE_QUOTE = 0x27; /* ' */
2971var CHAR_ASTERISK = 0x2A; /* * */
2972var CHAR_COMMA = 0x2C; /* , */
2973var CHAR_MINUS = 0x2D; /* - */
2974var CHAR_COLON = 0x3A; /* : */
2975var CHAR_GREATER_THAN = 0x3E; /* > */
2976var CHAR_QUESTION = 0x3F; /* ? */
2977var CHAR_COMMERCIAL_AT = 0x40; /* @ */
2978var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
2979var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
2980var CHAR_GRAVE_ACCENT = 0x60; /* ` */
2981var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
2982var CHAR_VERTICAL_LINE = 0x7C; /* | */
2983var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
2984
2985var ESCAPE_SEQUENCES = {};
2986
2987ESCAPE_SEQUENCES[0x00] = '\\0';
2988ESCAPE_SEQUENCES[0x07] = '\\a';
2989ESCAPE_SEQUENCES[0x08] = '\\b';
2990ESCAPE_SEQUENCES[0x09] = '\\t';
2991ESCAPE_SEQUENCES[0x0A] = '\\n';
2992ESCAPE_SEQUENCES[0x0B] = '\\v';
2993ESCAPE_SEQUENCES[0x0C] = '\\f';
2994ESCAPE_SEQUENCES[0x0D] = '\\r';
2995ESCAPE_SEQUENCES[0x1B] = '\\e';
2996ESCAPE_SEQUENCES[0x22] = '\\"';
2997ESCAPE_SEQUENCES[0x5C] = '\\\\';
2998ESCAPE_SEQUENCES[0x85] = '\\N';
2999ESCAPE_SEQUENCES[0xA0] = '\\_';
3000ESCAPE_SEQUENCES[0x2028] = '\\L';
3001ESCAPE_SEQUENCES[0x2029] = '\\P';
3002
3003var DEPRECATED_BOOLEANS_SYNTAX = [
3004 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
3005 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
3006];
3007
3008function compileStyleMap(schema, map) {
3009 var result, keys, index, length, tag, style, type;
3010
3011 if (map === null) { return {}; }
3012
3013 result = {};
3014 keys = Object.keys(map);
3015
3016 for (index = 0, length = keys.length; index < length; index += 1) {
3017 tag = keys[index];
3018 style = String(map[tag]);
3019
3020 if (tag.slice(0, 2) === '!!') {
3021 tag = 'tag:yaml.org,2002:' + tag.slice(2);
3022 }
3023 type = schema.compiledTypeMap['fallback'][tag];
3024
3025 if (type && _hasOwnProperty$3.call(type.styleAliases, style)) {
3026 style = type.styleAliases[style];
3027 }
3028
3029 result[tag] = style;
3030 }
3031
3032 return result;
3033}
3034
3035function encodeHex(character) {
3036 var string, handle, length;
3037
3038 string = character.toString(16).toUpperCase();
3039
3040 if (character <= 0xFF) {
3041 handle = 'x';
3042 length = 2;
3043 } else if (character <= 0xFFFF) {
3044 handle = 'u';
3045 length = 4;
3046 } else if (character <= 0xFFFFFFFF) {
3047 handle = 'U';
3048 length = 8;
3049 } else {
3050 throw new YAMLException$5('code point within a string may not be greater than 0xFFFFFFFF');
3051 }
3052
3053 return '\\' + handle + common$7.repeat('0', length - string.length) + string;
3054}
3055
3056function State$1(options) {
3057 this.schema = options['schema'] || DEFAULT_FULL_SCHEMA$2;
3058 this.indent = Math.max(1, (options['indent'] || 2));
3059 this.skipInvalid = options['skipInvalid'] || false;
3060 this.flowLevel = (common$7.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
3061 this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
3062 this.sortKeys = options['sortKeys'] || false;
3063 this.lineWidth = options['lineWidth'] || 80;
3064 this.noRefs = options['noRefs'] || false;
3065 this.noCompatMode = options['noCompatMode'] || false;
3066
3067 this.implicitTypes = this.schema.compiledImplicit;
3068 this.explicitTypes = this.schema.compiledExplicit;
3069
3070 this.tag = null;
3071 this.result = '';
3072
3073 this.duplicates = [];
3074 this.usedDuplicates = null;
3075}
3076
3077// Indents every line in a string. Empty lines (\n only) are not indented.
3078function indentString(string, spaces) {
3079 var ind = common$7.repeat(' ', spaces),
3080 position = 0,
3081 next = -1,
3082 result = '',
3083 line,
3084 length = string.length;
3085
3086 while (position < length) {
3087 next = string.indexOf('\n', position);
3088 if (next === -1) {
3089 line = string.slice(position);
3090 position = length;
3091 } else {
3092 line = string.slice(position, next + 1);
3093 position = next + 1;
3094 }
3095
3096 if (line.length && line !== '\n') { result += ind; }
3097
3098 result += line;
3099 }
3100
3101 return result;
3102}
3103
3104function generateNextLine(state, level) {
3105 return '\n' + common$7.repeat(' ', state.indent * level);
3106}
3107
3108function testImplicitResolving(state, str) {
3109 var index, length, type;
3110
3111 for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
3112 type = state.implicitTypes[index];
3113
3114 if (type.resolve(str)) {
3115 return true;
3116 }
3117 }
3118
3119 return false;
3120}
3121
3122// [33] s-white ::= s-space | s-tab
3123function isWhitespace(c) {
3124 return c === CHAR_SPACE || c === CHAR_TAB;
3125}
3126
3127// Returns true if the character can be printed without escaping.
3128// From YAML 1.2: "any allowed characters known to be non-printable
3129// should also be escaped. [However,] This isn’t mandatory"
3130// Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
3131function isPrintable(c) {
3132 return (0x00020 <= c && c <= 0x00007E)
3133 || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
3134 || ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF /* BOM */)
3135 || (0x10000 <= c && c <= 0x10FFFF);
3136}
3137
3138// Simplified test for values allowed after the first character in plain style.
3139function isPlainSafe(c) {
3140 // Uses a subset of nb-char - c-flow-indicator - ":" - "#"
3141 // where nb-char ::= c-printable - b-char - c-byte-order-mark.
3142 return isPrintable(c) && c !== 0xFEFF
3143 // - c-flow-indicator
3144 && c !== CHAR_COMMA
3145 && c !== CHAR_LEFT_SQUARE_BRACKET
3146 && c !== CHAR_RIGHT_SQUARE_BRACKET
3147 && c !== CHAR_LEFT_CURLY_BRACKET
3148 && c !== CHAR_RIGHT_CURLY_BRACKET
3149 // - ":" - "#"
3150 && c !== CHAR_COLON
3151 && c !== CHAR_SHARP;
3152}
3153
3154// Simplified test for values allowed as the first character in plain style.
3155function isPlainSafeFirst(c) {
3156 // Uses a subset of ns-char - c-indicator
3157 // where ns-char = nb-char - s-white.
3158 return isPrintable(c) && c !== 0xFEFF
3159 && !isWhitespace(c) // - s-white
3160 // - (c-indicator ::=
3161 // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
3162 && c !== CHAR_MINUS
3163 && c !== CHAR_QUESTION
3164 && c !== CHAR_COLON
3165 && c !== CHAR_COMMA
3166 && c !== CHAR_LEFT_SQUARE_BRACKET
3167 && c !== CHAR_RIGHT_SQUARE_BRACKET
3168 && c !== CHAR_LEFT_CURLY_BRACKET
3169 && c !== CHAR_RIGHT_CURLY_BRACKET
3170 // | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
3171 && c !== CHAR_SHARP
3172 && c !== CHAR_AMPERSAND
3173 && c !== CHAR_ASTERISK
3174 && c !== CHAR_EXCLAMATION
3175 && c !== CHAR_VERTICAL_LINE
3176 && c !== CHAR_GREATER_THAN
3177 && c !== CHAR_SINGLE_QUOTE
3178 && c !== CHAR_DOUBLE_QUOTE
3179 // | “%” | “@” | “`”)
3180 && c !== CHAR_PERCENT
3181 && c !== CHAR_COMMERCIAL_AT
3182 && c !== CHAR_GRAVE_ACCENT;
3183}
3184
3185var STYLE_PLAIN = 1;
3186var STYLE_SINGLE = 2;
3187var STYLE_LITERAL = 3;
3188var STYLE_FOLDED = 4;
3189var STYLE_DOUBLE = 5;
3190
3191// Determines which scalar styles are possible and returns the preferred style.
3192// lineWidth = -1 => no limit.
3193// Pre-conditions: str.length > 0.
3194// Post-conditions:
3195// STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
3196// STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
3197// STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
3198function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
3199 var i;
3200 var char;
3201 var hasLineBreak = false;
3202 var hasFoldableLine = false; // only checked if shouldTrackWidth
3203 var shouldTrackWidth = lineWidth !== -1;
3204 var previousLineBreak = -1; // count the first line correctly
3205 var plain = isPlainSafeFirst(string.charCodeAt(0))
3206 && !isWhitespace(string.charCodeAt(string.length - 1));
3207
3208 if (singleLineOnly) {
3209 // Case: no block styles.
3210 // Check for disallowed characters to rule out plain and single.
3211 for (i = 0; i < string.length; i++) {
3212 char = string.charCodeAt(i);
3213 if (!isPrintable(char)) {
3214 return STYLE_DOUBLE;
3215 }
3216 plain = plain && isPlainSafe(char);
3217 }
3218 } else {
3219 // Case: block styles permitted.
3220 for (i = 0; i < string.length; i++) {
3221 char = string.charCodeAt(i);
3222 if (char === CHAR_LINE_FEED) {
3223 hasLineBreak = true;
3224 // Check if any line can be folded.
3225 if (shouldTrackWidth) {
3226 hasFoldableLine = hasFoldableLine ||
3227 // Foldable line = too long, and not more-indented.
3228 (i - previousLineBreak - 1 > lineWidth &&
3229 string[previousLineBreak + 1] !== ' ');
3230 previousLineBreak = i;
3231 }
3232 } else if (!isPrintable(char)) {
3233 return STYLE_DOUBLE;
3234 }
3235 plain = plain && isPlainSafe(char);
3236 }
3237 // in case the end is missing a \n
3238 hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
3239 (i - previousLineBreak - 1 > lineWidth &&
3240 string[previousLineBreak + 1] !== ' '));
3241 }
3242 // Although every style can represent \n without escaping, prefer block styles
3243 // for multiline, since they're more readable and they don't add empty lines.
3244 // Also prefer folding a super-long line.
3245 if (!hasLineBreak && !hasFoldableLine) {
3246 // Strings interpretable as another type have to be quoted;
3247 // e.g. the string 'true' vs. the boolean true.
3248 return plain && !testAmbiguousType(string)
3249 ? STYLE_PLAIN : STYLE_SINGLE;
3250 }
3251 // Edge case: block indentation indicator can only have one digit.
3252 if (string[0] === ' ' && indentPerLevel > 9) {
3253 return STYLE_DOUBLE;
3254 }
3255 // At this point we know block styles are valid.
3256 // Prefer literal style unless we want to fold.
3257 return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
3258}
3259
3260// Note: line breaking/folding is implemented for only the folded style.
3261// NB. We drop the last trailing newline (if any) of a returned block scalar
3262// since the dumper adds its own newline. This always works:
3263// • No ending newline => unaffected; already using strip "-" chomping.
3264// • Ending newline => removed then restored.
3265// Importantly, this keeps the "+" chomp indicator from gaining an extra line.
3266function writeScalar(state, string, level, iskey) {
3267 state.dump = (function () {
3268 if (string.length === 0) {
3269 return "''";
3270 }
3271 if (!state.noCompatMode &&
3272 DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
3273 return "'" + string + "'";
3274 }
3275
3276 var indent = state.indent * Math.max(1, level); // no 0-indent scalars
3277 // As indentation gets deeper, let the width decrease monotonically
3278 // to the lower bound min(state.lineWidth, 40).
3279 // Note that this implies
3280 // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
3281 // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
3282 // This behaves better than a constant minimum width which disallows narrower options,
3283 // or an indent threshold which causes the width to suddenly increase.
3284 var lineWidth = state.lineWidth === -1
3285 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
3286
3287 // Without knowing if keys are implicit/explicit, assume implicit for safety.
3288 var singleLineOnly = iskey
3289 // No block styles in flow mode.
3290 || (state.flowLevel > -1 && level >= state.flowLevel);
3291 function testAmbiguity(string) {
3292 return testImplicitResolving(state, string);
3293 }
3294
3295 switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
3296 case STYLE_PLAIN:
3297 return string;
3298 case STYLE_SINGLE:
3299 return "'" + string.replace(/'/g, "''") + "'";
3300 case STYLE_LITERAL:
3301 return '|' + blockHeader(string, state.indent)
3302 + dropEndingNewline(indentString(string, indent));
3303 case STYLE_FOLDED:
3304 return '>' + blockHeader(string, state.indent)
3305 + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
3306 case STYLE_DOUBLE:
3307 return '"' + escapeString(string, lineWidth) + '"';
3308 default:
3309 throw new YAMLException$5('impossible error: invalid scalar style');
3310 }
3311 }());
3312}
3313
3314// Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
3315function blockHeader(string, indentPerLevel) {
3316 var indentIndicator = (string[0] === ' ') ? String(indentPerLevel) : '';
3317
3318 // note the special case: the string '\n' counts as a "trailing" empty line.
3319 var clip = string[string.length - 1] === '\n';
3320 var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
3321 var chomp = keep ? '+' : (clip ? '' : '-');
3322
3323 return indentIndicator + chomp + '\n';
3324}
3325
3326// (See the note for writeScalar.)
3327function dropEndingNewline(string) {
3328 return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
3329}
3330
3331// Note: a long line without a suitable break point will exceed the width limit.
3332// Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
3333function foldString(string, width) {
3334 // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
3335 // unless they're before or after a more-indented line, or at the very
3336 // beginning or end, in which case $k$ maps to $k$.
3337 // Therefore, parse each chunk as newline(s) followed by a content line.
3338 var lineRe = /(\n+)([^\n]*)/g;
3339
3340 // first line (possibly an empty line)
3341 var result = (function () {
3342 var nextLF = string.indexOf('\n');
3343 nextLF = nextLF !== -1 ? nextLF : string.length;
3344 lineRe.lastIndex = nextLF;
3345 return foldLine(string.slice(0, nextLF), width);
3346 }());
3347 // If we haven't reached the first content line yet, don't add an extra \n.
3348 var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
3349 var moreIndented;
3350
3351 // rest of the lines
3352 var match;
3353 while ((match = lineRe.exec(string))) {
3354 var prefix = match[1], line = match[2];
3355 moreIndented = (line[0] === ' ');
3356 result += prefix
3357 + (!prevMoreIndented && !moreIndented && line !== ''
3358 ? '\n' : '')
3359 + foldLine(line, width);
3360 prevMoreIndented = moreIndented;
3361 }
3362
3363 return result;
3364}
3365
3366// Greedy line breaking.
3367// Picks the longest line under the limit each time,
3368// otherwise settles for the shortest line over the limit.
3369// NB. More-indented lines *cannot* be folded, as that would add an extra \n.
3370function foldLine(line, width) {
3371 if (line === '' || line[0] === ' ') { return line; }
3372
3373 // Since a more-indented line adds a \n, breaks can't be followed by a space.
3374 var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
3375 var match;
3376 // start is an inclusive index. end, curr, and next are exclusive.
3377 var start = 0, end, curr = 0, next = 0;
3378 var result = '';
3379
3380 // Invariants: 0 <= start <= length-1.
3381 // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
3382 // Inside the loop:
3383 // A match implies length >= 2, so curr and next are <= length-2.
3384 while ((match = breakRe.exec(line))) {
3385 next = match.index;
3386 // maintain invariant: curr - start <= width
3387 if (next - start > width) {
3388 end = (curr > start) ? curr : next; // derive end <= length-2
3389 result += '\n' + line.slice(start, end);
3390 // skip the space that was output as \n
3391 start = end + 1; // derive start <= length-1
3392 }
3393 curr = next;
3394 }
3395
3396 // By the invariants, start <= length-1, so there is something left over.
3397 // It is either the whole string or a part starting from non-whitespace.
3398 result += '\n';
3399 // Insert a break if the remainder is too long and there is a break available.
3400 if (line.length - start > width && curr > start) {
3401 result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
3402 } else {
3403 result += line.slice(start);
3404 }
3405
3406 return result.slice(1); // drop extra \n joiner
3407}
3408
3409// Escapes a double-quoted string.
3410function escapeString(string) {
3411 var result = '';
3412 var char;
3413 var escapeSeq;
3414
3415 for (var i = 0; i < string.length; i++) {
3416 char = string.charCodeAt(i);
3417 escapeSeq = ESCAPE_SEQUENCES[char];
3418 result += !escapeSeq && isPrintable(char)
3419 ? string[i]
3420 : escapeSeq || encodeHex(char);
3421 }
3422
3423 return result;
3424}
3425
3426function writeFlowSequence(state, level, object) {
3427 var _result = '',
3428 _tag = state.tag,
3429 index,
3430 length;
3431
3432 for (index = 0, length = object.length; index < length; index += 1) {
3433 // Write only valid elements.
3434 if (writeNode(state, level, object[index], false, false)) {
3435 if (index !== 0) { _result += ', '; }
3436 _result += state.dump;
3437 }
3438 }
3439
3440 state.tag = _tag;
3441 state.dump = '[' + _result + ']';
3442}
3443
3444function writeBlockSequence(state, level, object, compact) {
3445 var _result = '',
3446 _tag = state.tag,
3447 index,
3448 length;
3449
3450 for (index = 0, length = object.length; index < length; index += 1) {
3451 // Write only valid elements.
3452 if (writeNode(state, level + 1, object[index], true, true)) {
3453 if (!compact || index !== 0) {
3454 _result += generateNextLine(state, level);
3455 }
3456 _result += '- ' + state.dump;
3457 }
3458 }
3459
3460 state.tag = _tag;
3461 state.dump = _result || '[]'; // Empty sequence if no valid values.
3462}
3463
3464function writeFlowMapping(state, level, object) {
3465 var _result = '',
3466 _tag = state.tag,
3467 objectKeyList = Object.keys(object),
3468 index,
3469 length,
3470 objectKey,
3471 objectValue,
3472 pairBuffer;
3473
3474 for (index = 0, length = objectKeyList.length; index < length; index += 1) {
3475 pairBuffer = '';
3476
3477 if (index !== 0) { pairBuffer += ', '; }
3478
3479 objectKey = objectKeyList[index];
3480 objectValue = object[objectKey];
3481
3482 if (!writeNode(state, level, objectKey, false, false)) {
3483 continue; // Skip this pair because of invalid key;
3484 }
3485
3486 if (state.dump.length > 1024) { pairBuffer += '? '; }
3487
3488 pairBuffer += state.dump + ': ';
3489
3490 if (!writeNode(state, level, objectValue, false, false)) {
3491 continue; // Skip this pair because of invalid value.
3492 }
3493
3494 pairBuffer += state.dump;
3495
3496 // Both key and value are valid.
3497 _result += pairBuffer;
3498 }
3499
3500 state.tag = _tag;
3501 state.dump = '{' + _result + '}';
3502}
3503
3504function writeBlockMapping(state, level, object, compact) {
3505 var _result = '',
3506 _tag = state.tag,
3507 objectKeyList = Object.keys(object),
3508 index,
3509 length,
3510 objectKey,
3511 objectValue,
3512 explicitPair,
3513 pairBuffer;
3514
3515 // Allow sorting keys so that the output file is deterministic
3516 if (state.sortKeys === true) {
3517 // Default sorting
3518 objectKeyList.sort();
3519 } else if (typeof state.sortKeys === 'function') {
3520 // Custom sort function
3521 objectKeyList.sort(state.sortKeys);
3522 } else if (state.sortKeys) {
3523 // Something is wrong
3524 throw new YAMLException$5('sortKeys must be a boolean or a function');
3525 }
3526
3527 for (index = 0, length = objectKeyList.length; index < length; index += 1) {
3528 pairBuffer = '';
3529
3530 if (!compact || index !== 0) {
3531 pairBuffer += generateNextLine(state, level);
3532 }
3533
3534 objectKey = objectKeyList[index];
3535 objectValue = object[objectKey];
3536
3537 if (!writeNode(state, level + 1, objectKey, true, true, true)) {
3538 continue; // Skip this pair because of invalid key.
3539 }
3540
3541 explicitPair = (state.tag !== null && state.tag !== '?') ||
3542 (state.dump && state.dump.length > 1024);
3543
3544 if (explicitPair) {
3545 if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
3546 pairBuffer += '?';
3547 } else {
3548 pairBuffer += '? ';
3549 }
3550 }
3551
3552 pairBuffer += state.dump;
3553
3554 if (explicitPair) {
3555 pairBuffer += generateNextLine(state, level);
3556 }
3557
3558 if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
3559 continue; // Skip this pair because of invalid value.
3560 }
3561
3562 if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
3563 pairBuffer += ':';
3564 } else {
3565 pairBuffer += ': ';
3566 }
3567
3568 pairBuffer += state.dump;
3569
3570 // Both key and value are valid.
3571 _result += pairBuffer;
3572 }
3573
3574 state.tag = _tag;
3575 state.dump = _result || '{}'; // Empty mapping if no valid pairs.
3576}
3577
3578function detectType(state, object, explicit) {
3579 var _result, typeList, index, length, type, style;
3580
3581 typeList = explicit ? state.explicitTypes : state.implicitTypes;
3582
3583 for (index = 0, length = typeList.length; index < length; index += 1) {
3584 type = typeList[index];
3585
3586 if ((type.instanceOf || type.predicate) &&
3587 (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
3588 (!type.predicate || type.predicate(object))) {
3589
3590 state.tag = explicit ? type.tag : '?';
3591
3592 if (type.represent) {
3593 style = state.styleMap[type.tag] || type.defaultStyle;
3594
3595 if (_toString$2.call(type.represent) === '[object Function]') {
3596 _result = type.represent(object, style);
3597 } else if (_hasOwnProperty$3.call(type.represent, style)) {
3598 _result = type.represent[style](object, style);
3599 } else {
3600 throw new YAMLException$5('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
3601 }
3602
3603 state.dump = _result;
3604 }
3605
3606 return true;
3607 }
3608 }
3609
3610 return false;
3611}
3612
3613// Serializes `object` and writes it to global `result`.
3614// Returns true on success, or false on invalid object.
3615//
3616function writeNode(state, level, object, block, compact, iskey) {
3617 state.tag = null;
3618 state.dump = object;
3619
3620 if (!detectType(state, object, false)) {
3621 detectType(state, object, true);
3622 }
3623
3624 var type = _toString$2.call(state.dump);
3625
3626 if (block) {
3627 block = (state.flowLevel < 0 || state.flowLevel > level);
3628 }
3629
3630 var objectOrArray = type === '[object Object]' || type === '[object Array]',
3631 duplicateIndex,
3632 duplicate;
3633
3634 if (objectOrArray) {
3635 duplicateIndex = state.duplicates.indexOf(object);
3636 duplicate = duplicateIndex !== -1;
3637 }
3638
3639 if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
3640 compact = false;
3641 }
3642
3643 if (duplicate && state.usedDuplicates[duplicateIndex]) {
3644 state.dump = '*ref_' + duplicateIndex;
3645 } else {
3646 if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
3647 state.usedDuplicates[duplicateIndex] = true;
3648 }
3649 if (type === '[object Object]') {
3650 if (block && (Object.keys(state.dump).length !== 0)) {
3651 writeBlockMapping(state, level, state.dump, compact);
3652 if (duplicate) {
3653 state.dump = '&ref_' + duplicateIndex + state.dump;
3654 }
3655 } else {
3656 writeFlowMapping(state, level, state.dump);
3657 if (duplicate) {
3658 state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
3659 }
3660 }
3661 } else if (type === '[object Array]') {
3662 if (block && (state.dump.length !== 0)) {
3663 writeBlockSequence(state, level, state.dump, compact);
3664 if (duplicate) {
3665 state.dump = '&ref_' + duplicateIndex + state.dump;
3666 }
3667 } else {
3668 writeFlowSequence(state, level, state.dump);
3669 if (duplicate) {
3670 state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
3671 }
3672 }
3673 } else if (type === '[object String]') {
3674 if (state.tag !== '?') {
3675 writeScalar(state, state.dump, level, iskey);
3676 }
3677 } else {
3678 if (state.skipInvalid) { return false; }
3679 throw new YAMLException$5('unacceptable kind of an object to dump ' + type);
3680 }
3681
3682 if (state.tag !== null && state.tag !== '?') {
3683 state.dump = '!<' + state.tag + '> ' + state.dump;
3684 }
3685 }
3686
3687 return true;
3688}
3689
3690function getDuplicateReferences(object, state) {
3691 var objects = [],
3692 duplicatesIndexes = [],
3693 index,
3694 length;
3695
3696 inspectNode(object, objects, duplicatesIndexes);
3697
3698 for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
3699 state.duplicates.push(objects[duplicatesIndexes[index]]);
3700 }
3701 state.usedDuplicates = new Array(length);
3702}
3703
3704function inspectNode(object, objects, duplicatesIndexes) {
3705 var objectKeyList,
3706 index,
3707 length;
3708
3709 if (object !== null && typeof object === 'object') {
3710 index = objects.indexOf(object);
3711 if (index !== -1) {
3712 if (duplicatesIndexes.indexOf(index) === -1) {
3713 duplicatesIndexes.push(index);
3714 }
3715 } else {
3716 objects.push(object);
3717
3718 if (Array.isArray(object)) {
3719 for (index = 0, length = object.length; index < length; index += 1) {
3720 inspectNode(object[index], objects, duplicatesIndexes);
3721 }
3722 } else {
3723 objectKeyList = Object.keys(object);
3724
3725 for (index = 0, length = objectKeyList.length; index < length; index += 1) {
3726 inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
3727 }
3728 }
3729 }
3730 }
3731}
3732
3733function dump$1(input, options) {
3734 options = options || {};
3735
3736 var state = new State$1(options);
3737
3738 if (!state.noRefs) { getDuplicateReferences(input, state); }
3739
3740 if (writeNode(state, 0, input, true, true)) { return state.dump + '\n'; }
3741
3742 return '';
3743}
3744
3745function safeDump$1(input, options) {
3746 return dump$1(input, common$7.extend({ schema: DEFAULT_SAFE_SCHEMA$2 }, options));
3747}
3748
3749var dump_1 = dump$1;
3750var safeDump_1 = safeDump$1;
3751
3752var dumper$1 = {
3753 dump: dump_1,
3754 safeDump: safeDump_1
3755};
3756
3757var loader = loader$1;
3758var dumper = dumper$1;
3759
3760
3761function deprecated(name) {
3762 return function () {
3763 throw new Error('Function ' + name + ' is deprecated and cannot be used.');
3764 };
3765}
3766
3767
3768var Type = type;
3769var Schema = schema;
3770var FAILSAFE_SCHEMA = failsafe;
3771var JSON_SCHEMA = json;
3772var CORE_SCHEMA = core;
3773var DEFAULT_SAFE_SCHEMA = default_safe;
3774var DEFAULT_FULL_SCHEMA = default_full;
3775var load = loader.load;
3776var loadAll = loader.loadAll;
3777var safeLoad = loader.safeLoad;
3778var safeLoadAll = loader.safeLoadAll;
3779var dump = dumper.dump;
3780var safeDump = dumper.safeDump;
3781var YAMLException = exception;
3782
3783// Deprecated schema names from JS-YAML 2.0.x
3784var MINIMAL_SCHEMA = failsafe;
3785var SAFE_SCHEMA = default_safe;
3786var DEFAULT_SCHEMA = default_full;
3787
3788// Deprecated functions from JS-YAML 1.x.x
3789var scan$1 = deprecated('scan');
3790var parse$1 = deprecated('parse');
3791var compose = deprecated('compose');
3792var addConstructor = deprecated('addConstructor');
3793
3794var jsYaml = {
3795 Type: Type,
3796 Schema: Schema,
3797 FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
3798 JSON_SCHEMA: JSON_SCHEMA,
3799 CORE_SCHEMA: CORE_SCHEMA,
3800 DEFAULT_SAFE_SCHEMA: DEFAULT_SAFE_SCHEMA,
3801 DEFAULT_FULL_SCHEMA: DEFAULT_FULL_SCHEMA,
3802 load: load,
3803 loadAll: loadAll,
3804 safeLoad: safeLoad,
3805 safeLoadAll: safeLoadAll,
3806 dump: dump,
3807 safeDump: safeDump,
3808 YAMLException: YAMLException,
3809 MINIMAL_SCHEMA: MINIMAL_SCHEMA,
3810 SAFE_SCHEMA: SAFE_SCHEMA,
3811 DEFAULT_SCHEMA: DEFAULT_SCHEMA,
3812 scan: scan$1,
3813 parse: parse$1,
3814 compose: compose,
3815 addConstructor: addConstructor
3816};
3817
3818var yaml = jsYaml;
3819
3820
3821var index = yaml;
3822
3823var frontMatter = function(dom, data) {
3824 var localData = {};
3825 var el = dom.querySelector('script[type="text/front-matter"]');
3826 if (el) {
3827 var text = el.textContent;
3828 localData = index.safeLoad(text);
3829 }
3830
3831 data.title = localData.title ? localData.title : "Untitled";
3832 data.description = localData.description ? localData.description : "No description.";
3833
3834 data.authors = localData.authors ? localData.authors : [];
3835
3836 data.authors = data.authors.map(function (author, i) {
3837 var a = {};
3838 var name = Object.keys(author)[0];
3839 if ((typeof author) === "string") {
3840 name = author;
3841 } else {
3842 a.personalURL = author[name];
3843 }
3844 var names = name.split(" ");
3845 a.name = name;
3846 a.firstName = names.slice(0, names.length - 1).join(" ");
3847 a.lastName = names[names.length -1];
3848 if(localData.affiliations[i]) {
3849 var affiliation = Object.keys(localData.affiliations[i])[0];
3850 if ((typeof localData.affiliations[i]) === "string") {
3851 affiliation = localData.affiliations[i];
3852 } else {
3853 a.affiliationURL = localData.affiliations[i][affiliation];
3854 }
3855 a.affiliation = affiliation;
3856 }
3857 return a;
3858 });
3859
3860
3861};
3862
3863var bibtexParse = createCommonjsModule(function (module, exports) {
3864/* start bibtexParse 0.0.22 */
3865
3866//Original work by Henrik Muehe (c) 2010
3867//
3868//CommonJS port by Mikola Lysenko 2013
3869//
3870//Port to Browser lib by ORCID / RCPETERS
3871//
3872//Issues:
3873//no comment handling within strings
3874//no string concatenation
3875//no variable values yet
3876//Grammar implemented here:
3877//bibtex -> (string | preamble | comment | entry)*;
3878//string -> '@STRING' '{' key_equals_value '}';
3879//preamble -> '@PREAMBLE' '{' value '}';
3880//comment -> '@COMMENT' '{' value '}';
3881//entry -> '@' key '{' key ',' key_value_list '}';
3882//key_value_list -> key_equals_value (',' key_equals_value)*;
3883//key_equals_value -> key '=' value;
3884//value -> value_quotes | value_braces | key;
3885//value_quotes -> '"' .*? '"'; // not quite
3886//value_braces -> '{' .*? '"'; // not quite
3887(function(exports) {
3888
3889 function BibtexParser() {
3890
3891 this.months = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
3892 this.notKey = [',','{','}',' ','='];
3893 this.pos = 0;
3894 this.input = "";
3895 this.entries = new Array();
3896
3897 this.currentEntry = "";
3898
3899 this.setInput = function(t) {
3900 this.input = t;
3901 };
3902
3903 this.getEntries = function() {
3904 return this.entries;
3905 };
3906
3907 this.isWhitespace = function(s) {
3908 return (s == ' ' || s == '\r' || s == '\t' || s == '\n');
3909 };
3910
3911 this.match = function(s, canCommentOut) {
3912 if (canCommentOut == undefined || canCommentOut == null)
3913 { canCommentOut = true; }
3914 this.skipWhitespace(canCommentOut);
3915 if (this.input.substring(this.pos, this.pos + s.length) == s) {
3916 this.pos += s.length;
3917 } else {
3918 throw "Token mismatch, expected " + s + ", found "
3919 + this.input.substring(this.pos);
3920 }
3921 this.skipWhitespace(canCommentOut);
3922 };
3923
3924 this.tryMatch = function(s, canCommentOut) {
3925 if (canCommentOut == undefined || canCommentOut == null)
3926 { canCommentOut = true; }
3927 this.skipWhitespace(canCommentOut);
3928 if (this.input.substring(this.pos, this.pos + s.length) == s) {
3929 return true;
3930 } else {
3931 return false;
3932 }
3933 this.skipWhitespace(canCommentOut);
3934 };
3935
3936 /* when search for a match all text can be ignored, not just white space */
3937 this.matchAt = function() {
3938 var this$1 = this;
3939
3940 while (this.input.length > this.pos && this.input[this.pos] != '@') {
3941 this$1.pos++;
3942 }
3943
3944 if (this.input[this.pos] == '@') {
3945 return true;
3946 }
3947 return false;
3948 };
3949
3950 this.skipWhitespace = function(canCommentOut) {
3951 var this$1 = this;
3952
3953 while (this.isWhitespace(this.input[this.pos])) {
3954 this$1.pos++;
3955 }
3956 if (this.input[this.pos] == "%" && canCommentOut == true) {
3957 while (this.input[this.pos] != "\n") {
3958 this$1.pos++;
3959 }
3960 this.skipWhitespace(canCommentOut);
3961 }
3962 };
3963
3964 this.value_braces = function() {
3965 var this$1 = this;
3966
3967 var bracecount = 0;
3968 this.match("{", false);
3969 var start = this.pos;
3970 var escaped = false;
3971 while (true) {
3972 if (!escaped) {
3973 if (this$1.input[this$1.pos] == '}') {
3974 if (bracecount > 0) {
3975 bracecount--;
3976 } else {
3977 var end = this$1.pos;
3978 this$1.match("}", false);
3979 return this$1.input.substring(start, end);
3980 }
3981 } else if (this$1.input[this$1.pos] == '{') {
3982 bracecount++;
3983 } else if (this$1.pos >= this$1.input.length - 1) {
3984 throw "Unterminated value";
3985 }
3986 }
3987 if (this$1.input[this$1.pos] == '\\' && escaped == false)
3988 { escaped = true; }
3989 else
3990 { escaped = false; }
3991 this$1.pos++;
3992 }
3993 };
3994
3995 this.value_comment = function() {
3996 var this$1 = this;
3997
3998 var str = '';
3999 var brcktCnt = 0;
4000 while (!(this.tryMatch("}", false) && brcktCnt == 0)) {
4001 str = str + this$1.input[this$1.pos];
4002 if (this$1.input[this$1.pos] == '{')
4003 { brcktCnt++; }
4004 if (this$1.input[this$1.pos] == '}')
4005 { brcktCnt--; }
4006 if (this$1.pos >= this$1.input.length - 1) {
4007 throw "Unterminated value:" + this$1.input.substring(start);
4008 }
4009 this$1.pos++;
4010 }
4011 return str;
4012 };
4013
4014 this.value_quotes = function() {
4015 var this$1 = this;
4016
4017 this.match('"', false);
4018 var start = this.pos;
4019 var escaped = false;
4020 while (true) {
4021 if (!escaped) {
4022 if (this$1.input[this$1.pos] == '"') {
4023 var end = this$1.pos;
4024 this$1.match('"', false);
4025 return this$1.input.substring(start, end);
4026 } else if (this$1.pos >= this$1.input.length - 1) {
4027 throw "Unterminated value:" + this$1.input.substring(start);
4028 }
4029 }
4030 if (this$1.input[this$1.pos] == '\\' && escaped == false)
4031 { escaped = true; }
4032 else
4033 { escaped = false; }
4034 this$1.pos++;
4035 }
4036 };
4037
4038 this.single_value = function() {
4039 var start = this.pos;
4040 if (this.tryMatch("{")) {
4041 return this.value_braces();
4042 } else if (this.tryMatch('"')) {
4043 return this.value_quotes();
4044 } else {
4045 var k = this.key();
4046 if (k.match("^[0-9]+$"))
4047 { return k; }
4048 else if (this.months.indexOf(k.toLowerCase()) >= 0)
4049 { return k.toLowerCase(); }
4050 else
4051 { throw "Value expected:" + this.input.substring(start) + ' for key: ' + k; }
4052
4053 }
4054 };
4055
4056 this.value = function() {
4057 var this$1 = this;
4058
4059 var values = [];
4060 values.push(this.single_value());
4061 while (this.tryMatch("#")) {
4062 this$1.match("#");
4063 values.push(this$1.single_value());
4064 }
4065 return values.join("");
4066 };
4067
4068 this.key = function() {
4069 var this$1 = this;
4070
4071 var start = this.pos;
4072 while (true) {
4073 if (this$1.pos >= this$1.input.length) {
4074 throw "Runaway key";
4075 }
4076 // а-яА-Я is Cyrillic
4077 //console.log(this.input[this.pos]);
4078 if (this$1.notKey.indexOf(this$1.input[this$1.pos]) >= 0) {
4079 return this$1.input.substring(start, this$1.pos);
4080 } else {
4081 this$1.pos++;
4082
4083 }
4084 }
4085 };
4086
4087 this.key_equals_value = function() {
4088 var key = this.key();
4089 if (this.tryMatch("=")) {
4090 this.match("=");
4091 var val = this.value();
4092 return [ key, val ];
4093 } else {
4094 throw "... = value expected, equals sign missing:"
4095 + this.input.substring(this.pos);
4096 }
4097 };
4098
4099 this.key_value_list = function() {
4100 var this$1 = this;
4101
4102 var kv = this.key_equals_value();
4103 this.currentEntry['entryTags'] = {};
4104 this.currentEntry['entryTags'][kv[0]] = kv[1];
4105 while (this.tryMatch(",")) {
4106 this$1.match(",");
4107 // fixes problems with commas at the end of a list
4108 if (this$1.tryMatch("}")) {
4109 break;
4110 }
4111
4112 kv = this$1.key_equals_value();
4113 this$1.currentEntry['entryTags'][kv[0]] = kv[1];
4114 }
4115 };
4116
4117 this.entry_body = function(d) {
4118 this.currentEntry = {};
4119 this.currentEntry['citationKey'] = this.key();
4120 this.currentEntry['entryType'] = d.substring(1);
4121 this.match(",");
4122 this.key_value_list();
4123 this.entries.push(this.currentEntry);
4124 };
4125
4126 this.directive = function() {
4127 this.match("@");
4128 return "@" + this.key();
4129 };
4130
4131 this.preamble = function() {
4132 this.currentEntry = {};
4133 this.currentEntry['entryType'] = 'PREAMBLE';
4134 this.currentEntry['entry'] = this.value_comment();
4135 this.entries.push(this.currentEntry);
4136 };
4137
4138 this.comment = function() {
4139 this.currentEntry = {};
4140 this.currentEntry['entryType'] = 'COMMENT';
4141 this.currentEntry['entry'] = this.value_comment();
4142 this.entries.push(this.currentEntry);
4143 };
4144
4145 this.entry = function(d) {
4146 this.entry_body(d);
4147 };
4148
4149 this.bibtex = function() {
4150 var this$1 = this;
4151
4152 while (this.matchAt()) {
4153 var d = this$1.directive();
4154 this$1.match("{");
4155 if (d == "@STRING") {
4156 this$1.string();
4157 } else if (d == "@PREAMBLE") {
4158 this$1.preamble();
4159 } else if (d == "@COMMENT") {
4160 this$1.comment();
4161 } else {
4162 this$1.entry(d);
4163 }
4164 this$1.match("}");
4165 }
4166 };
4167 }
4168
4169 exports.toJSON = function(bibtex) {
4170 var b = new BibtexParser();
4171 b.setInput(bibtex);
4172 b.bibtex();
4173 return b.entries;
4174 };
4175
4176 /* added during hackathon don't hate on me */
4177 exports.toBibtex = function(json) {
4178 var out = '';
4179 for ( var i in json) {
4180 out += "@" + json[i].entryType;
4181 out += '{';
4182 if (json[i].citationKey)
4183 { out += json[i].citationKey + ', '; }
4184 if (json[i].entry)
4185 { out += json[i].entry ; }
4186 if (json[i].entryTags) {
4187 var tags = '';
4188 for (var jdx in json[i].entryTags) {
4189 if (tags.length != 0)
4190 { tags += ', '; }
4191 tags += jdx + '= {' + json[i].entryTags[jdx] + '}';
4192 }
4193 out += tags;
4194 }
4195 out += '}\n\n';
4196 }
4197 return out;
4198
4199 };
4200
4201})(exports);
4202
4203/* end bibtexParse */
4204});
4205
4206var bibliography = function(dom, data) {
4207 var el = dom.querySelector('script[type="text/bibliography"]');
4208 var citations = [];
4209 var bibliography = {};
4210 //TODO If we don't have a local element, make a request for the document.
4211 if (el) {
4212 var rawBib = el.textContent;
4213 var parsed = bibtexParse.toJSON(rawBib);
4214 if(parsed) {
4215 parsed.forEach(function (e) {
4216 for (var k in e.entryTags){
4217 var val = e.entryTags[k];
4218 val = val.replace(/[\t\n ]+/g, " ");
4219 val = val.replace(/{\\["^`\.'acu~Hvs]( )?([a-zA-Z])}/g,
4220 function (full, x, char) { return char; });
4221 val = val.replace(/{\\([a-zA-Z])}/g,
4222 function (full, char) { return char; });
4223 e.entryTags[k] = val;
4224 }
4225 bibliography[e.citationKey] = e.entryTags;
4226 bibliography[e.citationKey].type = e.entryType;
4227 });
4228 }
4229
4230
4231 var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
4232 citeTags.forEach(function (el) {
4233 var key = el.getAttribute("key");
4234 if (key) {
4235 var citationKeys = key.split(",");
4236 citationKeys.forEach(function (key) {
4237 if (citations.indexOf(key) == -1){
4238 citations.push(key);
4239 if (!(key in bibliography)){
4240 console.warn("No bibliography entry found for: " + key);
4241 }
4242 }
4243 });
4244 }
4245 });
4246 }
4247 data.bibliography = bibliography;
4248 data.citations = citations;
4249};
4250
4251var t0 = new Date;
4252var t1 = new Date;
4253
4254function newInterval(floori, offseti, count, field) {
4255
4256 function interval(date) {
4257 return floori(date = new Date(+date)), date;
4258 }
4259
4260 interval.floor = interval;
4261
4262 interval.ceil = function(date) {
4263 return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
4264 };
4265
4266 interval.round = function(date) {
4267 var d0 = interval(date),
4268 d1 = interval.ceil(date);
4269 return date - d0 < d1 - date ? d0 : d1;
4270 };
4271
4272 interval.offset = function(date, step) {
4273 return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
4274 };
4275
4276 interval.range = function(start, stop, step) {
4277 var range = [];
4278 start = interval.ceil(start);
4279 step = step == null ? 1 : Math.floor(step);
4280 if (!(start < stop) || !(step > 0)) { return range; } // also handles Invalid Date
4281 do { range.push(new Date(+start)); } while (offseti(start, step), floori(start), start < stop)
4282 return range;
4283 };
4284
4285 interval.filter = function(test) {
4286 return newInterval(function(date) {
4287 if (date >= date) { while (floori(date), !test(date)) { date.setTime(date - 1); } }
4288 }, function(date, step) {
4289 if (date >= date) { while (--step >= 0) { while (offseti(date, 1), !test(date)) {} } } // eslint-disable-line no-empty
4290 });
4291 };
4292
4293 if (count) {
4294 interval.count = function(start, end) {
4295 t0.setTime(+start), t1.setTime(+end);
4296 floori(t0), floori(t1);
4297 return Math.floor(count(t0, t1));
4298 };
4299
4300 interval.every = function(step) {
4301 step = Math.floor(step);
4302 return !isFinite(step) || !(step > 0) ? null
4303 : !(step > 1) ? interval
4304 : interval.filter(field
4305 ? function(d) { return field(d) % step === 0; }
4306 : function(d) { return interval.count(0, d) % step === 0; });
4307 };
4308 }
4309
4310 return interval;
4311}
4312
4313var millisecond = newInterval(function() {
4314 // noop
4315}, function(date, step) {
4316 date.setTime(+date + step);
4317}, function(start, end) {
4318 return end - start;
4319});
4320
4321// An optimized implementation for this simple case.
4322millisecond.every = function(k) {
4323 k = Math.floor(k);
4324 if (!isFinite(k) || !(k > 0)) { return null; }
4325 if (!(k > 1)) { return millisecond; }
4326 return newInterval(function(date) {
4327 date.setTime(Math.floor(date / k) * k);
4328 }, function(date, step) {
4329 date.setTime(+date + step * k);
4330 }, function(start, end) {
4331 return (end - start) / k;
4332 });
4333};
4334
4335var durationSecond = 1e3;
4336var durationMinute = 6e4;
4337var durationHour = 36e5;
4338var durationDay = 864e5;
4339var durationWeek = 6048e5;
4340
4341var second = newInterval(function(date) {
4342 date.setTime(Math.floor(date / durationSecond) * durationSecond);
4343}, function(date, step) {
4344 date.setTime(+date + step * durationSecond);
4345}, function(start, end) {
4346 return (end - start) / durationSecond;
4347}, function(date) {
4348 return date.getUTCSeconds();
4349});
4350
4351var minute = newInterval(function(date) {
4352 date.setTime(Math.floor(date / durationMinute) * durationMinute);
4353}, function(date, step) {
4354 date.setTime(+date + step * durationMinute);
4355}, function(start, end) {
4356 return (end - start) / durationMinute;
4357}, function(date) {
4358 return date.getMinutes();
4359});
4360
4361var hour = newInterval(function(date) {
4362 var offset = date.getTimezoneOffset() * durationMinute % durationHour;
4363 if (offset < 0) { offset += durationHour; }
4364 date.setTime(Math.floor((+date - offset) / durationHour) * durationHour + offset);
4365}, function(date, step) {
4366 date.setTime(+date + step * durationHour);
4367}, function(start, end) {
4368 return (end - start) / durationHour;
4369}, function(date) {
4370 return date.getHours();
4371});
4372
4373var day = newInterval(function(date) {
4374 date.setHours(0, 0, 0, 0);
4375}, function(date, step) {
4376 date.setDate(date.getDate() + step);
4377}, function(start, end) {
4378 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationDay;
4379}, function(date) {
4380 return date.getDate() - 1;
4381});
4382
4383function weekday(i) {
4384 return newInterval(function(date) {
4385 date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
4386 date.setHours(0, 0, 0, 0);
4387 }, function(date, step) {
4388 date.setDate(date.getDate() + step * 7);
4389 }, function(start, end) {
4390 return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * durationMinute) / durationWeek;
4391 });
4392}
4393
4394var sunday = weekday(0);
4395var monday = weekday(1);
4396var tuesday = weekday(2);
4397var wednesday = weekday(3);
4398var thursday = weekday(4);
4399var friday = weekday(5);
4400var saturday = weekday(6);
4401
4402var month = newInterval(function(date) {
4403 date.setDate(1);
4404 date.setHours(0, 0, 0, 0);
4405}, function(date, step) {
4406 date.setMonth(date.getMonth() + step);
4407}, function(start, end) {
4408 return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
4409}, function(date) {
4410 return date.getMonth();
4411});
4412
4413var year = newInterval(function(date) {
4414 date.setMonth(0, 1);
4415 date.setHours(0, 0, 0, 0);
4416}, function(date, step) {
4417 date.setFullYear(date.getFullYear() + step);
4418}, function(start, end) {
4419 return end.getFullYear() - start.getFullYear();
4420}, function(date) {
4421 return date.getFullYear();
4422});
4423
4424// An optimized implementation for this simple case.
4425year.every = function(k) {
4426 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
4427 date.setFullYear(Math.floor(date.getFullYear() / k) * k);
4428 date.setMonth(0, 1);
4429 date.setHours(0, 0, 0, 0);
4430 }, function(date, step) {
4431 date.setFullYear(date.getFullYear() + step * k);
4432 });
4433};
4434
4435var utcMinute = newInterval(function(date) {
4436 date.setUTCSeconds(0, 0);
4437}, function(date, step) {
4438 date.setTime(+date + step * durationMinute);
4439}, function(start, end) {
4440 return (end - start) / durationMinute;
4441}, function(date) {
4442 return date.getUTCMinutes();
4443});
4444
4445var utcHour = newInterval(function(date) {
4446 date.setUTCMinutes(0, 0, 0);
4447}, function(date, step) {
4448 date.setTime(+date + step * durationHour);
4449}, function(start, end) {
4450 return (end - start) / durationHour;
4451}, function(date) {
4452 return date.getUTCHours();
4453});
4454
4455var utcDay = newInterval(function(date) {
4456 date.setUTCHours(0, 0, 0, 0);
4457}, function(date, step) {
4458 date.setUTCDate(date.getUTCDate() + step);
4459}, function(start, end) {
4460 return (end - start) / durationDay;
4461}, function(date) {
4462 return date.getUTCDate() - 1;
4463});
4464
4465function utcWeekday(i) {
4466 return newInterval(function(date) {
4467 date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
4468 date.setUTCHours(0, 0, 0, 0);
4469 }, function(date, step) {
4470 date.setUTCDate(date.getUTCDate() + step * 7);
4471 }, function(start, end) {
4472 return (end - start) / durationWeek;
4473 });
4474}
4475
4476var utcSunday = utcWeekday(0);
4477var utcMonday = utcWeekday(1);
4478var utcTuesday = utcWeekday(2);
4479var utcWednesday = utcWeekday(3);
4480var utcThursday = utcWeekday(4);
4481var utcFriday = utcWeekday(5);
4482var utcSaturday = utcWeekday(6);
4483
4484var utcMonth = newInterval(function(date) {
4485 date.setUTCDate(1);
4486 date.setUTCHours(0, 0, 0, 0);
4487}, function(date, step) {
4488 date.setUTCMonth(date.getUTCMonth() + step);
4489}, function(start, end) {
4490 return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
4491}, function(date) {
4492 return date.getUTCMonth();
4493});
4494
4495var utcYear = newInterval(function(date) {
4496 date.setUTCMonth(0, 1);
4497 date.setUTCHours(0, 0, 0, 0);
4498}, function(date, step) {
4499 date.setUTCFullYear(date.getUTCFullYear() + step);
4500}, function(start, end) {
4501 return end.getUTCFullYear() - start.getUTCFullYear();
4502}, function(date) {
4503 return date.getUTCFullYear();
4504});
4505
4506// An optimized implementation for this simple case.
4507utcYear.every = function(k) {
4508 return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : newInterval(function(date) {
4509 date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
4510 date.setUTCMonth(0, 1);
4511 date.setUTCHours(0, 0, 0, 0);
4512 }, function(date, step) {
4513 date.setUTCFullYear(date.getUTCFullYear() + step * k);
4514 });
4515};
4516
4517function localDate(d) {
4518 if (0 <= d.y && d.y < 100) {
4519 var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
4520 date.setFullYear(d.y);
4521 return date;
4522 }
4523 return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
4524}
4525
4526function utcDate(d) {
4527 if (0 <= d.y && d.y < 100) {
4528 var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
4529 date.setUTCFullYear(d.y);
4530 return date;
4531 }
4532 return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
4533}
4534
4535function newYear(y) {
4536 return {y: y, m: 0, d: 1, H: 0, M: 0, S: 0, L: 0};
4537}
4538
4539function formatLocale(locale) {
4540 var locale_dateTime = locale.dateTime,
4541 locale_date = locale.date,
4542 locale_time = locale.time,
4543 locale_periods = locale.periods,
4544 locale_weekdays = locale.days,
4545 locale_shortWeekdays = locale.shortDays,
4546 locale_months = locale.months,
4547 locale_shortMonths = locale.shortMonths;
4548
4549 var periodRe = formatRe(locale_periods),
4550 periodLookup = formatLookup(locale_periods),
4551 weekdayRe = formatRe(locale_weekdays),
4552 weekdayLookup = formatLookup(locale_weekdays),
4553 shortWeekdayRe = formatRe(locale_shortWeekdays),
4554 shortWeekdayLookup = formatLookup(locale_shortWeekdays),
4555 monthRe = formatRe(locale_months),
4556 monthLookup = formatLookup(locale_months),
4557 shortMonthRe = formatRe(locale_shortMonths),
4558 shortMonthLookup = formatLookup(locale_shortMonths);
4559
4560 var formats = {
4561 "a": formatShortWeekday,
4562 "A": formatWeekday,
4563 "b": formatShortMonth,
4564 "B": formatMonth,
4565 "c": null,
4566 "d": formatDayOfMonth,
4567 "e": formatDayOfMonth,
4568 "H": formatHour24,
4569 "I": formatHour12,
4570 "j": formatDayOfYear,
4571 "L": formatMilliseconds,
4572 "m": formatMonthNumber,
4573 "M": formatMinutes,
4574 "p": formatPeriod,
4575 "S": formatSeconds,
4576 "U": formatWeekNumberSunday,
4577 "w": formatWeekdayNumber,
4578 "W": formatWeekNumberMonday,
4579 "x": null,
4580 "X": null,
4581 "y": formatYear,
4582 "Y": formatFullYear,
4583 "Z": formatZone,
4584 "%": formatLiteralPercent
4585 };
4586
4587 var utcFormats = {
4588 "a": formatUTCShortWeekday,
4589 "A": formatUTCWeekday,
4590 "b": formatUTCShortMonth,
4591 "B": formatUTCMonth,
4592 "c": null,
4593 "d": formatUTCDayOfMonth,
4594 "e": formatUTCDayOfMonth,
4595 "H": formatUTCHour24,
4596 "I": formatUTCHour12,
4597 "j": formatUTCDayOfYear,
4598 "L": formatUTCMilliseconds,
4599 "m": formatUTCMonthNumber,
4600 "M": formatUTCMinutes,
4601 "p": formatUTCPeriod,
4602 "S": formatUTCSeconds,
4603 "U": formatUTCWeekNumberSunday,
4604 "w": formatUTCWeekdayNumber,
4605 "W": formatUTCWeekNumberMonday,
4606 "x": null,
4607 "X": null,
4608 "y": formatUTCYear,
4609 "Y": formatUTCFullYear,
4610 "Z": formatUTCZone,
4611 "%": formatLiteralPercent
4612 };
4613
4614 var parses = {
4615 "a": parseShortWeekday,
4616 "A": parseWeekday,
4617 "b": parseShortMonth,
4618 "B": parseMonth,
4619 "c": parseLocaleDateTime,
4620 "d": parseDayOfMonth,
4621 "e": parseDayOfMonth,
4622 "H": parseHour24,
4623 "I": parseHour24,
4624 "j": parseDayOfYear,
4625 "L": parseMilliseconds,
4626 "m": parseMonthNumber,
4627 "M": parseMinutes,
4628 "p": parsePeriod,
4629 "S": parseSeconds,
4630 "U": parseWeekNumberSunday,
4631 "w": parseWeekdayNumber,
4632 "W": parseWeekNumberMonday,
4633 "x": parseLocaleDate,
4634 "X": parseLocaleTime,
4635 "y": parseYear,
4636 "Y": parseFullYear,
4637 "Z": parseZone,
4638 "%": parseLiteralPercent
4639 };
4640
4641 // These recursive directive definitions must be deferred.
4642 formats.x = newFormat(locale_date, formats);
4643 formats.X = newFormat(locale_time, formats);
4644 formats.c = newFormat(locale_dateTime, formats);
4645 utcFormats.x = newFormat(locale_date, utcFormats);
4646 utcFormats.X = newFormat(locale_time, utcFormats);
4647 utcFormats.c = newFormat(locale_dateTime, utcFormats);
4648
4649 function newFormat(specifier, formats) {
4650 return function(date) {
4651 var string = [],
4652 i = -1,
4653 j = 0,
4654 n = specifier.length,
4655 c,
4656 pad,
4657 format;
4658
4659 if (!(date instanceof Date)) { date = new Date(+date); }
4660
4661 while (++i < n) {
4662 if (specifier.charCodeAt(i) === 37) {
4663 string.push(specifier.slice(j, i));
4664 if ((pad = pads[c = specifier.charAt(++i)]) != null) { c = specifier.charAt(++i); }
4665 else { pad = c === "e" ? " " : "0"; }
4666 if (format = formats[c]) { c = format(date, pad); }
4667 string.push(c);
4668 j = i + 1;
4669 }
4670 }
4671
4672 string.push(specifier.slice(j, i));
4673 return string.join("");
4674 };
4675 }
4676
4677 function newParse(specifier, newDate) {
4678 return function(string) {
4679 var d = newYear(1900),
4680 i = parseSpecifier(d, specifier, string += "", 0);
4681 if (i != string.length) { return null; }
4682
4683 // The am-pm flag is 0 for AM, and 1 for PM.
4684 if ("p" in d) { d.H = d.H % 12 + d.p * 12; }
4685
4686 // Convert day-of-week and week-of-year to day-of-year.
4687 if ("W" in d || "U" in d) {
4688 if (!("w" in d)) { d.w = "W" in d ? 1 : 0; }
4689 var day$$1 = "Z" in d ? utcDate(newYear(d.y)).getUTCDay() : newDate(newYear(d.y)).getDay();
4690 d.m = 0;
4691 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;
4692 }
4693
4694 // If a time zone is specified, all fields are interpreted as UTC and then
4695 // offset according to the specified time zone.
4696 if ("Z" in d) {
4697 d.H += d.Z / 100 | 0;
4698 d.M += d.Z % 100;
4699 return utcDate(d);
4700 }
4701
4702 // Otherwise, all fields are in local time.
4703 return newDate(d);
4704 };
4705 }
4706
4707 function parseSpecifier(d, specifier, string, j) {
4708 var i = 0,
4709 n = specifier.length,
4710 m = string.length,
4711 c,
4712 parse;
4713
4714 while (i < n) {
4715 if (j >= m) { return -1; }
4716 c = specifier.charCodeAt(i++);
4717 if (c === 37) {
4718 c = specifier.charAt(i++);
4719 parse = parses[c in pads ? specifier.charAt(i++) : c];
4720 if (!parse || ((j = parse(d, string, j)) < 0)) { return -1; }
4721 } else if (c != string.charCodeAt(j++)) {
4722 return -1;
4723 }
4724 }
4725
4726 return j;
4727 }
4728
4729 function parsePeriod(d, string, i) {
4730 var n = periodRe.exec(string.slice(i));
4731 return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
4732 }
4733
4734 function parseShortWeekday(d, string, i) {
4735 var n = shortWeekdayRe.exec(string.slice(i));
4736 return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
4737 }
4738
4739 function parseWeekday(d, string, i) {
4740 var n = weekdayRe.exec(string.slice(i));
4741 return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
4742 }
4743
4744 function parseShortMonth(d, string, i) {
4745 var n = shortMonthRe.exec(string.slice(i));
4746 return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
4747 }
4748
4749 function parseMonth(d, string, i) {
4750 var n = monthRe.exec(string.slice(i));
4751 return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
4752 }
4753
4754 function parseLocaleDateTime(d, string, i) {
4755 return parseSpecifier(d, locale_dateTime, string, i);
4756 }
4757
4758 function parseLocaleDate(d, string, i) {
4759 return parseSpecifier(d, locale_date, string, i);
4760 }
4761
4762 function parseLocaleTime(d, string, i) {
4763 return parseSpecifier(d, locale_time, string, i);
4764 }
4765
4766 function formatShortWeekday(d) {
4767 return locale_shortWeekdays[d.getDay()];
4768 }
4769
4770 function formatWeekday(d) {
4771 return locale_weekdays[d.getDay()];
4772 }
4773
4774 function formatShortMonth(d) {
4775 return locale_shortMonths[d.getMonth()];
4776 }
4777
4778 function formatMonth(d) {
4779 return locale_months[d.getMonth()];
4780 }
4781
4782 function formatPeriod(d) {
4783 return locale_periods[+(d.getHours() >= 12)];
4784 }
4785
4786 function formatUTCShortWeekday(d) {
4787 return locale_shortWeekdays[d.getUTCDay()];
4788 }
4789
4790 function formatUTCWeekday(d) {
4791 return locale_weekdays[d.getUTCDay()];
4792 }
4793
4794 function formatUTCShortMonth(d) {
4795 return locale_shortMonths[d.getUTCMonth()];
4796 }
4797
4798 function formatUTCMonth(d) {
4799 return locale_months[d.getUTCMonth()];
4800 }
4801
4802 function formatUTCPeriod(d) {
4803 return locale_periods[+(d.getUTCHours() >= 12)];
4804 }
4805
4806 return {
4807 format: function(specifier) {
4808 var f = newFormat(specifier += "", formats);
4809 f.toString = function() { return specifier; };
4810 return f;
4811 },
4812 parse: function(specifier) {
4813 var p = newParse(specifier += "", localDate);
4814 p.toString = function() { return specifier; };
4815 return p;
4816 },
4817 utcFormat: function(specifier) {
4818 var f = newFormat(specifier += "", utcFormats);
4819 f.toString = function() { return specifier; };
4820 return f;
4821 },
4822 utcParse: function(specifier) {
4823 var p = newParse(specifier, utcDate);
4824 p.toString = function() { return specifier; };
4825 return p;
4826 }
4827 };
4828}
4829
4830var pads = {"-": "", "_": " ", "0": "0"};
4831var numberRe = /^\s*\d+/;
4832var percentRe = /^%/;
4833var requoteRe = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
4834
4835function pad(value, fill, width) {
4836 var sign = value < 0 ? "-" : "",
4837 string = (sign ? -value : value) + "",
4838 length = string.length;
4839 return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
4840}
4841
4842function requote(s) {
4843 return s.replace(requoteRe, "\\$&");
4844}
4845
4846function formatRe(names) {
4847 return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
4848}
4849
4850function formatLookup(names) {
4851 var map = {}, i = -1, n = names.length;
4852 while (++i < n) { map[names[i].toLowerCase()] = i; }
4853 return map;
4854}
4855
4856function parseWeekdayNumber(d, string, i) {
4857 var n = numberRe.exec(string.slice(i, i + 1));
4858 return n ? (d.w = +n[0], i + n[0].length) : -1;
4859}
4860
4861function parseWeekNumberSunday(d, string, i) {
4862 var n = numberRe.exec(string.slice(i));
4863 return n ? (d.U = +n[0], i + n[0].length) : -1;
4864}
4865
4866function parseWeekNumberMonday(d, string, i) {
4867 var n = numberRe.exec(string.slice(i));
4868 return n ? (d.W = +n[0], i + n[0].length) : -1;
4869}
4870
4871function parseFullYear(d, string, i) {
4872 var n = numberRe.exec(string.slice(i, i + 4));
4873 return n ? (d.y = +n[0], i + n[0].length) : -1;
4874}
4875
4876function parseYear(d, string, i) {
4877 var n = numberRe.exec(string.slice(i, i + 2));
4878 return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
4879}
4880
4881function parseZone(d, string, i) {
4882 var n = /^(Z)|([+-]\d\d)(?:\:?(\d\d))?/.exec(string.slice(i, i + 6));
4883 return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
4884}
4885
4886function parseMonthNumber(d, string, i) {
4887 var n = numberRe.exec(string.slice(i, i + 2));
4888 return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
4889}
4890
4891function parseDayOfMonth(d, string, i) {
4892 var n = numberRe.exec(string.slice(i, i + 2));
4893 return n ? (d.d = +n[0], i + n[0].length) : -1;
4894}
4895
4896function parseDayOfYear(d, string, i) {
4897 var n = numberRe.exec(string.slice(i, i + 3));
4898 return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
4899}
4900
4901function parseHour24(d, string, i) {
4902 var n = numberRe.exec(string.slice(i, i + 2));
4903 return n ? (d.H = +n[0], i + n[0].length) : -1;
4904}
4905
4906function parseMinutes(d, string, i) {
4907 var n = numberRe.exec(string.slice(i, i + 2));
4908 return n ? (d.M = +n[0], i + n[0].length) : -1;
4909}
4910
4911function parseSeconds(d, string, i) {
4912 var n = numberRe.exec(string.slice(i, i + 2));
4913 return n ? (d.S = +n[0], i + n[0].length) : -1;
4914}
4915
4916function parseMilliseconds(d, string, i) {
4917 var n = numberRe.exec(string.slice(i, i + 3));
4918 return n ? (d.L = +n[0], i + n[0].length) : -1;
4919}
4920
4921function parseLiteralPercent(d, string, i) {
4922 var n = percentRe.exec(string.slice(i, i + 1));
4923 return n ? i + n[0].length : -1;
4924}
4925
4926function formatDayOfMonth(d, p) {
4927 return pad(d.getDate(), p, 2);
4928}
4929
4930function formatHour24(d, p) {
4931 return pad(d.getHours(), p, 2);
4932}
4933
4934function formatHour12(d, p) {
4935 return pad(d.getHours() % 12 || 12, p, 2);
4936}
4937
4938function formatDayOfYear(d, p) {
4939 return pad(1 + day.count(year(d), d), p, 3);
4940}
4941
4942function formatMilliseconds(d, p) {
4943 return pad(d.getMilliseconds(), p, 3);
4944}
4945
4946function formatMonthNumber(d, p) {
4947 return pad(d.getMonth() + 1, p, 2);
4948}
4949
4950function formatMinutes(d, p) {
4951 return pad(d.getMinutes(), p, 2);
4952}
4953
4954function formatSeconds(d, p) {
4955 return pad(d.getSeconds(), p, 2);
4956}
4957
4958function formatWeekNumberSunday(d, p) {
4959 return pad(sunday.count(year(d), d), p, 2);
4960}
4961
4962function formatWeekdayNumber(d) {
4963 return d.getDay();
4964}
4965
4966function formatWeekNumberMonday(d, p) {
4967 return pad(monday.count(year(d), d), p, 2);
4968}
4969
4970function formatYear(d, p) {
4971 return pad(d.getFullYear() % 100, p, 2);
4972}
4973
4974function formatFullYear(d, p) {
4975 return pad(d.getFullYear() % 10000, p, 4);
4976}
4977
4978function formatZone(d) {
4979 var z = d.getTimezoneOffset();
4980 return (z > 0 ? "-" : (z *= -1, "+"))
4981 + pad(z / 60 | 0, "0", 2)
4982 + pad(z % 60, "0", 2);
4983}
4984
4985function formatUTCDayOfMonth(d, p) {
4986 return pad(d.getUTCDate(), p, 2);
4987}
4988
4989function formatUTCHour24(d, p) {
4990 return pad(d.getUTCHours(), p, 2);
4991}
4992
4993function formatUTCHour12(d, p) {
4994 return pad(d.getUTCHours() % 12 || 12, p, 2);
4995}
4996
4997function formatUTCDayOfYear(d, p) {
4998 return pad(1 + utcDay.count(utcYear(d), d), p, 3);
4999}
5000
5001function formatUTCMilliseconds(d, p) {
5002 return pad(d.getUTCMilliseconds(), p, 3);
5003}
5004
5005function formatUTCMonthNumber(d, p) {
5006 return pad(d.getUTCMonth() + 1, p, 2);
5007}
5008
5009function formatUTCMinutes(d, p) {
5010 return pad(d.getUTCMinutes(), p, 2);
5011}
5012
5013function formatUTCSeconds(d, p) {
5014 return pad(d.getUTCSeconds(), p, 2);
5015}
5016
5017function formatUTCWeekNumberSunday(d, p) {
5018 return pad(utcSunday.count(utcYear(d), d), p, 2);
5019}
5020
5021function formatUTCWeekdayNumber(d) {
5022 return d.getUTCDay();
5023}
5024
5025function formatUTCWeekNumberMonday(d, p) {
5026 return pad(utcMonday.count(utcYear(d), d), p, 2);
5027}
5028
5029function formatUTCYear(d, p) {
5030 return pad(d.getUTCFullYear() % 100, p, 2);
5031}
5032
5033function formatUTCFullYear(d, p) {
5034 return pad(d.getUTCFullYear() % 10000, p, 4);
5035}
5036
5037function formatUTCZone() {
5038 return "+0000";
5039}
5040
5041function formatLiteralPercent() {
5042 return "%";
5043}
5044
5045var locale$1;
5046var timeFormat;
5047var timeParse;
5048var utcFormat;
5049var utcParse;
5050
5051defaultLocale({
5052 dateTime: "%x, %X",
5053 date: "%-m/%-d/%Y",
5054 time: "%-I:%M:%S %p",
5055 periods: ["AM", "PM"],
5056 days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
5057 shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
5058 months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
5059 shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
5060});
5061
5062function defaultLocale(definition) {
5063 locale$1 = formatLocale(definition);
5064 timeFormat = locale$1.format;
5065 timeParse = locale$1.parse;
5066 utcFormat = locale$1.utcFormat;
5067 utcParse = locale$1.utcParse;
5068 return locale$1;
5069}
5070
5071var isoSpecifier = "%Y-%m-%dT%H:%M:%S.%LZ";
5072
5073function formatIsoNative(date) {
5074 return date.toISOString();
5075}
5076
5077var formatIso = Date.prototype.toISOString
5078 ? formatIsoNative
5079 : utcFormat(isoSpecifier);
5080
5081function parseIsoNative(string) {
5082 var date = new Date(string);
5083 return isNaN(date) ? null : date;
5084}
5085
5086var parseIso = +new Date("2000-01-01T00:00:00.000Z")
5087 ? parseIsoNative
5088 : utcParse(isoSpecifier);
5089
5090var expandData = function(dom, data) {
5091
5092 data.authors = data.authors || [];
5093
5094 // paths
5095 data.url = "http://distill.pub/" + data.distillPath;
5096 data.githubUrl = "https://github.com/" + data.githubPath;
5097
5098 // Homepage
5099 //data.homepage = !post.noHomepage;
5100 data.journal = data.journal || {};
5101
5102 // Dates
5103 if (data.publishedDate){//} && data.journal) {
5104 data.volume = data.publishedDate.getFullYear() - 2015;
5105 data.issue = data.publishedDate.getMonth() + 1;
5106 }
5107
5108 data.publishedDate = data.publishedDate ? data.publishedDate : new Date("Invalid");
5109 data.updatedDate = data.updatedDate ? data.updatedDate : new Date("Invalid");
5110
5111 data.publishedDateRFC;
5112 var RFC = timeFormat("%a, %d %b %Y %H:%M:%S %Z");
5113 var months = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"];
5114 var zeroPad = function (n) { return n < 10 ? "0" + n : n; };
5115 data.publishedDateRFC = RFC(data.publishedDate);
5116 data.publishedYear = data.publishedDate.getFullYear();
5117 data.publishedMonth = months[data.publishedDate.getMonth()];
5118 data.publishedDay = data.publishedDate.getDate();
5119 data.publishedMonthPadded = zeroPad(data.publishedDate.getMonth() + 1);
5120 data.publishedDayPadded = zeroPad(data.publishedDate.getDate());
5121 data.updatedDateRFC = RFC(data.updatedDate);
5122
5123 if (data.authors.length > 2) {
5124 data.concatenatedAuthors = data.authors[0].lastName + ", et al.";
5125 } else if (data.authors.length === 2) {
5126 data.concatenatedAuthors = data.authors[0].lastName + " & " + data.authors[1].lastName;
5127 } else if (data.authors.length === 1) {
5128 data.concatenatedAuthors = data.authors[0].lastName;
5129 }
5130
5131 data.bibtexAuthors = data.authors.map(function(author){
5132 return author.lastName + ", " + author.firstName;
5133 }).join(" and ");
5134
5135 data.slug = data.authors.length ? data.authors[0].lastName.toLowerCase() + data.publishedYear + data.title.split(" ")[0].toLowerCase() : "Untitled";
5136
5137};
5138
5139var 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";
5140
5141var meta = function(dom, data) {
5142 var head = dom.querySelector("head");
5143 var appendHead = function (html) { return appendHtml(head, html); };
5144
5145 function meta(name, content) {
5146 if (content)
5147 { appendHead((" <meta name=\"" + name + "\" content=\"" + content + "\" >\n")); }
5148 }
5149
5150 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 "));
5151
5152 appendHead(("\n <!-- https://schema.org/Article -->\n <meta property=\"article:published\" itemprop=\"datePublished\" content=\"" + (data.publishedYear) + "-" + (data.publishedMonthPadded) + "-" + (data.publishedDayPadded) + "\" />\n <meta property=\"article:modified\" itemprop=\"dateModified\" content=\"" + (data.updatedDate) + "\" />\n "));
5153 data.authors.forEach(function (a) {
5154 appendHtml(head, ("\n <meta property=\"article:author\" content=\"" + (a.firstName) + " " + (a.lastName) + "\" />"));
5155 });
5156
5157 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 "));
5158
5159 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 "));
5160
5161 // if this is a proprer article, generate Google Scholar meta data
5162 if (data.doiSuffix){
5163 appendHead("\n <!-- https://scholar.google.com/intl/en/scholar/inclusion.html#indexing -->\n");
5164
5165 meta("citation_title", data.title);
5166 meta("citation_fulltext_html_url", data.url);
5167 meta("citation_volume", data.volume);
5168 meta("citation_issue", data.issue);
5169 meta("citation_firstpage", data.doiSuffix? ("e" + (data.doiSuffix)) : undefined);
5170 meta("citation_doi", data.doi);
5171
5172 var journal = data.journal || {};
5173 meta("citation_journal_title", journal.name);
5174 meta("citation_journal_abbrev", journal.nameAbbrev);
5175 meta("citation_issn", journal.issn);
5176 meta("citation_publisher", journal.publisher);
5177
5178 if (data.publishedDate){
5179 var zeroPad = function (n) { return n < 10 ? "0" + n : n; };
5180 meta("citation_publication_date", ((data.publishedYear) + "/" + (data.publishedMonthPadded) + "/" + (data.publishedDayPadded)));
5181 }
5182
5183 (data.authors || []).forEach(function (a) {
5184 meta("citation_author", ((a.lastName) + ", " + (a.firstName)));
5185 meta("citation_author_institution", a.affiliation);
5186 });
5187
5188 if (data.citations) {
5189 data.citations.forEach(function (key) {
5190 var d = data.bibliography[key];
5191 if(!d) {
5192 console.warn("No bibliography data fround for " + key);
5193 } else {
5194 meta("citation_reference", citation_meta_content(data.bibliography[key]) );
5195 }
5196 });
5197 }
5198 }
5199};
5200
5201function appendHtml(el, html) {
5202 el.innerHTML += html;
5203}
5204
5205function citation_meta_content(ref){
5206 var content = "citation_title=" + (ref.title) + ";";
5207 ref.author.split(" and ").forEach(function (author) {
5208 content += "citation_author=" + (author.trim()) + ";";
5209 });
5210 if ("journal" in ref){
5211 content += "citation_journal_title=" + (ref.journal) + ";";
5212 }
5213 if ("volume" in ref) {
5214 content += "citation_volume=" + (ref.volume) + ";";
5215 }
5216 if ("issue" in ref || "number" in ref){
5217 content += "citation_number=" + (ref.issue || ref.number) + ";";
5218 }
5219 /*content += `citation_first_page=${};`;
5220 content += `citation_publication_date=${};`;*/
5221 return content;
5222}
5223
5224var html$1 = "\n<style>\n dt-banner {\n background: #FFF59D;\n display: block;\n text-align: center;\n color: black;\n height: 70px;\n line-height: 70px;\n }\n</style>\n<div>This article is a draft, awaiting review for publication in Distill</div>\n";
5225
5226var banner = function(dom, data) {
5227 var banner = dom.createElement("dt-banner");
5228 banner.innerHTML = html$1;
5229 var b = dom.querySelector("body");
5230 b.insertBefore(banner, b.firstChild);
5231 banner.addEventListener("click", function() {
5232 banner.style.display = "none";
5233 });
5234};
5235
5236var 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";
5237
5238var html$2 = "\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 padding: 22px 0;\n}\ndt-header a:hover {\n color: rgba(255, 255, 255, 1);\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 padding: 28px 0;\n }\n dt-header .logo {\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 font-weight: 300;\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 <a href=\"/faq\">About</a>\n <!-- https://twitter.com/distillpub -->\n </div>\n</div>\n";
5239
5240var header = function(dom, data) {
5241 var el = dom.querySelector("dt-header");
5242 if(el) {
5243 el.innerHTML = html$2;
5244 } else {
5245 var header = dom.createElement("dt-header");
5246 header.innerHTML = html$2;
5247 var b = dom.querySelector("body");
5248 b.insertBefore(header, b.firstChild);
5249 }
5250};
5251
5252var mustache = createCommonjsModule(function (module, exports) {
5253/*!
5254 * mustache.js - Logic-less {{mustache}} templates with JavaScript
5255 * http://github.com/janl/mustache.js
5256 */
5257
5258/*global define: false Mustache: true*/
5259
5260(function defineMustache (global, factory) {
5261 if ('object' === 'object' && exports && typeof exports.nodeName !== 'string') {
5262 factory(exports); // CommonJS
5263 } else if (typeof undefined === 'function' && undefined.amd) {
5264 undefined(['exports'], factory); // AMD
5265 } else {
5266 global.Mustache = {};
5267 factory(global.Mustache); // script, wsh, asp
5268 }
5269}(commonjsGlobal, function mustacheFactory (mustache) {
5270
5271 var objectToString = Object.prototype.toString;
5272 var isArray = Array.isArray || function isArrayPolyfill (object) {
5273 return objectToString.call(object) === '[object Array]';
5274 };
5275
5276 function isFunction (object) {
5277 return typeof object === 'function';
5278 }
5279
5280 /**
5281 * More correct typeof string handling array
5282 * which normally returns typeof 'object'
5283 */
5284 function typeStr (obj) {
5285 return isArray(obj) ? 'array' : typeof obj;
5286 }
5287
5288 function escapeRegExp (string) {
5289 return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
5290 }
5291
5292 /**
5293 * Null safe way of checking whether or not an object,
5294 * including its prototype, has a given property
5295 */
5296 function hasProperty (obj, propName) {
5297 return obj != null && typeof obj === 'object' && (propName in obj);
5298 }
5299
5300 // Workaround for https://issues.apache.org/jira/browse/COUCHDB-577
5301 // See https://github.com/janl/mustache.js/issues/189
5302 var regExpTest = RegExp.prototype.test;
5303 function testRegExp (re, string) {
5304 return regExpTest.call(re, string);
5305 }
5306
5307 var nonSpaceRe = /\S/;
5308 function isWhitespace (string) {
5309 return !testRegExp(nonSpaceRe, string);
5310 }
5311
5312 var entityMap = {
5313 '&': '&amp;',
5314 '<': '&lt;',
5315 '>': '&gt;',
5316 '"': '&quot;',
5317 "'": '&#39;',
5318 '/': '&#x2F;',
5319 '`': '&#x60;',
5320 '=': '&#x3D;'
5321 };
5322
5323 function escapeHtml (string) {
5324 return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) {
5325 return entityMap[s];
5326 });
5327 }
5328
5329 var whiteRe = /\s*/;
5330 var spaceRe = /\s+/;
5331 var equalsRe = /\s*=/;
5332 var curlyRe = /\s*\}/;
5333 var tagRe = /#|\^|\/|>|\{|&|=|!/;
5334
5335 /**
5336 * Breaks up the given `template` string into a tree of tokens. If the `tags`
5337 * argument is given here it must be an array with two string values: the
5338 * opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
5339 * course, the default is to use mustaches (i.e. mustache.tags).
5340 *
5341 * A token is an array with at least 4 elements. The first element is the
5342 * mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
5343 * did not contain a symbol (i.e. {{myValue}}) this element is "name". For
5344 * all text that appears outside a symbol this element is "text".
5345 *
5346 * The second element of a token is its "value". For mustache tags this is
5347 * whatever else was inside the tag besides the opening symbol. For text tokens
5348 * this is the text itself.
5349 *
5350 * The third and fourth elements of the token are the start and end indices,
5351 * respectively, of the token in the original template.
5352 *
5353 * Tokens that are the root node of a subtree contain two more elements: 1) an
5354 * array of tokens in the subtree and 2) the index in the original template at
5355 * which the closing tag for that section begins.
5356 */
5357 function parseTemplate (template, tags) {
5358 if (!template)
5359 { return []; }
5360
5361 var sections = []; // Stack to hold section tokens
5362 var tokens = []; // Buffer to hold the tokens
5363 var spaces = []; // Indices of whitespace tokens on the current line
5364 var hasTag = false; // Is there a {{tag}} on the current line?
5365 var nonSpace = false; // Is there a non-space char on the current line?
5366
5367 // Strips all whitespace tokens array for the current line
5368 // if there was a {{#tag}} on it and otherwise only space.
5369 function stripSpace () {
5370 if (hasTag && !nonSpace) {
5371 while (spaces.length)
5372 { delete tokens[spaces.pop()]; }
5373 } else {
5374 spaces = [];
5375 }
5376
5377 hasTag = false;
5378 nonSpace = false;
5379 }
5380
5381 var openingTagRe, closingTagRe, closingCurlyRe;
5382 function compileTags (tagsToCompile) {
5383 if (typeof tagsToCompile === 'string')
5384 { tagsToCompile = tagsToCompile.split(spaceRe, 2); }
5385
5386 if (!isArray(tagsToCompile) || tagsToCompile.length !== 2)
5387 { throw new Error('Invalid tags: ' + tagsToCompile); }
5388
5389 openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\s*');
5390 closingTagRe = new RegExp('\\s*' + escapeRegExp(tagsToCompile[1]));
5391 closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tagsToCompile[1]));
5392 }
5393
5394 compileTags(tags || mustache.tags);
5395
5396 var scanner = new Scanner(template);
5397
5398 var start, type, value, chr, token, openSection;
5399 while (!scanner.eos()) {
5400 start = scanner.pos;
5401
5402 // Match any text between tags.
5403 value = scanner.scanUntil(openingTagRe);
5404
5405 if (value) {
5406 for (var i = 0, valueLength = value.length; i < valueLength; ++i) {
5407 chr = value.charAt(i);
5408
5409 if (isWhitespace(chr)) {
5410 spaces.push(tokens.length);
5411 } else {
5412 nonSpace = true;
5413 }
5414
5415 tokens.push([ 'text', chr, start, start + 1 ]);
5416 start += 1;
5417
5418 // Check for whitespace on the current line.
5419 if (chr === '\n')
5420 { stripSpace(); }
5421 }
5422 }
5423
5424 // Match the opening tag.
5425 if (!scanner.scan(openingTagRe))
5426 { break; }
5427
5428 hasTag = true;
5429
5430 // Get the tag type.
5431 type = scanner.scan(tagRe) || 'name';
5432 scanner.scan(whiteRe);
5433
5434 // Get the tag value.
5435 if (type === '=') {
5436 value = scanner.scanUntil(equalsRe);
5437 scanner.scan(equalsRe);
5438 scanner.scanUntil(closingTagRe);
5439 } else if (type === '{') {
5440 value = scanner.scanUntil(closingCurlyRe);
5441 scanner.scan(curlyRe);
5442 scanner.scanUntil(closingTagRe);
5443 type = '&';
5444 } else {
5445 value = scanner.scanUntil(closingTagRe);
5446 }
5447
5448 // Match the closing tag.
5449 if (!scanner.scan(closingTagRe))
5450 { throw new Error('Unclosed tag at ' + scanner.pos); }
5451
5452 token = [ type, value, start, scanner.pos ];
5453 tokens.push(token);
5454
5455 if (type === '#' || type === '^') {
5456 sections.push(token);
5457 } else if (type === '/') {
5458 // Check section nesting.
5459 openSection = sections.pop();
5460
5461 if (!openSection)
5462 { throw new Error('Unopened section "' + value + '" at ' + start); }
5463
5464 if (openSection[1] !== value)
5465 { throw new Error('Unclosed section "' + openSection[1] + '" at ' + start); }
5466 } else if (type === 'name' || type === '{' || type === '&') {
5467 nonSpace = true;
5468 } else if (type === '=') {
5469 // Set the tags for the next time around.
5470 compileTags(value);
5471 }
5472 }
5473
5474 // Make sure there are no open sections when we're done.
5475 openSection = sections.pop();
5476
5477 if (openSection)
5478 { throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos); }
5479
5480 return nestTokens(squashTokens(tokens));
5481 }
5482
5483 /**
5484 * Combines the values of consecutive text tokens in the given `tokens` array
5485 * to a single token.
5486 */
5487 function squashTokens (tokens) {
5488 var squashedTokens = [];
5489
5490 var token, lastToken;
5491 for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
5492 token = tokens[i];
5493
5494 if (token) {
5495 if (token[0] === 'text' && lastToken && lastToken[0] === 'text') {
5496 lastToken[1] += token[1];
5497 lastToken[3] = token[3];
5498 } else {
5499 squashedTokens.push(token);
5500 lastToken = token;
5501 }
5502 }
5503 }
5504
5505 return squashedTokens;
5506 }
5507
5508 /**
5509 * Forms the given array of `tokens` into a nested tree structure where
5510 * tokens that represent a section have two additional items: 1) an array of
5511 * all tokens that appear in that section and 2) the index in the original
5512 * template that represents the end of that section.
5513 */
5514 function nestTokens (tokens) {
5515 var nestedTokens = [];
5516 var collector = nestedTokens;
5517 var sections = [];
5518
5519 var token, section;
5520 for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
5521 token = tokens[i];
5522
5523 switch (token[0]) {
5524 case '#':
5525 case '^':
5526 collector.push(token);
5527 sections.push(token);
5528 collector = token[4] = [];
5529 break;
5530 case '/':
5531 section = sections.pop();
5532 section[5] = token[2];
5533 collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens;
5534 break;
5535 default:
5536 collector.push(token);
5537 }
5538 }
5539
5540 return nestedTokens;
5541 }
5542
5543 /**
5544 * A simple string scanner that is used by the template parser to find
5545 * tokens in template strings.
5546 */
5547 function Scanner (string) {
5548 this.string = string;
5549 this.tail = string;
5550 this.pos = 0;
5551 }
5552
5553 /**
5554 * Returns `true` if the tail is empty (end of string).
5555 */
5556 Scanner.prototype.eos = function eos () {
5557 return this.tail === '';
5558 };
5559
5560 /**
5561 * Tries to match the given regular expression at the current position.
5562 * Returns the matched text if it can match, the empty string otherwise.
5563 */
5564 Scanner.prototype.scan = function scan (re) {
5565 var match = this.tail.match(re);
5566
5567 if (!match || match.index !== 0)
5568 { return ''; }
5569
5570 var string = match[0];
5571
5572 this.tail = this.tail.substring(string.length);
5573 this.pos += string.length;
5574
5575 return string;
5576 };
5577
5578 /**
5579 * Skips all text until the given regular expression can be matched. Returns
5580 * the skipped string, which is the entire tail if no match can be made.
5581 */
5582 Scanner.prototype.scanUntil = function scanUntil (re) {
5583 var index = this.tail.search(re), match;
5584
5585 switch (index) {
5586 case -1:
5587 match = this.tail;
5588 this.tail = '';
5589 break;
5590 case 0:
5591 match = '';
5592 break;
5593 default:
5594 match = this.tail.substring(0, index);
5595 this.tail = this.tail.substring(index);
5596 }
5597
5598 this.pos += match.length;
5599
5600 return match;
5601 };
5602
5603 /**
5604 * Represents a rendering context by wrapping a view object and
5605 * maintaining a reference to the parent context.
5606 */
5607 function Context (view, parentContext) {
5608 this.view = view;
5609 this.cache = { '.': this.view };
5610 this.parent = parentContext;
5611 }
5612
5613 /**
5614 * Creates a new context using the given view with this context
5615 * as the parent.
5616 */
5617 Context.prototype.push = function push (view) {
5618 return new Context(view, this);
5619 };
5620
5621 /**
5622 * Returns the value of the given name in this context, traversing
5623 * up the context hierarchy if the value is absent in this context's view.
5624 */
5625 Context.prototype.lookup = function lookup (name) {
5626 var cache = this.cache;
5627
5628 var value;
5629 if (cache.hasOwnProperty(name)) {
5630 value = cache[name];
5631 } else {
5632 var context = this, names, index, lookupHit = false;
5633
5634 while (context) {
5635 if (name.indexOf('.') > 0) {
5636 value = context.view;
5637 names = name.split('.');
5638 index = 0;
5639
5640 /**
5641 * Using the dot notion path in `name`, we descend through the
5642 * nested objects.
5643 *
5644 * To be certain that the lookup has been successful, we have to
5645 * check if the last object in the path actually has the property
5646 * we are looking for. We store the result in `lookupHit`.
5647 *
5648 * This is specially necessary for when the value has been set to
5649 * `undefined` and we want to avoid looking up parent contexts.
5650 **/
5651 while (value != null && index < names.length) {
5652 if (index === names.length - 1)
5653 { lookupHit = hasProperty(value, names[index]); }
5654
5655 value = value[names[index++]];
5656 }
5657 } else {
5658 value = context.view[name];
5659 lookupHit = hasProperty(context.view, name);
5660 }
5661
5662 if (lookupHit)
5663 { break; }
5664
5665 context = context.parent;
5666 }
5667
5668 cache[name] = value;
5669 }
5670
5671 if (isFunction(value))
5672 { value = value.call(this.view); }
5673
5674 return value;
5675 };
5676
5677 /**
5678 * A Writer knows how to take a stream of tokens and render them to a
5679 * string, given a context. It also maintains a cache of templates to
5680 * avoid the need to parse the same template twice.
5681 */
5682 function Writer () {
5683 this.cache = {};
5684 }
5685
5686 /**
5687 * Clears all cached templates in this writer.
5688 */
5689 Writer.prototype.clearCache = function clearCache () {
5690 this.cache = {};
5691 };
5692
5693 /**
5694 * Parses and caches the given `template` and returns the array of tokens
5695 * that is generated from the parse.
5696 */
5697 Writer.prototype.parse = function parse (template, tags) {
5698 var cache = this.cache;
5699 var tokens = cache[template];
5700
5701 if (tokens == null)
5702 { tokens = cache[template] = parseTemplate(template, tags); }
5703
5704 return tokens;
5705 };
5706
5707 /**
5708 * High-level method that is used to render the given `template` with
5709 * the given `view`.
5710 *
5711 * The optional `partials` argument may be an object that contains the
5712 * names and templates of partials that are used in the template. It may
5713 * also be a function that is used to load partial templates on the fly
5714 * that takes a single argument: the name of the partial.
5715 */
5716 Writer.prototype.render = function render (template, view, partials) {
5717 var tokens = this.parse(template);
5718 var context = (view instanceof Context) ? view : new Context(view);
5719 return this.renderTokens(tokens, context, partials, template);
5720 };
5721
5722 /**
5723 * Low-level method that renders the given array of `tokens` using
5724 * the given `context` and `partials`.
5725 *
5726 * Note: The `originalTemplate` is only ever used to extract the portion
5727 * of the original template that was contained in a higher-order section.
5728 * If the template doesn't use higher-order sections, this argument may
5729 * be omitted.
5730 */
5731 Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate) {
5732 var this$1 = this;
5733
5734 var buffer = '';
5735
5736 var token, symbol, value;
5737 for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) {
5738 value = undefined;
5739 token = tokens[i];
5740 symbol = token[0];
5741
5742 if (symbol === '#') { value = this$1.renderSection(token, context, partials, originalTemplate); }
5743 else if (symbol === '^') { value = this$1.renderInverted(token, context, partials, originalTemplate); }
5744 else if (symbol === '>') { value = this$1.renderPartial(token, context, partials, originalTemplate); }
5745 else if (symbol === '&') { value = this$1.unescapedValue(token, context); }
5746 else if (symbol === 'name') { value = this$1.escapedValue(token, context); }
5747 else if (symbol === 'text') { value = this$1.rawValue(token); }
5748
5749 if (value !== undefined)
5750 { buffer += value; }
5751 }
5752
5753 return buffer;
5754 };
5755
5756 Writer.prototype.renderSection = function renderSection (token, context, partials, originalTemplate) {
5757 var this$1 = this;
5758
5759 var self = this;
5760 var buffer = '';
5761 var value = context.lookup(token[1]);
5762
5763 // This function is used to render an arbitrary template
5764 // in the current context by higher-order sections.
5765 function subRender (template) {
5766 return self.render(template, context, partials);
5767 }
5768
5769 if (!value) { return; }
5770
5771 if (isArray(value)) {
5772 for (var j = 0, valueLength = value.length; j < valueLength; ++j) {
5773 buffer += this$1.renderTokens(token[4], context.push(value[j]), partials, originalTemplate);
5774 }
5775 } else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') {
5776 buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate);
5777 } else if (isFunction(value)) {
5778 if (typeof originalTemplate !== 'string')
5779 { throw new Error('Cannot use higher-order sections without the original template'); }
5780
5781 // Extract the portion of the original template that the section contains.
5782 value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender);
5783
5784 if (value != null)
5785 { buffer += value; }
5786 } else {
5787 buffer += this.renderTokens(token[4], context, partials, originalTemplate);
5788 }
5789 return buffer;
5790 };
5791
5792 Writer.prototype.renderInverted = function renderInverted (token, context, partials, originalTemplate) {
5793 var value = context.lookup(token[1]);
5794
5795 // Use JavaScript's definition of falsy. Include empty arrays.
5796 // See https://github.com/janl/mustache.js/issues/186
5797 if (!value || (isArray(value) && value.length === 0))
5798 { return this.renderTokens(token[4], context, partials, originalTemplate); }
5799 };
5800
5801 Writer.prototype.renderPartial = function renderPartial (token, context, partials) {
5802 if (!partials) { return; }
5803
5804 var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
5805 if (value != null)
5806 { return this.renderTokens(this.parse(value), context, partials, value); }
5807 };
5808
5809 Writer.prototype.unescapedValue = function unescapedValue (token, context) {
5810 var value = context.lookup(token[1]);
5811 if (value != null)
5812 { return value; }
5813 };
5814
5815 Writer.prototype.escapedValue = function escapedValue (token, context) {
5816 var value = context.lookup(token[1]);
5817 if (value != null)
5818 { return mustache.escape(value); }
5819 };
5820
5821 Writer.prototype.rawValue = function rawValue (token) {
5822 return token[1];
5823 };
5824
5825 mustache.name = 'mustache.js';
5826 mustache.version = '2.3.0';
5827 mustache.tags = [ '{{', '}}' ];
5828
5829 // All high-level mustache.* functions use this writer.
5830 var defaultWriter = new Writer();
5831
5832 /**
5833 * Clears all cached templates in the default writer.
5834 */
5835 mustache.clearCache = function clearCache () {
5836 return defaultWriter.clearCache();
5837 };
5838
5839 /**
5840 * Parses and caches the given template in the default writer and returns the
5841 * array of tokens it contains. Doing this ahead of time avoids the need to
5842 * parse templates on the fly as they are rendered.
5843 */
5844 mustache.parse = function parse (template, tags) {
5845 return defaultWriter.parse(template, tags);
5846 };
5847
5848 /**
5849 * Renders the `template` with the given `view` and `partials` using the
5850 * default writer.
5851 */
5852 mustache.render = function render (template, view, partials) {
5853 if (typeof template !== 'string') {
5854 throw new TypeError('Invalid template! Template should be a "string" ' +
5855 'but "' + typeStr(template) + '" was given as the first ' +
5856 'argument for mustache#render(template, view, partials)');
5857 }
5858
5859 return defaultWriter.render(template, view, partials);
5860 };
5861
5862 // This is here for backwards compatibility with 0.4.x.,
5863 /*eslint-disable */ // eslint wants camel cased function name
5864 mustache.to_html = function to_html (template, view, partials, send) {
5865 /*eslint-enable*/
5866
5867 var result = mustache.render(template, view, partials);
5868
5869 if (isFunction(send)) {
5870 send(result);
5871 } else {
5872 return result;
5873 }
5874 };
5875
5876 // Export the escaping function so that the user may override it.
5877 // See https://github.com/janl/mustache.js/issues/244
5878 mustache.escape = escapeHtml;
5879
5880 // Export these mainly for testing, but also for advanced usage.
5881 mustache.Scanner = Scanner;
5882 mustache.Context = Context;
5883 mustache.Writer = Writer;
5884
5885 return mustache;
5886}));
5887});
5888
5889var html$3 = "\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 dt-article dt-byline a {\n text-decoration: none;\n border-bottom: none;\n }\n dt-article dt-byline a:hover {\n text-decoration: underline;\n border-bottom: none;\n }\n dt-byline .authors {\n text-align: left;\n }\n dt-byline .name {\n display: inline;\n text-transform: uppercase;\n }\n dt-byline .affiliation {\n display: inline;\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: 1080px) {\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";
5890
5891var 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";
5892
5893var byline = function(dom, data) {
5894 var el = dom.querySelector('dt-byline');
5895 if (el) {
5896 el.innerHTML = html$3 + mustache.render(template, data);
5897 }
5898};
5899
5900var html$4 = "\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: rgb(250, 250, 250);\n padding-top: 36px;\n padding-bottom: 60px;\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 dt-appendix ol,\n dt-appendix ul {\n padding-left: 24px;\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";
5901
5902var appendix = function(dom, data) {
5903 var el = dom.querySelector('dt-appendix');
5904 if (el) {
5905 var oldHtml = el.innerHTML;
5906 el.innerHTML = html$4;
5907 var div = el.querySelector("div.l-body");
5908
5909 if (dom.querySelector("dt-fn")) {
5910 div.innerHTML = "<h3>Footnotes</h3><dt-fn-list></dt-fn-list>" + div.innerHTML;
5911 }
5912
5913 div.innerHTML = oldHtml + div.innerHTML;
5914 console.log(data.githubCompareUpdatesUrl);
5915 if (data.githubCompareUpdatesUrl) {
5916 div.innerHTML = "<h3>Updates</h3><p><a href=\"" + (data.githubCompareUpdatesUrl) + "\">View all changes</a> to this article since it was first published.</p>" + div.innerHTML;
5917 }
5918
5919 el.querySelector("a.github").setAttribute("href", data.githubUrl);
5920 el.querySelector("a.github-issue").setAttribute("href", data.githubUrl + "/issues/new");
5921 el.querySelector(".citation.short").textContent = data.concatenatedAuthors + ", " + '"' + data.title + '", Distill, ' + data.publishedYear + ".";
5922 var bibtex = "@article{" + data.slug + ",\n";
5923 bibtex += " author = {" + data.bibtexAuthors + "},\n";
5924 bibtex += " title = {" + data.title + "},\n";
5925 bibtex += " journal = {Distill},\n";
5926 bibtex += " year = {" + data.publishedYear + "},\n";
5927 bibtex += " note = {" + data.url + "}\n";
5928 bibtex += "}";
5929 el.querySelector(".citation.long").textContent = bibtex;
5930 }
5931
5932};
5933
5934var html$5 = "\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";
5935
5936var footer = function(dom, data) {
5937 var el = dom.querySelector("dt-footer");
5938 if(el) {
5939 el.innerHTML = html$5;
5940 } else {
5941 var footer = dom.createElement("dt-footer");
5942 footer.innerHTML = html$5;
5943 var b = dom.querySelector("body");
5944 b.appendChild(footer);
5945 }
5946};
5947
5948var citation = function(dom, data) {
5949 var css = "\n dt-cite {\n color: hsla(206, 90%, 20%, 0.7);\n }\n dt-cite .citation-number {\n cursor: default;\n white-space: nowrap;\n font-family: -apple-system, BlinkMacSystemFont, \"Roboto\", Helvetica, sans-serif;\n font-size: 75%;\n color: hsla(206, 90%, 20%, 0.7);\n display: inline-block;\n line-height: 1.1em;\n text-align: center;\n position: relative;\n top: -2px;\n margin: 0 2px;\n }\n figcaption dt-cite .citation-number {\n font-size: 11px;\n font-weight: normal;\n top: -2px;\n line-height: 1em;\n }\n ";
5950
5951 var style = dom.createElement("style");
5952 style.textContent = css;
5953 dom.querySelector("body").appendChild(style);
5954
5955 var citations = data.citations;
5956 /*if (data.citations) {
5957 citations = Object.keys(data.citations).map(c => data.citations[c]);
5958 citations.sort((a, b) => {
5959 return a.author.localeCompare(b.author);
5960 });
5961 }*/
5962
5963 var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
5964 citeTags.forEach(function (el,n) {
5965 var key = el.getAttribute("key");
5966 if (key) {
5967 var keys = key.split(",");
5968 var cite_string = inline_cite_short(keys);
5969 var cite_hover_str = "";
5970 keys.map(function (key,n) {
5971 if (n>0) { cite_hover_str += "<br><br>"; }
5972 cite_hover_str += hover_cite(data.bibliography[key]);
5973 });
5974 cite_hover_str = cite_hover_str.replace(/"/g, "&#39;");
5975 var orig_string = el.innerHTML;
5976 if (orig_string != "") { orig_string += " "; }
5977 el.innerHTML = "<span id=\"citation-" + n + "\" data-hover=\"" + cite_hover_str + "\">" + orig_string + "<span class=\"citation-number\">" + cite_string + "</span></span>";
5978 }
5979 });
5980
5981 var bibEl = dom.querySelector("dt-bibliography");
5982 if (bibEl) {
5983 var ol = dom.createElement("ol");
5984 citations.forEach(function (key) {
5985 var el = dom.createElement("li");
5986 el.innerHTML = bibliography_cite(data.bibliography[key]);
5987 ol.appendChild(el);
5988 });
5989 bibEl.appendChild(ol);
5990 }
5991
5992 function inline_cite_short(keys){
5993 function cite_string(key){
5994 if (key in data.bibliography){
5995 var n = data.citations.indexOf(key)+1;
5996 return ""+n;
5997 } else {
5998 return "?";
5999 }
6000 }
6001 return "["+keys.map(cite_string).join(", ")+"]";
6002 }
6003
6004 function inline_cite_long(keys){
6005 function cite_string(key){
6006 if (key in data.bibliography){
6007 var ent = data.bibliography[key];
6008 var names = ent.author.split(" and ");
6009 names = names.map(function (name) { return name.split(",")[0].trim(); });
6010 var year = ent.year;
6011 if (names.length == 1) { return names[0] + ", " + year; }
6012 if (names.length == 2) { return names[0] + " & " + names[1] + ", " + year; }
6013 if (names.length > 2) { return names[0] + ", et al., " + year; }
6014 } else {
6015 return "?";
6016 }
6017 }
6018 return keys.map(cite_string).join(", ");
6019 }
6020
6021 function author_string(ent, template, sep, finalSep){
6022 var names = ent.author.split(" and ");
6023 var name_strings = names.map(function (name) {
6024 name = name.trim();
6025 if (name.indexOf(",") != -1){
6026 var last = name.split(",")[0].trim();
6027 var firsts = name.split(",")[1];
6028 } else {
6029 var last = name.split(" ").slice(-1)[0].trim();
6030 var firsts = name.split(" ").slice(0,-1).join(" ");
6031 }
6032 var initials = "";
6033 if (firsts != undefined) {
6034 initials = firsts.trim().split(" ").map(function (s) { return s.trim()[0]; });
6035 initials = initials.join(".")+".";
6036 }
6037 return template.replace("${F}", firsts)
6038 .replace("${L}", last)
6039 .replace("${I}", initials);
6040 });
6041 if (names.length > 1) {
6042 var str = name_strings.slice(0, names.length-1).join(sep);
6043 str += (finalSep || sep) + name_strings[names.length-1];
6044 return str;
6045 } else {
6046 return name_strings[0];
6047 }
6048 }
6049
6050 function venue_string(ent) {
6051 var cite = (ent.journal || ent.booktitle || "");
6052 if ("volume" in ent){
6053 var issue = ent.issue || ent.number;
6054 issue = (issue != undefined)? "("+issue+")" : "";
6055 cite += ", Vol " + ent.volume + issue;
6056 }
6057 if ("pages" in ent){
6058 cite += ", pp. " + ent.pages;
6059 }
6060 if (cite != "") { cite += ". "; }
6061 if ("publisher" in ent){
6062 cite += ent.publisher;
6063 if (cite[cite.length-1] != ".") { cite += "."; }
6064 }
6065 return cite;
6066 }
6067
6068 function link_string(ent){
6069 if ("url" in ent){
6070 var url = ent.url;
6071 var arxiv_match = (/arxiv\.org\/abs\/([0-9\.]*)/).exec(url);
6072 if (arxiv_match != null){
6073 url = "http://arxiv.org/pdf/" + (arxiv_match[1]) + ".pdf";
6074 }
6075
6076 if (url.slice(-4) == ".pdf"){
6077 var label = "PDF";
6078 } else if (url.slice(-5) == ".html") {
6079 var label = "HTML";
6080 }
6081 return (" &ensp;<a href=\"" + url + "\">[" + (label||"link") + "]</a>");
6082 }/* else if ("doi" in ent){
6083 return ` &ensp;<a href="https://doi.org/${ent.doi}" >[DOI]</a>`;
6084 }*/ else {
6085 return "";
6086 }
6087 }
6088 function doi_string(ent, new_line){
6089 if ("doi" in ent) {
6090 return ((new_line?"<br>":"") + " <a href=\"https://doi.org/" + (ent.doi) + "\" style=\"text-decoration:inherit;\">DOI: " + (ent.doi) + "</a>");
6091 } else {
6092 return "";
6093 }
6094 }
6095
6096 function bibliography_cite(ent, fancy){
6097 if (ent){
6098 var cite = "<b>" + ent.title + "</b> ";
6099 cite += link_string(ent) + "<br>";
6100 cite += author_string(ent, "${L}, ${I}", ", ", " and ");
6101 if (ent.year || ent.date){
6102 cite += ", " + (ent.year || ent.date) + ". ";
6103 } else {
6104 cite += ". ";
6105 }
6106 cite += venue_string(ent);
6107 cite += doi_string(ent);
6108 return cite
6109 /*var cite = author_string(ent, "${L}, ${I}", ", ", " and ");
6110 if (ent.year || ent.date){
6111 cite += ", " + (ent.year || ent.date) + ". "
6112 } else {
6113 cite += ". "
6114 }
6115 cite += "<b>" + ent.title + "</b>. ";
6116 cite += venue_string(ent);
6117 cite += doi_string(ent);
6118 cite += link_string(ent);
6119 return cite*/
6120 } else {
6121 return "?";
6122 }
6123 }
6124
6125 function hover_cite(ent){
6126 if (ent){
6127 var cite = "";
6128 cite += "<b>" + ent.title + "</b>";
6129 cite += link_string(ent);
6130 cite += "<br>";
6131
6132 var a_str = author_string(ent, "${I} ${L}", ", ") + ".";
6133 var v_str = venue_string(ent).trim() + " " + ent.year + ". " + doi_string(ent, true);
6134
6135 if ((a_str+v_str).length < Math.min(40, ent.title.length)) {
6136 cite += a_str + " " + v_str;
6137 } else {
6138 cite += a_str + "<br>" + v_str;
6139 }
6140 return cite;
6141 } else {
6142 return "?";
6143 }
6144 }
6145
6146
6147 //https://scholar.google.com/scholar?q=allintitle%3ADocument+author%3Aolah
6148 function get_GS_URL(ent){
6149 if (ent){
6150 var names = ent.author.split(" and ");
6151 names = names.map(function (name) { return name.split(",")[0].trim(); });
6152 var title = ent.title.split(" ");//.replace(/[,:]/, "")
6153 var url = "http://search.labs.crossref.org/dois?";//""https://scholar.google.com/scholar?"
6154 url += uris({q: names.join(" ") + " " + title.join(" ")});
6155 }
6156
6157 }
6158};
6159
6160var footnote = function(dom, data) {
6161
6162 var fnTags = [].slice.apply(dom.querySelectorAll("dt-fn"));
6163 var fnContent = [];
6164 fnTags.forEach(function (el,n) {
6165 var content = el.innerHTML;
6166 fnContent.push(content);
6167 n = (n+1)+"";
6168 var key = "fn-"+n;
6169 var escaped_content = content.replace(/"/g, "&#39;");
6170 el.innerHTML = "<sup><span id=\"" + key + "\" data-hover=\"" + escaped_content + "\" style=\"cursor:pointer\">" + n + "</span></sup>";
6171 });
6172
6173 var fnList = dom.querySelector("dt-fn-list");
6174 if (fnList) {
6175 var ol = dom.createElement("ol");
6176 fnContent.forEach(function (content) {
6177 var el = dom.createElement("li");
6178 el.innerHTML = content;
6179 ol.appendChild(el);
6180 });
6181 fnList.appendChild(ol);
6182 }
6183
6184};
6185
6186var marked = createCommonjsModule(function (module, exports) {
6187/**
6188 * marked - a markdown parser
6189 * Copyright (c) 2011-2014, Christopher Jeffrey. (MIT Licensed)
6190 * https://github.com/chjj/marked
6191 */
6192
6193(function() {
6194
6195/**
6196 * Block-Level Grammar
6197 */
6198
6199var block = {
6200 newline: /^\n+/,
6201 code: /^( {4}[^\n]+\n*)+/,
6202 fences: noop,
6203 hr: /^( *[-*_]){3,} *(?:\n+|$)/,
6204 heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/,
6205 nptable: noop,
6206 lheading: /^([^\n]+)\n *(=|-){2,} *(?:\n+|$)/,
6207 blockquote: /^( *>[^\n]+(\n(?!def)[^\n]+)*\n*)+/,
6208 list: /^( *)(bull) [\s\S]+?(?:hr|def|\n{2,}(?! )(?!\1bull )\n*|\s*$)/,
6209 html: /^ *(?:comment *(?:\n|\s*$)|closed *(?:\n{2,}|\s*$)|closing *(?:\n{2,}|\s*$))/,
6210 def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)/,
6211 table: noop,
6212 paragraph: /^((?:[^\n]+\n?(?!hr|heading|lheading|blockquote|tag|def))+)\n*/,
6213 text: /^[^\n]+/
6214};
6215
6216block.bullet = /(?:[*+-]|\d+\.)/;
6217block.item = /^( *)(bull) [^\n]*(?:\n(?!\1bull )[^\n]*)*/;
6218block.item = replace(block.item, 'gm')
6219 (/bull/g, block.bullet)
6220 ();
6221
6222block.list = replace(block.list)
6223 (/bull/g, block.bullet)
6224 ('hr', '\\n+(?=\\1?(?:[-*_] *){3,}(?:\\n+|$))')
6225 ('def', '\\n+(?=' + block.def.source + ')')
6226 ();
6227
6228block.blockquote = replace(block.blockquote)
6229 ('def', block.def)
6230 ();
6231
6232block._tag = '(?!(?:'
6233 + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code'
6234 + '|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo'
6235 + '|span|br|wbr|ins|del|img)\\b)\\w+(?!:/|[^\\w\\s@]*@)\\b';
6236
6237block.html = replace(block.html)
6238 ('comment', /<!--[\s\S]*?-->/)
6239 ('closed', /<(tag)[\s\S]+?<\/\1>/)
6240 ('closing', /<tag(?:"[^"]*"|'[^']*'|[^'">])*?>/)
6241 (/tag/g, block._tag)
6242 ();
6243
6244block.paragraph = replace(block.paragraph)
6245 ('hr', block.hr)
6246 ('heading', block.heading)
6247 ('lheading', block.lheading)
6248 ('blockquote', block.blockquote)
6249 ('tag', '<' + block._tag)
6250 ('def', block.def)
6251 ();
6252
6253/**
6254 * Normal Block Grammar
6255 */
6256
6257block.normal = merge({}, block);
6258
6259/**
6260 * GFM Block Grammar
6261 */
6262
6263block.gfm = merge({}, block.normal, {
6264 fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\s*\1 *(?:\n+|$)/,
6265 paragraph: /^/,
6266 heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/
6267});
6268
6269block.gfm.paragraph = replace(block.paragraph)
6270 ('(?!', '(?!'
6271 + block.gfm.fences.source.replace('\\1', '\\2') + '|'
6272 + block.list.source.replace('\\1', '\\3') + '|')
6273 ();
6274
6275/**
6276 * GFM + Tables Block Grammar
6277 */
6278
6279block.tables = merge({}, block.gfm, {
6280 nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/,
6281 table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/
6282});
6283
6284/**
6285 * Block Lexer
6286 */
6287
6288function Lexer(options) {
6289 this.tokens = [];
6290 this.tokens.links = {};
6291 this.options = options || marked.defaults;
6292 this.rules = block.normal;
6293
6294 if (this.options.gfm) {
6295 if (this.options.tables) {
6296 this.rules = block.tables;
6297 } else {
6298 this.rules = block.gfm;
6299 }
6300 }
6301}
6302
6303/**
6304 * Expose Block Rules
6305 */
6306
6307Lexer.rules = block;
6308
6309/**
6310 * Static Lex Method
6311 */
6312
6313Lexer.lex = function(src, options) {
6314 var lexer = new Lexer(options);
6315 return lexer.lex(src);
6316};
6317
6318/**
6319 * Preprocessing
6320 */
6321
6322Lexer.prototype.lex = function(src) {
6323 src = src
6324 .replace(/\r\n|\r/g, '\n')
6325 .replace(/\t/g, ' ')
6326 .replace(/\u00a0/g, ' ')
6327 .replace(/\u2424/g, '\n');
6328
6329 return this.token(src, true);
6330};
6331
6332/**
6333 * Lexing
6334 */
6335
6336Lexer.prototype.token = function(src, top, bq) {
6337 var this$1 = this;
6338
6339 var src = src.replace(/^ +$/gm, '')
6340 , next
6341 , loose
6342 , cap
6343 , bull
6344 , b
6345 , item
6346 , space
6347 , i
6348 , l;
6349
6350 while (src) {
6351 // newline
6352 if (cap = this$1.rules.newline.exec(src)) {
6353 src = src.substring(cap[0].length);
6354 if (cap[0].length > 1) {
6355 this$1.tokens.push({
6356 type: 'space'
6357 });
6358 }
6359 }
6360
6361 // code
6362 if (cap = this$1.rules.code.exec(src)) {
6363 src = src.substring(cap[0].length);
6364 cap = cap[0].replace(/^ {4}/gm, '');
6365 this$1.tokens.push({
6366 type: 'code',
6367 text: !this$1.options.pedantic
6368 ? cap.replace(/\n+$/, '')
6369 : cap
6370 });
6371 continue;
6372 }
6373
6374 // fences (gfm)
6375 if (cap = this$1.rules.fences.exec(src)) {
6376 src = src.substring(cap[0].length);
6377 this$1.tokens.push({
6378 type: 'code',
6379 lang: cap[2],
6380 text: cap[3] || ''
6381 });
6382 continue;
6383 }
6384
6385 // heading
6386 if (cap = this$1.rules.heading.exec(src)) {
6387 src = src.substring(cap[0].length);
6388 this$1.tokens.push({
6389 type: 'heading',
6390 depth: cap[1].length,
6391 text: cap[2]
6392 });
6393 continue;
6394 }
6395
6396 // table no leading pipe (gfm)
6397 if (top && (cap = this$1.rules.nptable.exec(src))) {
6398 src = src.substring(cap[0].length);
6399
6400 item = {
6401 type: 'table',
6402 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
6403 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
6404 cells: cap[3].replace(/\n$/, '').split('\n')
6405 };
6406
6407 for (i = 0; i < item.align.length; i++) {
6408 if (/^ *-+: *$/.test(item.align[i])) {
6409 item.align[i] = 'right';
6410 } else if (/^ *:-+: *$/.test(item.align[i])) {
6411 item.align[i] = 'center';
6412 } else if (/^ *:-+ *$/.test(item.align[i])) {
6413 item.align[i] = 'left';
6414 } else {
6415 item.align[i] = null;
6416 }
6417 }
6418
6419 for (i = 0; i < item.cells.length; i++) {
6420 item.cells[i] = item.cells[i].split(/ *\| */);
6421 }
6422
6423 this$1.tokens.push(item);
6424
6425 continue;
6426 }
6427
6428 // lheading
6429 if (cap = this$1.rules.lheading.exec(src)) {
6430 src = src.substring(cap[0].length);
6431 this$1.tokens.push({
6432 type: 'heading',
6433 depth: cap[2] === '=' ? 1 : 2,
6434 text: cap[1]
6435 });
6436 continue;
6437 }
6438
6439 // hr
6440 if (cap = this$1.rules.hr.exec(src)) {
6441 src = src.substring(cap[0].length);
6442 this$1.tokens.push({
6443 type: 'hr'
6444 });
6445 continue;
6446 }
6447
6448 // blockquote
6449 if (cap = this$1.rules.blockquote.exec(src)) {
6450 src = src.substring(cap[0].length);
6451
6452 this$1.tokens.push({
6453 type: 'blockquote_start'
6454 });
6455
6456 cap = cap[0].replace(/^ *> ?/gm, '');
6457
6458 // Pass `top` to keep the current
6459 // "toplevel" state. This is exactly
6460 // how markdown.pl works.
6461 this$1.token(cap, top, true);
6462
6463 this$1.tokens.push({
6464 type: 'blockquote_end'
6465 });
6466
6467 continue;
6468 }
6469
6470 // list
6471 if (cap = this$1.rules.list.exec(src)) {
6472 src = src.substring(cap[0].length);
6473 bull = cap[2];
6474
6475 this$1.tokens.push({
6476 type: 'list_start',
6477 ordered: bull.length > 1
6478 });
6479
6480 // Get each top-level item.
6481 cap = cap[0].match(this$1.rules.item);
6482
6483 next = false;
6484 l = cap.length;
6485 i = 0;
6486
6487 for (; i < l; i++) {
6488 item = cap[i];
6489
6490 // Remove the list item's bullet
6491 // so it is seen as the next token.
6492 space = item.length;
6493 item = item.replace(/^ *([*+-]|\d+\.) +/, '');
6494
6495 // Outdent whatever the
6496 // list item contains. Hacky.
6497 if (~item.indexOf('\n ')) {
6498 space -= item.length;
6499 item = !this$1.options.pedantic
6500 ? item.replace(new RegExp('^ {1,' + space + '}', 'gm'), '')
6501 : item.replace(/^ {1,4}/gm, '');
6502 }
6503
6504 // Determine whether the next list item belongs here.
6505 // Backpedal if it does not belong in this list.
6506 if (this$1.options.smartLists && i !== l - 1) {
6507 b = block.bullet.exec(cap[i + 1])[0];
6508 if (bull !== b && !(bull.length > 1 && b.length > 1)) {
6509 src = cap.slice(i + 1).join('\n') + src;
6510 i = l - 1;
6511 }
6512 }
6513
6514 // Determine whether item is loose or not.
6515 // Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
6516 // for discount behavior.
6517 loose = next || /\n\n(?!\s*$)/.test(item);
6518 if (i !== l - 1) {
6519 next = item.charAt(item.length - 1) === '\n';
6520 if (!loose) { loose = next; }
6521 }
6522
6523 this$1.tokens.push({
6524 type: loose
6525 ? 'loose_item_start'
6526 : 'list_item_start'
6527 });
6528
6529 // Recurse.
6530 this$1.token(item, false, bq);
6531
6532 this$1.tokens.push({
6533 type: 'list_item_end'
6534 });
6535 }
6536
6537 this$1.tokens.push({
6538 type: 'list_end'
6539 });
6540
6541 continue;
6542 }
6543
6544 // html
6545 if (cap = this$1.rules.html.exec(src)) {
6546 src = src.substring(cap[0].length);
6547 this$1.tokens.push({
6548 type: this$1.options.sanitize
6549 ? 'paragraph'
6550 : 'html',
6551 pre: !this$1.options.sanitizer
6552 && (cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style'),
6553 text: cap[0]
6554 });
6555 continue;
6556 }
6557
6558 // def
6559 if ((!bq && top) && (cap = this$1.rules.def.exec(src))) {
6560 src = src.substring(cap[0].length);
6561 this$1.tokens.links[cap[1].toLowerCase()] = {
6562 href: cap[2],
6563 title: cap[3]
6564 };
6565 continue;
6566 }
6567
6568 // table (gfm)
6569 if (top && (cap = this$1.rules.table.exec(src))) {
6570 src = src.substring(cap[0].length);
6571
6572 item = {
6573 type: 'table',
6574 header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */),
6575 align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */),
6576 cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n')
6577 };
6578
6579 for (i = 0; i < item.align.length; i++) {
6580 if (/^ *-+: *$/.test(item.align[i])) {
6581 item.align[i] = 'right';
6582 } else if (/^ *:-+: *$/.test(item.align[i])) {
6583 item.align[i] = 'center';
6584 } else if (/^ *:-+ *$/.test(item.align[i])) {
6585 item.align[i] = 'left';
6586 } else {
6587 item.align[i] = null;
6588 }
6589 }
6590
6591 for (i = 0; i < item.cells.length; i++) {
6592 item.cells[i] = item.cells[i]
6593 .replace(/^ *\| *| *\| *$/g, '')
6594 .split(/ *\| */);
6595 }
6596
6597 this$1.tokens.push(item);
6598
6599 continue;
6600 }
6601
6602 // top-level paragraph
6603 if (top && (cap = this$1.rules.paragraph.exec(src))) {
6604 src = src.substring(cap[0].length);
6605 this$1.tokens.push({
6606 type: 'paragraph',
6607 text: cap[1].charAt(cap[1].length - 1) === '\n'
6608 ? cap[1].slice(0, -1)
6609 : cap[1]
6610 });
6611 continue;
6612 }
6613
6614 // text
6615 if (cap = this$1.rules.text.exec(src)) {
6616 // Top-level should never reach here.
6617 src = src.substring(cap[0].length);
6618 this$1.tokens.push({
6619 type: 'text',
6620 text: cap[0]
6621 });
6622 continue;
6623 }
6624
6625 if (src) {
6626 throw new
6627 Error('Infinite loop on byte: ' + src.charCodeAt(0));
6628 }
6629 }
6630
6631 return this.tokens;
6632};
6633
6634/**
6635 * Inline-Level Grammar
6636 */
6637
6638var inline = {
6639 escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
6640 autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
6641 url: noop,
6642 tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
6643 link: /^!?\[(inside)\]\(href\)/,
6644 reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
6645 nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
6646 strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
6647 em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
6648 code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
6649 br: /^ {2,}\n(?!\s*$)/,
6650 del: noop,
6651 text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
6652};
6653
6654inline._inside = /(?:\[[^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*/;
6655inline._href = /\s*<?([\s\S]*?)>?(?:\s+['"]([\s\S]*?)['"])?\s*/;
6656
6657inline.link = replace(inline.link)
6658 ('inside', inline._inside)
6659 ('href', inline._href)
6660 ();
6661
6662inline.reflink = replace(inline.reflink)
6663 ('inside', inline._inside)
6664 ();
6665
6666/**
6667 * Normal Inline Grammar
6668 */
6669
6670inline.normal = merge({}, inline);
6671
6672/**
6673 * Pedantic Inline Grammar
6674 */
6675
6676inline.pedantic = merge({}, inline.normal, {
6677 strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
6678 em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/
6679});
6680
6681/**
6682 * GFM Inline Grammar
6683 */
6684
6685inline.gfm = merge({}, inline.normal, {
6686 escape: replace(inline.escape)('])', '~|])')(),
6687 url: /^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/,
6688 del: /^~~(?=\S)([\s\S]*?\S)~~/,
6689 text: replace(inline.text)
6690 (']|', '~]|')
6691 ('|', '|https?://|')
6692 ()
6693});
6694
6695/**
6696 * GFM + Line Breaks Inline Grammar
6697 */
6698
6699inline.breaks = merge({}, inline.gfm, {
6700 br: replace(inline.br)('{2,}', '*')(),
6701 text: replace(inline.gfm.text)('{2,}', '*')()
6702});
6703
6704/**
6705 * Inline Lexer & Compiler
6706 */
6707
6708function InlineLexer(links, options) {
6709 this.options = options || marked.defaults;
6710 this.links = links;
6711 this.rules = inline.normal;
6712 this.renderer = this.options.renderer || new Renderer;
6713 this.renderer.options = this.options;
6714
6715 if (!this.links) {
6716 throw new
6717 Error('Tokens array requires a `links` property.');
6718 }
6719
6720 if (this.options.gfm) {
6721 if (this.options.breaks) {
6722 this.rules = inline.breaks;
6723 } else {
6724 this.rules = inline.gfm;
6725 }
6726 } else if (this.options.pedantic) {
6727 this.rules = inline.pedantic;
6728 }
6729}
6730
6731/**
6732 * Expose Inline Rules
6733 */
6734
6735InlineLexer.rules = inline;
6736
6737/**
6738 * Static Lexing/Compiling Method
6739 */
6740
6741InlineLexer.output = function(src, links, options) {
6742 var inline = new InlineLexer(links, options);
6743 return inline.output(src);
6744};
6745
6746/**
6747 * Lexing/Compiling
6748 */
6749
6750InlineLexer.prototype.output = function(src) {
6751 var this$1 = this;
6752
6753 var out = ''
6754 , link
6755 , text
6756 , href
6757 , cap;
6758
6759 while (src) {
6760 // escape
6761 if (cap = this$1.rules.escape.exec(src)) {
6762 src = src.substring(cap[0].length);
6763 out += cap[1];
6764 continue;
6765 }
6766
6767 // autolink
6768 if (cap = this$1.rules.autolink.exec(src)) {
6769 src = src.substring(cap[0].length);
6770 if (cap[2] === '@') {
6771 text = cap[1].charAt(6) === ':'
6772 ? this$1.mangle(cap[1].substring(7))
6773 : this$1.mangle(cap[1]);
6774 href = this$1.mangle('mailto:') + text;
6775 } else {
6776 text = escape(cap[1]);
6777 href = text;
6778 }
6779 out += this$1.renderer.link(href, null, text);
6780 continue;
6781 }
6782
6783 // url (gfm)
6784 if (!this$1.inLink && (cap = this$1.rules.url.exec(src))) {
6785 src = src.substring(cap[0].length);
6786 text = escape(cap[1]);
6787 href = text;
6788 out += this$1.renderer.link(href, null, text);
6789 continue;
6790 }
6791
6792 // tag
6793 if (cap = this$1.rules.tag.exec(src)) {
6794 if (!this$1.inLink && /^<a /i.test(cap[0])) {
6795 this$1.inLink = true;
6796 } else if (this$1.inLink && /^<\/a>/i.test(cap[0])) {
6797 this$1.inLink = false;
6798 }
6799 src = src.substring(cap[0].length);
6800 out += this$1.options.sanitize
6801 ? this$1.options.sanitizer
6802 ? this$1.options.sanitizer(cap[0])
6803 : escape(cap[0])
6804 : cap[0];
6805 continue;
6806 }
6807
6808 // link
6809 if (cap = this$1.rules.link.exec(src)) {
6810 src = src.substring(cap[0].length);
6811 this$1.inLink = true;
6812 out += this$1.outputLink(cap, {
6813 href: cap[2],
6814 title: cap[3]
6815 });
6816 this$1.inLink = false;
6817 continue;
6818 }
6819
6820 // reflink, nolink
6821 if ((cap = this$1.rules.reflink.exec(src))
6822 || (cap = this$1.rules.nolink.exec(src))) {
6823 src = src.substring(cap[0].length);
6824 link = (cap[2] || cap[1]).replace(/\s+/g, ' ');
6825 link = this$1.links[link.toLowerCase()];
6826 if (!link || !link.href) {
6827 out += cap[0].charAt(0);
6828 src = cap[0].substring(1) + src;
6829 continue;
6830 }
6831 this$1.inLink = true;
6832 out += this$1.outputLink(cap, link);
6833 this$1.inLink = false;
6834 continue;
6835 }
6836
6837 // strong
6838 if (cap = this$1.rules.strong.exec(src)) {
6839 src = src.substring(cap[0].length);
6840 out += this$1.renderer.strong(this$1.output(cap[2] || cap[1]));
6841 continue;
6842 }
6843
6844 // em
6845 if (cap = this$1.rules.em.exec(src)) {
6846 src = src.substring(cap[0].length);
6847 out += this$1.renderer.em(this$1.output(cap[2] || cap[1]));
6848 continue;
6849 }
6850
6851 // code
6852 if (cap = this$1.rules.code.exec(src)) {
6853 src = src.substring(cap[0].length);
6854 out += this$1.renderer.codespan(escape(cap[2], true));
6855 continue;
6856 }
6857
6858 // br
6859 if (cap = this$1.rules.br.exec(src)) {
6860 src = src.substring(cap[0].length);
6861 out += this$1.renderer.br();
6862 continue;
6863 }
6864
6865 // del (gfm)
6866 if (cap = this$1.rules.del.exec(src)) {
6867 src = src.substring(cap[0].length);
6868 out += this$1.renderer.del(this$1.output(cap[1]));
6869 continue;
6870 }
6871
6872 // text
6873 if (cap = this$1.rules.text.exec(src)) {
6874 src = src.substring(cap[0].length);
6875 out += this$1.renderer.text(escape(this$1.smartypants(cap[0])));
6876 continue;
6877 }
6878
6879 if (src) {
6880 throw new
6881 Error('Infinite loop on byte: ' + src.charCodeAt(0));
6882 }
6883 }
6884
6885 return out;
6886};
6887
6888/**
6889 * Compile Link
6890 */
6891
6892InlineLexer.prototype.outputLink = function(cap, link) {
6893 var href = escape(link.href)
6894 , title = link.title ? escape(link.title) : null;
6895
6896 return cap[0].charAt(0) !== '!'
6897 ? this.renderer.link(href, title, this.output(cap[1]))
6898 : this.renderer.image(href, title, escape(cap[1]));
6899};
6900
6901/**
6902 * Smartypants Transformations
6903 */
6904
6905InlineLexer.prototype.smartypants = function(text) {
6906 if (!this.options.smartypants) { return text; }
6907 return text
6908 // em-dashes
6909 .replace(/---/g, '\u2014')
6910 // en-dashes
6911 .replace(/--/g, '\u2013')
6912 // opening singles
6913 .replace(/(^|[-\u2014/(\[{"\s])'/g, '$1\u2018')
6914 // closing singles & apostrophes
6915 .replace(/'/g, '\u2019')
6916 // opening doubles
6917 .replace(/(^|[-\u2014/(\[{\u2018\s])"/g, '$1\u201c')
6918 // closing doubles
6919 .replace(/"/g, '\u201d')
6920 // ellipses
6921 .replace(/\.{3}/g, '\u2026');
6922};
6923
6924/**
6925 * Mangle Links
6926 */
6927
6928InlineLexer.prototype.mangle = function(text) {
6929 if (!this.options.mangle) { return text; }
6930 var out = ''
6931 , l = text.length
6932 , i = 0
6933 , ch;
6934
6935 for (; i < l; i++) {
6936 ch = text.charCodeAt(i);
6937 if (Math.random() > 0.5) {
6938 ch = 'x' + ch.toString(16);
6939 }
6940 out += '&#' + ch + ';';
6941 }
6942
6943 return out;
6944};
6945
6946/**
6947 * Renderer
6948 */
6949
6950function Renderer(options) {
6951 this.options = options || {};
6952}
6953
6954Renderer.prototype.code = function(code, lang, escaped) {
6955 if (this.options.highlight) {
6956 var out = this.options.highlight(code, lang);
6957 if (out != null && out !== code) {
6958 escaped = true;
6959 code = out;
6960 }
6961 }
6962
6963 if (!lang) {
6964 return '<pre><code>'
6965 + (escaped ? code : escape(code, true))
6966 + '\n</code></pre>';
6967 }
6968
6969 return '<pre><code class="'
6970 + this.options.langPrefix
6971 + escape(lang, true)
6972 + '">'
6973 + (escaped ? code : escape(code, true))
6974 + '\n</code></pre>\n';
6975};
6976
6977Renderer.prototype.blockquote = function(quote) {
6978 return '<blockquote>\n' + quote + '</blockquote>\n';
6979};
6980
6981Renderer.prototype.html = function(html) {
6982 return html;
6983};
6984
6985Renderer.prototype.heading = function(text, level, raw) {
6986 return '<h'
6987 + level
6988 + ' id="'
6989 + this.options.headerPrefix
6990 + raw.toLowerCase().replace(/[^\w]+/g, '-')
6991 + '">'
6992 + text
6993 + '</h'
6994 + level
6995 + '>\n';
6996};
6997
6998Renderer.prototype.hr = function() {
6999 return this.options.xhtml ? '<hr/>\n' : '<hr>\n';
7000};
7001
7002Renderer.prototype.list = function(body, ordered) {
7003 var type = ordered ? 'ol' : 'ul';
7004 return '<' + type + '>\n' + body + '</' + type + '>\n';
7005};
7006
7007Renderer.prototype.listitem = function(text) {
7008 return '<li>' + text + '</li>\n';
7009};
7010
7011Renderer.prototype.paragraph = function(text) {
7012 return '<p>' + text + '</p>\n';
7013};
7014
7015Renderer.prototype.table = function(header, body) {
7016 return '<table>\n'
7017 + '<thead>\n'
7018 + header
7019 + '</thead>\n'
7020 + '<tbody>\n'
7021 + body
7022 + '</tbody>\n'
7023 + '</table>\n';
7024};
7025
7026Renderer.prototype.tablerow = function(content) {
7027 return '<tr>\n' + content + '</tr>\n';
7028};
7029
7030Renderer.prototype.tablecell = function(content, flags) {
7031 var type = flags.header ? 'th' : 'td';
7032 var tag = flags.align
7033 ? '<' + type + ' style="text-align:' + flags.align + '">'
7034 : '<' + type + '>';
7035 return tag + content + '</' + type + '>\n';
7036};
7037
7038// span level renderer
7039Renderer.prototype.strong = function(text) {
7040 return '<strong>' + text + '</strong>';
7041};
7042
7043Renderer.prototype.em = function(text) {
7044 return '<em>' + text + '</em>';
7045};
7046
7047Renderer.prototype.codespan = function(text) {
7048 return '<code>' + text + '</code>';
7049};
7050
7051Renderer.prototype.br = function() {
7052 return this.options.xhtml ? '<br/>' : '<br>';
7053};
7054
7055Renderer.prototype.del = function(text) {
7056 return '<del>' + text + '</del>';
7057};
7058
7059Renderer.prototype.link = function(href, title, text) {
7060 if (this.options.sanitize) {
7061 try {
7062 var prot = decodeURIComponent(unescape(href))
7063 .replace(/[^\w:]/g, '')
7064 .toLowerCase();
7065 } catch (e) {
7066 return '';
7067 }
7068 if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0) {
7069 return '';
7070 }
7071 }
7072 var out = '<a href="' + href + '"';
7073 if (title) {
7074 out += ' title="' + title + '"';
7075 }
7076 out += '>' + text + '</a>';
7077 return out;
7078};
7079
7080Renderer.prototype.image = function(href, title, text) {
7081 var out = '<img src="' + href + '" alt="' + text + '"';
7082 if (title) {
7083 out += ' title="' + title + '"';
7084 }
7085 out += this.options.xhtml ? '/>' : '>';
7086 return out;
7087};
7088
7089Renderer.prototype.text = function(text) {
7090 return text;
7091};
7092
7093/**
7094 * Parsing & Compiling
7095 */
7096
7097function Parser(options) {
7098 this.tokens = [];
7099 this.token = null;
7100 this.options = options || marked.defaults;
7101 this.options.renderer = this.options.renderer || new Renderer;
7102 this.renderer = this.options.renderer;
7103 this.renderer.options = this.options;
7104}
7105
7106/**
7107 * Static Parse Method
7108 */
7109
7110Parser.parse = function(src, options, renderer) {
7111 var parser = new Parser(options, renderer);
7112 return parser.parse(src);
7113};
7114
7115/**
7116 * Parse Loop
7117 */
7118
7119Parser.prototype.parse = function(src) {
7120 var this$1 = this;
7121
7122 this.inline = new InlineLexer(src.links, this.options, this.renderer);
7123 this.tokens = src.reverse();
7124
7125 var out = '';
7126 while (this.next()) {
7127 out += this$1.tok();
7128 }
7129
7130 return out;
7131};
7132
7133/**
7134 * Next Token
7135 */
7136
7137Parser.prototype.next = function() {
7138 return this.token = this.tokens.pop();
7139};
7140
7141/**
7142 * Preview Next Token
7143 */
7144
7145Parser.prototype.peek = function() {
7146 return this.tokens[this.tokens.length - 1] || 0;
7147};
7148
7149/**
7150 * Parse Text Tokens
7151 */
7152
7153Parser.prototype.parseText = function() {
7154 var this$1 = this;
7155
7156 var body = this.token.text;
7157
7158 while (this.peek().type === 'text') {
7159 body += '\n' + this$1.next().text;
7160 }
7161
7162 return this.inline.output(body);
7163};
7164
7165/**
7166 * Parse Current Token
7167 */
7168
7169Parser.prototype.tok = function() {
7170 var this$1 = this;
7171
7172 switch (this.token.type) {
7173 case 'space': {
7174 return '';
7175 }
7176 case 'hr': {
7177 return this.renderer.hr();
7178 }
7179 case 'heading': {
7180 return this.renderer.heading(
7181 this.inline.output(this.token.text),
7182 this.token.depth,
7183 this.token.text);
7184 }
7185 case 'code': {
7186 return this.renderer.code(this.token.text,
7187 this.token.lang,
7188 this.token.escaped);
7189 }
7190 case 'table': {
7191 var header = ''
7192 , body = ''
7193 , i
7194 , row
7195 , cell
7196 , flags
7197 , j;
7198
7199 // header
7200 cell = '';
7201 for (i = 0; i < this.token.header.length; i++) {
7202 flags = { header: true, align: this$1.token.align[i] };
7203 cell += this$1.renderer.tablecell(
7204 this$1.inline.output(this$1.token.header[i]),
7205 { header: true, align: this$1.token.align[i] }
7206 );
7207 }
7208 header += this.renderer.tablerow(cell);
7209
7210 for (i = 0; i < this.token.cells.length; i++) {
7211 row = this$1.token.cells[i];
7212
7213 cell = '';
7214 for (j = 0; j < row.length; j++) {
7215 cell += this$1.renderer.tablecell(
7216 this$1.inline.output(row[j]),
7217 { header: false, align: this$1.token.align[j] }
7218 );
7219 }
7220
7221 body += this$1.renderer.tablerow(cell);
7222 }
7223 return this.renderer.table(header, body);
7224 }
7225 case 'blockquote_start': {
7226 var body = '';
7227
7228 while (this.next().type !== 'blockquote_end') {
7229 body += this$1.tok();
7230 }
7231
7232 return this.renderer.blockquote(body);
7233 }
7234 case 'list_start': {
7235 var body = ''
7236 , ordered = this.token.ordered;
7237
7238 while (this.next().type !== 'list_end') {
7239 body += this$1.tok();
7240 }
7241
7242 return this.renderer.list(body, ordered);
7243 }
7244 case 'list_item_start': {
7245 var body = '';
7246
7247 while (this.next().type !== 'list_item_end') {
7248 body += this$1.token.type === 'text'
7249 ? this$1.parseText()
7250 : this$1.tok();
7251 }
7252
7253 return this.renderer.listitem(body);
7254 }
7255 case 'loose_item_start': {
7256 var body = '';
7257
7258 while (this.next().type !== 'list_item_end') {
7259 body += this$1.tok();
7260 }
7261
7262 return this.renderer.listitem(body);
7263 }
7264 case 'html': {
7265 var html = !this.token.pre && !this.options.pedantic
7266 ? this.inline.output(this.token.text)
7267 : this.token.text;
7268 return this.renderer.html(html);
7269 }
7270 case 'paragraph': {
7271 return this.renderer.paragraph(this.inline.output(this.token.text));
7272 }
7273 case 'text': {
7274 return this.renderer.paragraph(this.parseText());
7275 }
7276 }
7277};
7278
7279/**
7280 * Helpers
7281 */
7282
7283function escape(html, encode) {
7284 return html
7285 .replace(!encode ? /&(?!#?\w+;)/g : /&/g, '&amp;')
7286 .replace(/</g, '&lt;')
7287 .replace(/>/g, '&gt;')
7288 .replace(/"/g, '&quot;')
7289 .replace(/'/g, '&#39;');
7290}
7291
7292function unescape(html) {
7293 // explicitly match decimal, hex, and named HTML entities
7294 return html.replace(/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/g, function(_, n) {
7295 n = n.toLowerCase();
7296 if (n === 'colon') { return ':'; }
7297 if (n.charAt(0) === '#') {
7298 return n.charAt(1) === 'x'
7299 ? String.fromCharCode(parseInt(n.substring(2), 16))
7300 : String.fromCharCode(+n.substring(1));
7301 }
7302 return '';
7303 });
7304}
7305
7306function replace(regex, opt) {
7307 regex = regex.source;
7308 opt = opt || '';
7309 return function self(name, val) {
7310 if (!name) { return new RegExp(regex, opt); }
7311 val = val.source || val;
7312 val = val.replace(/(^|[^\[])\^/g, '$1');
7313 regex = regex.replace(name, val);
7314 return self;
7315 };
7316}
7317
7318function noop() {}
7319noop.exec = noop;
7320
7321function merge(obj) {
7322 var arguments$1 = arguments;
7323
7324 var i = 1
7325 , target
7326 , key;
7327
7328 for (; i < arguments.length; i++) {
7329 target = arguments$1[i];
7330 for (key in target) {
7331 if (Object.prototype.hasOwnProperty.call(target, key)) {
7332 obj[key] = target[key];
7333 }
7334 }
7335 }
7336
7337 return obj;
7338}
7339
7340
7341/**
7342 * Marked
7343 */
7344
7345function marked(src, opt, callback) {
7346 if (callback || typeof opt === 'function') {
7347 if (!callback) {
7348 callback = opt;
7349 opt = null;
7350 }
7351
7352 opt = merge({}, marked.defaults, opt || {});
7353
7354 var highlight = opt.highlight
7355 , tokens
7356 , pending
7357 , i = 0;
7358
7359 try {
7360 tokens = Lexer.lex(src, opt);
7361 } catch (e) {
7362 return callback(e);
7363 }
7364
7365 pending = tokens.length;
7366
7367 var done = function(err) {
7368 if (err) {
7369 opt.highlight = highlight;
7370 return callback(err);
7371 }
7372
7373 var out;
7374
7375 try {
7376 out = Parser.parse(tokens, opt);
7377 } catch (e) {
7378 err = e;
7379 }
7380
7381 opt.highlight = highlight;
7382
7383 return err
7384 ? callback(err)
7385 : callback(null, out);
7386 };
7387
7388 if (!highlight || highlight.length < 3) {
7389 return done();
7390 }
7391
7392 delete opt.highlight;
7393
7394 if (!pending) { return done(); }
7395
7396 for (; i < tokens.length; i++) {
7397 (function(token) {
7398 if (token.type !== 'code') {
7399 return --pending || done();
7400 }
7401 return highlight(token.text, token.lang, function(err, code) {
7402 if (err) { return done(err); }
7403 if (code == null || code === token.text) {
7404 return --pending || done();
7405 }
7406 token.text = code;
7407 token.escaped = true;
7408 --pending || done();
7409 });
7410 })(tokens[i]);
7411 }
7412
7413 return;
7414 }
7415 try {
7416 if (opt) { opt = merge({}, marked.defaults, opt); }
7417 return Parser.parse(Lexer.lex(src, opt), opt);
7418 } catch (e) {
7419 e.message += '\nPlease report this to https://github.com/chjj/marked.';
7420 if ((opt || marked.defaults).silent) {
7421 return '<p>An error occured:</p><pre>'
7422 + escape(e.message + '', true)
7423 + '</pre>';
7424 }
7425 throw e;
7426 }
7427}
7428
7429/**
7430 * Options
7431 */
7432
7433marked.options =
7434marked.setOptions = function(opt) {
7435 merge(marked.defaults, opt);
7436 return marked;
7437};
7438
7439marked.defaults = {
7440 gfm: true,
7441 tables: true,
7442 breaks: false,
7443 pedantic: false,
7444 sanitize: false,
7445 sanitizer: null,
7446 mangle: true,
7447 smartLists: false,
7448 silent: false,
7449 highlight: null,
7450 langPrefix: 'lang-',
7451 smartypants: false,
7452 headerPrefix: '',
7453 renderer: new Renderer,
7454 xhtml: false
7455};
7456
7457/**
7458 * Expose
7459 */
7460
7461marked.Parser = Parser;
7462marked.parser = Parser.parse;
7463
7464marked.Renderer = Renderer;
7465
7466marked.Lexer = Lexer;
7467marked.lexer = Lexer.lex;
7468
7469marked.InlineLexer = InlineLexer;
7470marked.inlineLexer = InlineLexer.output;
7471
7472marked.parse = marked;
7473
7474if ('object' !== 'undefined' && 'object' === 'object') {
7475 module.exports = marked;
7476} else if (typeof undefined === 'function' && undefined.amd) {
7477 undefined(function() { return marked; });
7478} else {
7479 this.marked = marked;
7480}
7481
7482}).call(function() {
7483 return this || (typeof window !== 'undefined' ? window : commonjsGlobal);
7484}());
7485});
7486
7487marked.setOptions({
7488 gfm: true,
7489 smartypants: true
7490});
7491
7492var markdown = function(dom, data) {
7493 var markdownElements = [].slice.call(dom.querySelectorAll('[markdown]'));
7494 markdownElements.forEach(function (el) {
7495 var content = el.innerHTML;
7496 // Set default indents
7497 content = content.replace(/\n/, "");
7498 var tabs = content.match(/\s*/);
7499 content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
7500 content = content.trim();
7501
7502 el.innerHTML = marked(content);
7503 });
7504};
7505
7506var prism = createCommonjsModule(function (module) {
7507/* **********************************************
7508 Begin prism-core.js
7509********************************************** */
7510
7511var _self = (typeof window !== 'undefined')
7512 ? window // if in browser
7513 : (
7514 (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)
7515 ? self // if in worker
7516 : {} // if in node js
7517 );
7518
7519/**
7520 * Prism: Lightweight, robust, elegant syntax highlighting
7521 * MIT license http://www.opensource.org/licenses/mit-license.php/
7522 * @author Lea Verou http://lea.verou.me
7523 */
7524
7525var Prism = (function(){
7526
7527// Private helper vars
7528var lang = /\blang(?:uage)?-(\w+)\b/i;
7529var uniqueId = 0;
7530
7531var _ = _self.Prism = {
7532 util: {
7533 encode: function (tokens) {
7534 if (tokens instanceof Token) {
7535 return new Token(tokens.type, _.util.encode(tokens.content), tokens.alias);
7536 } else if (_.util.type(tokens) === 'Array') {
7537 return tokens.map(_.util.encode);
7538 } else {
7539 return tokens.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/\u00a0/g, ' ');
7540 }
7541 },
7542
7543 type: function (o) {
7544 return Object.prototype.toString.call(o).match(/\[object (\w+)\]/)[1];
7545 },
7546
7547 objId: function (obj) {
7548 if (!obj['__id']) {
7549 Object.defineProperty(obj, '__id', { value: ++uniqueId });
7550 }
7551 return obj['__id'];
7552 },
7553
7554 // Deep clone a language definition (e.g. to extend it)
7555 clone: function (o) {
7556 var type = _.util.type(o);
7557
7558 switch (type) {
7559 case 'Object':
7560 var clone = {};
7561
7562 for (var key in o) {
7563 if (o.hasOwnProperty(key)) {
7564 clone[key] = _.util.clone(o[key]);
7565 }
7566 }
7567
7568 return clone;
7569
7570 case 'Array':
7571 // Check for existence for IE8
7572 return o.map && o.map(function(v) { return _.util.clone(v); });
7573 }
7574
7575 return o;
7576 }
7577 },
7578
7579 languages: {
7580 extend: function (id, redef) {
7581 var lang = _.util.clone(_.languages[id]);
7582
7583 for (var key in redef) {
7584 lang[key] = redef[key];
7585 }
7586
7587 return lang;
7588 },
7589
7590 /**
7591 * Insert a token before another token in a language literal
7592 * As this needs to recreate the object (we cannot actually insert before keys in object literals),
7593 * we cannot just provide an object, we need anobject and a key.
7594 * @param inside The key (or language id) of the parent
7595 * @param before The key to insert before. If not provided, the function appends instead.
7596 * @param insert Object with the key/value pairs to insert
7597 * @param root The object that contains `inside`. If equal to Prism.languages, it can be omitted.
7598 */
7599 insertBefore: function (inside, before, insert, root) {
7600 root = root || _.languages;
7601 var grammar = root[inside];
7602
7603 if (arguments.length == 2) {
7604 insert = arguments[1];
7605
7606 for (var newToken in insert) {
7607 if (insert.hasOwnProperty(newToken)) {
7608 grammar[newToken] = insert[newToken];
7609 }
7610 }
7611
7612 return grammar;
7613 }
7614
7615 var ret = {};
7616
7617 for (var token in grammar) {
7618
7619 if (grammar.hasOwnProperty(token)) {
7620
7621 if (token == before) {
7622
7623 for (var newToken in insert) {
7624
7625 if (insert.hasOwnProperty(newToken)) {
7626 ret[newToken] = insert[newToken];
7627 }
7628 }
7629 }
7630
7631 ret[token] = grammar[token];
7632 }
7633 }
7634
7635 // Update references in other language definitions
7636 _.languages.DFS(_.languages, function(key, value) {
7637 if (value === root[inside] && key != inside) {
7638 this[key] = ret;
7639 }
7640 });
7641
7642 return root[inside] = ret;
7643 },
7644
7645 // Traverse a language definition with Depth First Search
7646 DFS: function(o, callback, type, visited) {
7647 visited = visited || {};
7648 for (var i in o) {
7649 if (o.hasOwnProperty(i)) {
7650 callback.call(o, i, o[i], type || i);
7651
7652 if (_.util.type(o[i]) === 'Object' && !visited[_.util.objId(o[i])]) {
7653 visited[_.util.objId(o[i])] = true;
7654 _.languages.DFS(o[i], callback, null, visited);
7655 }
7656 else if (_.util.type(o[i]) === 'Array' && !visited[_.util.objId(o[i])]) {
7657 visited[_.util.objId(o[i])] = true;
7658 _.languages.DFS(o[i], callback, i, visited);
7659 }
7660 }
7661 }
7662 }
7663 },
7664 plugins: {},
7665
7666 highlightAll: function(async, callback) {
7667 var env = {
7668 callback: callback,
7669 selector: 'code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code'
7670 };
7671
7672 _.hooks.run("before-highlightall", env);
7673
7674 var elements = env.elements || document.querySelectorAll(env.selector);
7675
7676 for (var i=0, element; element = elements[i++];) {
7677 _.highlightElement(element, async === true, env.callback);
7678 }
7679 },
7680
7681 highlightElement: function(element, async, callback) {
7682 // Find language
7683 var language, grammar, parent = element;
7684
7685 while (parent && !lang.test(parent.className)) {
7686 parent = parent.parentNode;
7687 }
7688
7689 if (parent) {
7690 language = (parent.className.match(lang) || [,''])[1].toLowerCase();
7691 grammar = _.languages[language];
7692 }
7693
7694 // Set language on the element, if not present
7695 element.className = element.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
7696
7697 // Set language on the parent, for styling
7698 parent = element.parentNode;
7699
7700 if (/pre/i.test(parent.nodeName)) {
7701 parent.className = parent.className.replace(lang, '').replace(/\s+/g, ' ') + ' language-' + language;
7702 }
7703
7704 var code = element.textContent;
7705
7706 var env = {
7707 element: element,
7708 language: language,
7709 grammar: grammar,
7710 code: code
7711 };
7712
7713 _.hooks.run('before-sanity-check', env);
7714
7715 if (!env.code || !env.grammar) {
7716 if (env.code) {
7717 env.element.textContent = env.code;
7718 }
7719 _.hooks.run('complete', env);
7720 return;
7721 }
7722
7723 _.hooks.run('before-highlight', env);
7724
7725 if (async && _self.Worker) {
7726 var worker = new Worker(_.filename);
7727
7728 worker.onmessage = function(evt) {
7729 env.highlightedCode = evt.data;
7730
7731 _.hooks.run('before-insert', env);
7732
7733 env.element.innerHTML = env.highlightedCode;
7734
7735 callback && callback.call(env.element);
7736 _.hooks.run('after-highlight', env);
7737 _.hooks.run('complete', env);
7738 };
7739
7740 worker.postMessage(JSON.stringify({
7741 language: env.language,
7742 code: env.code,
7743 immediateClose: true
7744 }));
7745 }
7746 else {
7747 env.highlightedCode = _.highlight(env.code, env.grammar, env.language);
7748
7749 _.hooks.run('before-insert', env);
7750
7751 env.element.innerHTML = env.highlightedCode;
7752
7753 callback && callback.call(element);
7754
7755 _.hooks.run('after-highlight', env);
7756 _.hooks.run('complete', env);
7757 }
7758 },
7759
7760 highlight: function (text, grammar, language) {
7761 var tokens = _.tokenize(text, grammar);
7762 return Token.stringify(_.util.encode(tokens), language);
7763 },
7764
7765 tokenize: function(text, grammar, language) {
7766 var Token = _.Token;
7767
7768 var strarr = [text];
7769
7770 var rest = grammar.rest;
7771
7772 if (rest) {
7773 for (var token in rest) {
7774 grammar[token] = rest[token];
7775 }
7776
7777 delete grammar.rest;
7778 }
7779
7780 tokenloop: for (var token in grammar) {
7781 if(!grammar.hasOwnProperty(token) || !grammar[token]) {
7782 continue;
7783 }
7784
7785 var patterns = grammar[token];
7786 patterns = (_.util.type(patterns) === "Array") ? patterns : [patterns];
7787
7788 for (var j = 0; j < patterns.length; ++j) {
7789 var pattern = patterns[j],
7790 inside = pattern.inside,
7791 lookbehind = !!pattern.lookbehind,
7792 greedy = !!pattern.greedy,
7793 lookbehindLength = 0,
7794 alias = pattern.alias;
7795
7796 if (greedy && !pattern.pattern.global) {
7797 // Without the global flag, lastIndex won't work
7798 var flags = pattern.pattern.toString().match(/[imuy]*$/)[0];
7799 pattern.pattern = RegExp(pattern.pattern.source, flags + "g");
7800 }
7801
7802 pattern = pattern.pattern || pattern;
7803
7804 // Don’t cache length as it changes during the loop
7805 for (var i=0, pos = 0; i<strarr.length; pos += strarr[i].length, ++i) {
7806
7807 var str = strarr[i];
7808
7809 if (strarr.length > text.length) {
7810 // Something went terribly wrong, ABORT, ABORT!
7811 break tokenloop;
7812 }
7813
7814 if (str instanceof Token) {
7815 continue;
7816 }
7817
7818 pattern.lastIndex = 0;
7819
7820 var match = pattern.exec(str),
7821 delNum = 1;
7822
7823 // Greedy patterns can override/remove up to two previously matched tokens
7824 if (!match && greedy && i != strarr.length - 1) {
7825 pattern.lastIndex = pos;
7826 match = pattern.exec(text);
7827 if (!match) {
7828 break;
7829 }
7830
7831 var from = match.index + (lookbehind ? match[1].length : 0),
7832 to = match.index + match[0].length,
7833 k = i,
7834 p = pos;
7835
7836 for (var len = strarr.length; k < len && p < to; ++k) {
7837 p += strarr[k].length;
7838 // Move the index i to the element in strarr that is closest to from
7839 if (from >= p) {
7840 ++i;
7841 pos = p;
7842 }
7843 }
7844
7845 /*
7846 * If strarr[i] is a Token, then the match starts inside another Token, which is invalid
7847 * If strarr[k - 1] is greedy we are in conflict with another greedy pattern
7848 */
7849 if (strarr[i] instanceof Token || strarr[k - 1].greedy) {
7850 continue;
7851 }
7852
7853 // Number of tokens to delete and replace with the new match
7854 delNum = k - i;
7855 str = text.slice(pos, p);
7856 match.index -= pos;
7857 }
7858
7859 if (!match) {
7860 continue;
7861 }
7862
7863 if(lookbehind) {
7864 lookbehindLength = match[1].length;
7865 }
7866
7867 var from = match.index + lookbehindLength,
7868 match = match[0].slice(lookbehindLength),
7869 to = from + match.length,
7870 before = str.slice(0, from),
7871 after = str.slice(to);
7872
7873 var args = [i, delNum];
7874
7875 if (before) {
7876 args.push(before);
7877 }
7878
7879 var wrapped = new Token(token, inside? _.tokenize(match, inside) : match, alias, match, greedy);
7880
7881 args.push(wrapped);
7882
7883 if (after) {
7884 args.push(after);
7885 }
7886
7887 Array.prototype.splice.apply(strarr, args);
7888 }
7889 }
7890 }
7891
7892 return strarr;
7893 },
7894
7895 hooks: {
7896 all: {},
7897
7898 add: function (name, callback) {
7899 var hooks = _.hooks.all;
7900
7901 hooks[name] = hooks[name] || [];
7902
7903 hooks[name].push(callback);
7904 },
7905
7906 run: function (name, env) {
7907 var callbacks = _.hooks.all[name];
7908
7909 if (!callbacks || !callbacks.length) {
7910 return;
7911 }
7912
7913 for (var i=0, callback; callback = callbacks[i++];) {
7914 callback(env);
7915 }
7916 }
7917 }
7918};
7919
7920var Token = _.Token = function(type, content, alias, matchedStr, greedy) {
7921 this.type = type;
7922 this.content = content;
7923 this.alias = alias;
7924 // Copy of the full string this token was created from
7925 this.length = (matchedStr || "").length|0;
7926 this.greedy = !!greedy;
7927};
7928
7929Token.stringify = function(o, language, parent) {
7930 if (typeof o == 'string') {
7931 return o;
7932 }
7933
7934 if (_.util.type(o) === 'Array') {
7935 return o.map(function(element) {
7936 return Token.stringify(element, language, o);
7937 }).join('');
7938 }
7939
7940 var env = {
7941 type: o.type,
7942 content: Token.stringify(o.content, language, parent),
7943 tag: 'span',
7944 classes: ['token', o.type],
7945 attributes: {},
7946 language: language,
7947 parent: parent
7948 };
7949
7950 if (env.type == 'comment') {
7951 env.attributes['spellcheck'] = 'true';
7952 }
7953
7954 if (o.alias) {
7955 var aliases = _.util.type(o.alias) === 'Array' ? o.alias : [o.alias];
7956 Array.prototype.push.apply(env.classes, aliases);
7957 }
7958
7959 _.hooks.run('wrap', env);
7960
7961 var attributes = Object.keys(env.attributes).map(function(name) {
7962 return name + '="' + (env.attributes[name] || '').replace(/"/g, '&quot;') + '"';
7963 }).join(' ');
7964
7965 return '<' + env.tag + ' class="' + env.classes.join(' ') + '"' + (attributes ? ' ' + attributes : '') + '>' + env.content + '</' + env.tag + '>';
7966
7967};
7968
7969if (!_self.document) {
7970 if (!_self.addEventListener) {
7971 // in Node.js
7972 return _self.Prism;
7973 }
7974 // In worker
7975 _self.addEventListener('message', function(evt) {
7976 var message = JSON.parse(evt.data),
7977 lang = message.language,
7978 code = message.code,
7979 immediateClose = message.immediateClose;
7980
7981 _self.postMessage(_.highlight(code, _.languages[lang], lang));
7982 if (immediateClose) {
7983 _self.close();
7984 }
7985 }, false);
7986
7987 return _self.Prism;
7988}
7989
7990//Get current script and highlight
7991var script = document.currentScript || [].slice.call(document.getElementsByTagName("script")).pop();
7992
7993if (script) {
7994 _.filename = script.src;
7995
7996 if (document.addEventListener && !script.hasAttribute('data-manual')) {
7997 if(document.readyState !== "loading") {
7998 if (window.requestAnimationFrame) {
7999 window.requestAnimationFrame(_.highlightAll);
8000 } else {
8001 window.setTimeout(_.highlightAll, 16);
8002 }
8003 }
8004 else {
8005 document.addEventListener('DOMContentLoaded', _.highlightAll);
8006 }
8007 }
8008}
8009
8010return _self.Prism;
8011
8012})();
8013
8014if ('object' !== 'undefined' && module.exports) {
8015 module.exports = Prism;
8016}
8017
8018// hack for components to work correctly in node.js
8019if (typeof commonjsGlobal !== 'undefined') {
8020 commonjsGlobal.Prism = Prism;
8021}
8022
8023
8024/* **********************************************
8025 Begin prism-markup.js
8026********************************************** */
8027
8028Prism.languages.markup = {
8029 'comment': /<!--[\w\W]*?-->/,
8030 'prolog': /<\?[\w\W]+?\?>/,
8031 'doctype': /<!DOCTYPE[\w\W]+?>/i,
8032 'cdata': /<!\[CDATA\[[\w\W]*?]]>/i,
8033 'tag': {
8034 pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
8035 inside: {
8036 'tag': {
8037 pattern: /^<\/?[^\s>\/]+/i,
8038 inside: {
8039 'punctuation': /^<\/?/,
8040 'namespace': /^[^\s>\/:]+:/
8041 }
8042 },
8043 'attr-value': {
8044 pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
8045 inside: {
8046 'punctuation': /[=>"']/
8047 }
8048 },
8049 'punctuation': /\/?>/,
8050 'attr-name': {
8051 pattern: /[^\s>\/]+/,
8052 inside: {
8053 'namespace': /^[^\s>\/:]+:/
8054 }
8055 }
8056
8057 }
8058 },
8059 'entity': /&#?[\da-z]{1,8};/i
8060};
8061
8062// Plugin to make entity title show the real entity, idea by Roman Komarov
8063Prism.hooks.add('wrap', function(env) {
8064
8065 if (env.type === 'entity') {
8066 env.attributes['title'] = env.content.replace(/&amp;/, '&');
8067 }
8068});
8069
8070Prism.languages.xml = Prism.languages.markup;
8071Prism.languages.html = Prism.languages.markup;
8072Prism.languages.mathml = Prism.languages.markup;
8073Prism.languages.svg = Prism.languages.markup;
8074
8075
8076/* **********************************************
8077 Begin prism-css.js
8078********************************************** */
8079
8080Prism.languages.css = {
8081 'comment': /\/\*[\w\W]*?\*\//,
8082 'atrule': {
8083 pattern: /@[\w-]+?.*?(;|(?=\s*\{))/i,
8084 inside: {
8085 'rule': /@[\w-]+/
8086 // See rest below
8087 }
8088 },
8089 'url': /url\((?:(["'])(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1|.*?)\)/i,
8090 'selector': /[^\{\}\s][^\{\};]*?(?=\s*\{)/,
8091 'string': {
8092 pattern: /("|')(\\(?:\r\n|[\w\W])|(?!\1)[^\\\r\n])*\1/,
8093 greedy: true
8094 },
8095 'property': /(\b|\B)[\w-]+(?=\s*:)/i,
8096 'important': /\B!important\b/i,
8097 'function': /[-a-z0-9]+(?=\()/i,
8098 'punctuation': /[(){};:]/
8099};
8100
8101Prism.languages.css['atrule'].inside.rest = Prism.util.clone(Prism.languages.css);
8102
8103if (Prism.languages.markup) {
8104 Prism.languages.insertBefore('markup', 'tag', {
8105 'style': {
8106 pattern: /(<style[\w\W]*?>)[\w\W]*?(?=<\/style>)/i,
8107 lookbehind: true,
8108 inside: Prism.languages.css,
8109 alias: 'language-css'
8110 }
8111 });
8112
8113 Prism.languages.insertBefore('inside', 'attr-value', {
8114 'style-attr': {
8115 pattern: /\s*style=("|').*?\1/i,
8116 inside: {
8117 'attr-name': {
8118 pattern: /^\s*style/i,
8119 inside: Prism.languages.markup.tag.inside
8120 },
8121 'punctuation': /^\s*=\s*['"]|['"]\s*$/,
8122 'attr-value': {
8123 pattern: /.+/i,
8124 inside: Prism.languages.css
8125 }
8126 },
8127 alias: 'language-css'
8128 }
8129 }, Prism.languages.markup.tag);
8130}
8131
8132/* **********************************************
8133 Begin prism-clike.js
8134********************************************** */
8135
8136Prism.languages.clike = {
8137 'comment': [
8138 {
8139 pattern: /(^|[^\\])\/\*[\w\W]*?\*\//,
8140 lookbehind: true
8141 },
8142 {
8143 pattern: /(^|[^\\:])\/\/.*/,
8144 lookbehind: true
8145 }
8146 ],
8147 'string': {
8148 pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
8149 greedy: true
8150 },
8151 'class-name': {
8152 pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
8153 lookbehind: true,
8154 inside: {
8155 punctuation: /(\.|\\)/
8156 }
8157 },
8158 'keyword': /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
8159 'boolean': /\b(true|false)\b/,
8160 'function': /[a-z0-9_]+(?=\()/i,
8161 'number': /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
8162 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
8163 'punctuation': /[{}[\];(),.:]/
8164};
8165
8166
8167/* **********************************************
8168 Begin prism-javascript.js
8169********************************************** */
8170
8171Prism.languages.javascript = Prism.languages.extend('clike', {
8172 '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/,
8173 'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
8174 // Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
8175 'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i,
8176 'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*\*?|\/|~|\^|%|\.{3}/
8177});
8178
8179Prism.languages.insertBefore('javascript', 'keyword', {
8180 'regex': {
8181 pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
8182 lookbehind: true,
8183 greedy: true
8184 }
8185});
8186
8187Prism.languages.insertBefore('javascript', 'string', {
8188 'template-string': {
8189 pattern: /`(?:\\\\|\\?[^\\])*?`/,
8190 greedy: true,
8191 inside: {
8192 'interpolation': {
8193 pattern: /\$\{[^}]+\}/,
8194 inside: {
8195 'interpolation-punctuation': {
8196 pattern: /^\$\{|\}$/,
8197 alias: 'punctuation'
8198 },
8199 rest: Prism.languages.javascript
8200 }
8201 },
8202 'string': /[\s\S]+/
8203 }
8204 }
8205});
8206
8207if (Prism.languages.markup) {
8208 Prism.languages.insertBefore('markup', 'tag', {
8209 'script': {
8210 pattern: /(<script[\w\W]*?>)[\w\W]*?(?=<\/script>)/i,
8211 lookbehind: true,
8212 inside: Prism.languages.javascript,
8213 alias: 'language-javascript'
8214 }
8215 });
8216}
8217
8218Prism.languages.js = Prism.languages.javascript;
8219
8220/* **********************************************
8221 Begin prism-file-highlight.js
8222********************************************** */
8223
8224(function () {
8225 if (typeof self === 'undefined' || !self.Prism || !self.document || !document.querySelector) {
8226 return;
8227 }
8228
8229 self.Prism.fileHighlight = function() {
8230
8231 var Extensions = {
8232 'js': 'javascript',
8233 'py': 'python',
8234 'rb': 'ruby',
8235 'ps1': 'powershell',
8236 'psm1': 'powershell',
8237 'sh': 'bash',
8238 'bat': 'batch',
8239 'h': 'c',
8240 'tex': 'latex'
8241 };
8242
8243 if(Array.prototype.forEach) { // Check to prevent error in IE8
8244 Array.prototype.slice.call(document.querySelectorAll('pre[data-src]')).forEach(function (pre) {
8245 var src = pre.getAttribute('data-src');
8246
8247 var language, parent = pre;
8248 var lang = /\blang(?:uage)?-(?!\*)(\w+)\b/i;
8249 while (parent && !lang.test(parent.className)) {
8250 parent = parent.parentNode;
8251 }
8252
8253 if (parent) {
8254 language = (pre.className.match(lang) || [, ''])[1];
8255 }
8256
8257 if (!language) {
8258 var extension = (src.match(/\.(\w+)$/) || [, ''])[1];
8259 language = Extensions[extension] || extension;
8260 }
8261
8262 var code = document.createElement('code');
8263 code.className = 'language-' + language;
8264
8265 pre.textContent = '';
8266
8267 code.textContent = 'Loading…';
8268
8269 pre.appendChild(code);
8270
8271 var xhr = new XMLHttpRequest();
8272
8273 xhr.open('GET', src, true);
8274
8275 xhr.onreadystatechange = function () {
8276 if (xhr.readyState == 4) {
8277
8278 if (xhr.status < 400 && xhr.responseText) {
8279 code.textContent = xhr.responseText;
8280
8281 Prism.highlightElement(code);
8282 }
8283 else if (xhr.status >= 400) {
8284 code.textContent = '✖ Error ' + xhr.status + ' while fetching file: ' + xhr.statusText;
8285 }
8286 else {
8287 code.textContent = '✖ Error: File does not exist or is empty';
8288 }
8289 }
8290 };
8291
8292 xhr.send(null);
8293 });
8294 }
8295
8296 };
8297
8298 document.addEventListener('DOMContentLoaded', self.Prism.fileHighlight);
8299
8300})();
8301});
8302
8303var code$1 = function(dom, data) {
8304 var codeElements = [].slice.call(dom.querySelectorAll("dt-code"));
8305 codeElements.forEach(function (el) {
8306 var content = el.textContent;
8307 el.innerHTML = "";
8308 var language = el.getAttribute("language");
8309 var c = dom.createElement("code");
8310 if (el.getAttribute("block") === "") {
8311 // Let's normalize the tab indents
8312 content = content.replace(/\n/, "");
8313 var tabs = content.match(/\s*/);
8314 content = content.replace(new RegExp("\n" + tabs, "g"), "\n");
8315 content = content.trim();
8316 var p = dom.createElement("pre");
8317 p.appendChild(c);
8318 el.appendChild(p);
8319 } else {
8320 el.appendChild(c);
8321 }
8322 var highlighted = content;
8323 if (prism.languages[language]) {
8324 c.setAttribute("class", "language-" + language);
8325 highlighted = prism.highlight(content, prism.languages[language]);
8326 }
8327 c.innerHTML = highlighted;
8328 });
8329};
8330
8331var typeset = function(dom, data) {
8332
8333 var textNodes = dom.createTreeWalker(
8334 dom.body,
8335 dom.defaultView.NodeFilter.SHOW_TEXT
8336 );
8337 while (textNodes.nextNode()) {
8338 var n = textNodes.currentNode,
8339 text = n.nodeValue;
8340 if (text && acceptNode(n)) {
8341 text = quotes(text);
8342 text = punctuation(text);
8343 text = ligatures(text);
8344 n.nodeValue = text;
8345 }
8346 }
8347};
8348
8349function acceptNode(node) {
8350 var parent = node.parentElement;
8351 var isMath = (parent && parent.getAttribute && parent.getAttribute("class")) ? parent.getAttribute("class").includes("katex") || parent.getAttribute("class").includes("MathJax") : false;
8352 return parent &&
8353 parent.nodeName !== "SCRIPT" &&
8354 parent.nodeName !== "STYLE" &&
8355 parent.nodeName !== "CODE" &&
8356 parent.nodeName !== "PRE" &&
8357 parent.nodeName !== "SPAN" &&
8358 parent.nodeName !== "DT-HEADER" &&
8359 parent.nodeName !== "DT-BYLINE" &&
8360 parent.nodeName !== "DT-MATH" &&
8361 parent.nodeName !== "DT-CODE" &&
8362 parent.nodeName !== "DT-BIBLIOGRAPHY" &&
8363 parent.nodeName !== "DT-FOOTER" &&
8364 parent.nodeType !== 8 && //comment nodes
8365 !isMath;
8366}
8367
8368
8369/*!
8370 * typeset - Typesetting for the web
8371 * @version v0.1.6
8372 * @link https://github.com/davidmerfield/Typeset.js
8373 * @author David Merfield
8374 */
8375 // which has a CC0 license
8376 // http://creativecommons.org/publicdomain/zero/1.0/
8377
8378
8379function punctuation(text){
8380
8381 // Dashes
8382 text = text.replace(/--/g, '\u2014');
8383 text = text.replace(/ \u2014 /g,"\u2009\u2014\u2009"); //this has thin spaces
8384
8385 // Elipses
8386 text = text.replace(/\.\.\./g,'…');
8387
8388 // Nbsp for punc with spaces
8389 var NBSP = "\u00a0";
8390 var NBSP_PUNCTUATION_START = /([«¿¡]) /g;
8391 var NBSP_PUNCTUATION_END = / ([\!\?:;\.,‽»])/g;
8392
8393 text = text.replace(NBSP_PUNCTUATION_START, '$1' + NBSP);
8394 text = text.replace(NBSP_PUNCTUATION_END, NBSP + '$1');
8395
8396 return text;
8397}
8398
8399function quotes(text) {
8400
8401 text = text
8402 .replace(/(\W|^)"([^\s\!\?:;\.,‽»])/g, '$1\u201c$2') // beginning "
8403 .replace(/(\u201c[^"]*)"([^"]*$|[^\u201c"]*\u201c)/g, '$1\u201d$2') // ending "
8404 .replace(/([^0-9])"/g,'$1\u201d') // remaining " at end of word
8405 .replace(/(\W|^)'(\S)/g, '$1\u2018$2') // beginning '
8406 .replace(/([a-z])'([a-z])/ig, '$1\u2019$2') // conjunction's possession
8407 .replace(/((\u2018[^']*)|[a-z])'([^0-9]|$)/ig, '$1\u2019$3') // ending '
8408 .replace(/(\u2018)([0-9]{2}[^\u2019]*)(\u2018([^0-9]|$)|$|\u2019[a-z])/ig, '\u2019$2$3') // abbrev. years like '93
8409 .replace(/(\B|^)\u2018(?=([^\u2019]*\u2019\b)*([^\u2019\u2018]*\W[\u2019\u2018]\b|[^\u2019\u2018]*$))/ig, '$1\u2019') // backwards apostrophe
8410 .replace(/'''/g, '\u2034') // triple prime
8411 .replace(/("|'')/g, '\u2033') // double prime
8412 .replace(/'/g, '\u2032');
8413
8414 // Allow escaped quotes
8415 text = text.replace(/\\“/, '\"');
8416 text = text.replace(/\\”/, '\"');
8417 text = text.replace(/\\’/, '\'');
8418 text = text.replace(/\\‘/, '\'');
8419
8420 return text;
8421}
8422
8423function ligatures(text){
8424
8425 text = text.replace(/fi/g, 'fi');
8426 text = text.replace(/fl/g, 'fl');
8427
8428 return text;
8429}
8430
8431var 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 white-s\n opacity: 0.95;\n max-width: ${width}px;\n top: ${top}px;\n left: ${left}px;\n border: 1px solid rgba(0, 0, 0, 0.25);\n padding: ${padding}px;\n border-radius: ${pretty? 3 : 0}px;\n box-shadow: 0px 2px 10px 2px rgba(0, 0, 0, 0.2);\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";
8432
8433var hoverBox = function(dom) {
8434 var s = dom.createElement("script");
8435 s.textContent = code$2;
8436 dom.querySelector("body").appendChild(s);
8437};
8438
8439//import xml from "xml";
8440
8441var generateCrossref = function(data) {
8442
8443
8444 var date = data.publishedDate;
8445
8446 var batch_timestamp = Math.floor(Date.now() / 1000);
8447 var batch_id = data.authors.length ? data.authors[0].lastName.toLowerCase().slice(0,20) : "Anonymous";
8448 batch_id += "_" + date.getFullYear();
8449 batch_id += "_" + data.title.split(" ")[0].toLowerCase().slice(0,20) + "_" + batch_timestamp;
8450 // generate XML
8451 var crf_data =
8452 {doi_batch : [
8453
8454 { _attr: {
8455 version: "4.3.7",
8456 xmlns: "http://www.crossref.org/schema/4.3.7",
8457 "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
8458 "xsi:schemaLocation": "http://www.crossref.org/schema/4.3.7 http://www.crossref.org/schemas/crossref4.3.7.xsd",
8459 }},
8460
8461 { head: [
8462 {doi_batch_id: batch_id},
8463 {timestamp: batch_timestamp},
8464 {depositor: [
8465 {depositor_name: data.journal.publisherName},
8466 {email_address: data.journal.publisherEmail} ]},
8467 {registrant: data.journal.publisherName} ]},
8468
8469 {body: [
8470 {journal: [
8471
8472 {journal_metadata: [
8473 {full_title: data.journal.full_title || data.journal.title},
8474 {abbrev_title: data.journal.abbrev_title || data.journal.title || data.journal.full_title},
8475 {doi_data: [
8476 {doi: data.journal.doi},
8477 {resource: data.journal.url} ]} ]},
8478
8479 {journal_issue: [
8480 {publication_date: [
8481 {month: date.getMonth()+1},
8482 {year: date.getFullYear()} ]},
8483 {journal_volume: [
8484 {volume: data.volume} ]},
8485 {issue: data.issue} ]},
8486
8487 {journal_article: [
8488 {titles: [
8489 {title: data.title} ]},
8490 { contributors:
8491 data.authors.map(function (author, ind) { return (
8492 {person_name: [
8493 { _attr: {
8494 contributor_role: "author",
8495 sequence: (ind == 0)? "first" : "additional"
8496 }},
8497 {given_name: author.firstName},
8498 {surname: author.lastName},
8499 {affiliation: author.affiliation}
8500 // TODO: ORCID?
8501 ]}
8502 ); })
8503 },
8504 {publication_date: [
8505 {month: date.getMonth()+1},
8506 {day: date.getDate()},
8507 {year: date.getFullYear()}
8508 ]},
8509 { publisher_item: [
8510 {item_number: data.doi}
8511 ]},
8512 {doi_data: [
8513 {doi: data.doi},
8514 //{timestamp: ""},
8515 {resource: data.url} ]},
8516 {citation_list:
8517 data.citations.map(function (key) { return citation_xml(key, data.bibliography[key]); })
8518 }
8519
8520 ]} ]} ]} ]};
8521
8522 return xml(crf_data);
8523};
8524
8525function citation_xml(key, ent){
8526 if (ent == undefined) { return {}; }
8527 var info = [];
8528 info.push({_attr: {key: key}});
8529 if ("title" in ent)
8530 { info.push({article_title: ent.title}); }
8531 if ("author" in ent)
8532 { info.push({author: ent.author.split(" and ")[0].split(",")[0].trim()}); }
8533 if ("journal" in ent)
8534 { info.push({journal_title: ent.journal}); }
8535 if ("booktitle" in ent)
8536 { info.push({volume_title: ent.booktitle}); }
8537 if ("volume" in ent)
8538 { info.push({volume: ent.volume}); }
8539 if ("issue" in ent)
8540 { info.push({issue: ent.issue}); }
8541 if ("doi" in ent)
8542 { info.push({doi: ent.doi}); }
8543 return {citation: info}
8544}
8545
8546function xml(obj) {
8547 //console.log(typeof(obj), obj)
8548 if (typeof obj === 'string') { return obj; }
8549 if (typeof obj === 'number') { return ""+obj; }
8550 var keys = Object.keys(obj);
8551 if (keys.length != 1) { console.error("can't interpret ", obj, "as xml"); }
8552 var name = keys[0];
8553 var full_content = obj[name];
8554 var attr = {};
8555 if (Array.isArray(full_content)){
8556 var content = [];
8557 for (var i in full_content) {
8558 var obj = full_content[i];
8559 var obj_name = Object.keys(obj)[0];
8560 if ("_attr" == obj_name) {
8561 attr = obj["_attr"];
8562 } else {
8563 //console.log(Object.keys(obj)[0])
8564 content.push(obj);
8565 }
8566 }
8567 } else {
8568 content = full_content;
8569 }
8570 if (content == undefined){
8571 content = "undefined";
8572 }
8573
8574 var attr_string = "";
8575 for (var k in attr) {
8576 attr_string += " " + k + "=\"" + (attr[k]) + "\"";
8577 }
8578
8579 //console.log(typeof content, Array.isArray(content), content instanceof String, content)
8580 if (Array.isArray(content)){
8581 content = content.map(xml);
8582 content = content.join("\n").split("\n");
8583 content = content.map(function (s) { return " " + s; }).join("\n");
8584 var result = "<" + name + attr_string + ">\n" + content + "\n</" + name + ">";
8585 } else {
8586 content = xml(content);
8587 var result = "<" + name + attr_string + ">" + content + "</" + name + ">";
8588 }
8589 return result;
8590}
8591
8592function renderImmediately(dom) {
8593 html(dom);
8594 styles(dom);
8595}
8596
8597function renderOnLoad(dom, data) {
8598 frontMatter(dom, data);
8599 bibliography(dom, data);
8600 expandData(dom, data);
8601 meta(dom, data);
8602 header(dom, data);
8603 byline(dom, data);
8604 appendix(dom, data);
8605 footer(dom, data);
8606 markdown(dom, data);
8607 code$1(dom, data);
8608 citation(dom, data);
8609 footnote(dom, data);
8610 typeset(dom, data);
8611 hoverBox(dom, data);
8612}
8613
8614// If we are in a browser, render automatically...
8615if(window && window.document) {
8616 var data = {};
8617 renderImmediately(window.document);
8618 window.document.addEventListener("DOMContentLoaded", function (event) {
8619 renderOnLoad(window.document, data);
8620 // Add a banner if we're not on localhost.
8621 if (window.location.hostname !== "localhost" && window.location.origin !== "file://") {
8622 banner(window.document, data);
8623 }
8624 generateCrossref(data);
8625 });
8626}
8627
8628// If we are in node...
8629function render$1(dom, data) {
8630 renderImmediately(dom);
8631 renderOnLoad(dom, data);
8632 // Remove script tag so it doesn't run again in the client
8633 var s = dom.querySelector('script[src="http://distill.pub/template.js"]');
8634 if (s) { s.parentElement.removeChild(s); }
8635}
8636
8637exports.render = render$1;
8638exports.generateCrossref = generateCrossref;
8639
8640Object.defineProperty(exports, '__esModule', { value: true });
8641
8642})));
8643//# sourceMappingURL=template.js.map