UNPKG

spec-md

Version:

Renders Markdown with some additions into an HTML format commonly used for writing technical specification documents. Markdown additions include code syntax highlighting, edit annotations, and the definition of algorithms and grammar productions.

1,788 lines (1,690 loc) 373 kB
/* * Generated by PEG.js 0.10.0. * * http://pegjs.org/ */ "use strict"; function peg$subclass(child, parent) { function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); } function peg$SyntaxError(message, expected, found, location) { this.message = message; this.expected = expected; this.found = found; this.location = location; this.name = "SyntaxError"; if (typeof Error.captureStackTrace === "function") { Error.captureStackTrace(this, peg$SyntaxError); } } peg$subclass(peg$SyntaxError, Error); peg$SyntaxError.buildMessage = function(expected, found) { var DESCRIBE_EXPECTATION_FNS = { literal: function(expectation) { return "\"" + literalEscape(expectation.text) + "\""; }, "class": function(expectation) { var escapedParts = "", i; for (i = 0; i < expectation.parts.length; i++) { escapedParts += expectation.parts[i] instanceof Array ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]); } return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]"; }, any: function(expectation) { return "any character"; }, end: function(expectation) { return "end of input"; }, other: function(expectation) { return expectation.description; } }; function hex(ch) { return ch.charCodeAt(0).toString(16).toUpperCase(); } function literalEscape(s) { return s .replace(/\\/g, '\\\\') .replace(/"/g, '\\"') .replace(/\0/g, '\\0') .replace(/\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); } function classEscape(s) { return s .replace(/\\/g, '\\\\') .replace(/\]/g, '\\]') .replace(/\^/g, '\\^') .replace(/-/g, '\\-') .replace(/\0/g, '\\0') .replace(/\t/g, '\\t') .replace(/\n/g, '\\n') .replace(/\r/g, '\\r') .replace(/[\x00-\x0F]/g, function(ch) { return '\\x0' + hex(ch); }) .replace(/[\x10-\x1F\x7F-\x9F]/g, function(ch) { return '\\x' + hex(ch); }); } function describeExpectation(expectation) { return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation); } function describeExpected(expected) { var descriptions = new Array(expected.length), i, j; for (i = 0; i < expected.length; i++) { descriptions[i] = describeExpectation(expected[i]); } descriptions.sort(); if (descriptions.length > 0) { for (i = 1, j = 1; i < descriptions.length; i++) { if (descriptions[i - 1] !== descriptions[i]) { descriptions[j] = descriptions[i]; j++; } } descriptions.length = j; } switch (descriptions.length) { case 1: return descriptions[0]; case 2: return descriptions[0] + " or " + descriptions[1]; default: return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1]; } } function describeFound(found) { return found ? "\"" + literalEscape(found) + "\"" : "end of input"; } return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found."; }; function peg$parse(input, options) { options = options !== void 0 ? options : {}; var peg$FAILED = {}, peg$startRuleFunctions = { initialDocument: peg$parseinitialDocument, importedDocument: peg$parseimportedDocument }, peg$startRuleFunction = peg$parseinitialDocument, peg$c0 = function(document) { return document; }, peg$c1 = function(comments, title, contents) { return located({ type: 'Document', comments: comments.map(pair => pair[0]), title: title, contents: contents }); }, peg$c2 = function(contents) { return located({ type: 'Document', contents: contents }); }, peg$c3 = "---", peg$c4 = peg$literalExpectation("---", false), peg$c5 = "-", peg$c6 = peg$literalExpectation("-", false), peg$c7 = "===", peg$c8 = peg$literalExpectation("===", false), peg$c9 = "=", peg$c10 = peg$literalExpectation("=", false), peg$c11 = function(value) { return located({ type: 'DocumentTitle', value: format(value) }); }, peg$c12 = "#", peg$c13 = peg$literalExpectation("#", false), peg$c14 = function(value) { return located({ type: 'DocumentTitle', value: value }); }, peg$c15 = "##", peg$c16 = peg$literalExpectation("##", false), peg$c17 = "###", peg$c18 = peg$literalExpectation("###", false), peg$c19 = "####", peg$c20 = peg$literalExpectation("####", false), peg$c21 = "#####", peg$c22 = peg$literalExpectation("#####", false), peg$c23 = "######", peg$c24 = peg$literalExpectation("######", false), peg$c25 = function(text) { return format(text); }, peg$c26 = /^[^\n\r# ]/, peg$c27 = peg$classExpectation(["\n", "\r", "#", " "], true, false), peg$c28 = /^[# ]/, peg$c29 = peg$classExpectation(["#", " "], false, false), peg$c30 = ".", peg$c31 = peg$literalExpectation(".", false), peg$c32 = function(start, rest) { return [start].concat(rest.map(function (nodes) { return nodes[1]; })); }, peg$c33 = /^[0-9]/, peg$c34 = peg$classExpectation([["0", "9"]], false, false), peg$c35 = /^[A-Z]/, peg$c36 = peg$classExpectation([["A", "Z"]], false, false), peg$c37 = "*", peg$c38 = peg$literalExpectation("*", false), peg$c39 = function(secID, title) { return located({ type: 'Header', level: 1, secID: secID, title: title }); }, peg$c40 = function(secID, title) { return located({ type: 'Header', level: 2, secID: secID, title: title }); }, peg$c41 = function(secID, title) { return located({ type: 'Header', level: 3, secID: secID, title: title }); }, peg$c42 = function(secID, title) { return located({ type: 'Header', level: 4, secID: secID, title: title }); }, peg$c43 = function(secID, title) { return located({ type: 'Header', level: 5, secID: secID, title: title }); }, peg$c44 = function(secID, title) { return located({ type: 'Header', level: 6, secID: secID, title: title }); }, peg$c45 = function(header, contents) { return located({ type: 'Section', header: header, contents: contents }); }, peg$c46 = "**", peg$c47 = peg$literalExpectation("**", false), peg$c48 = /^[^\n\r*]/, peg$c49 = peg$classExpectation(["\n", "\r", "*"], true, false), peg$c50 = function(title) { return located({ type: 'Subheader', title: format(title) }); }, peg$c51 = function(header, contents) { return located({ type: 'Subsection', header: header, contents: contents, }); }, peg$c52 = function(blocks) { return blocks.map(block => block[0]); }, peg$c53 = function(block) { return block; }, peg$c54 = function(link) { return link.url.slice(-3) === '.md' && !/^\/([a-z]*:\/\/)/.test(link.url); }, peg$c55 = function(link) { return located({ type: 'Import', path: link.url }); }, peg$c56 = function(importLink) { return importLink; }, peg$c57 = "{++", peg$c58 = peg$literalExpectation("{++", false), peg$c59 = "++}", peg$c60 = peg$literalExpectation("++}", false), peg$c61 = function(contents) { return located({ type: 'BlockIns', contents: contents }); }, peg$c62 = "{--", peg$c63 = peg$literalExpectation("{--", false), peg$c64 = "--}", peg$c65 = peg$literalExpectation("--}", false), peg$c66 = function(contents) { return located({ type: 'BlockDel', contents: contents }); }, peg$c67 = function(name) { if (BLOCK_TAGS_RX.test(name)) { htmlBlockName = name; return true; } }, peg$c68 = function(name, close) { return htmlBlockName === close; }, peg$c69 = function(html) { return located({ type: 'HTMLBlock', name: htmlBlockName, html: html }); }, peg$c70 = /^[^<]/, peg$c71 = peg$classExpectation(["<"], true, false), peg$c72 = function(inner) { return htmlBlockName === inner; }, peg$c73 = function(inner, close) { return htmlBlockName === close; }, peg$c74 = function(open) { return htmlBlockName !== open; }, peg$c75 = function(close) { return htmlBlockName !== close; }, peg$c76 = "<", peg$c77 = peg$literalExpectation("<", false), peg$c78 = /^[a-z]/, peg$c79 = peg$classExpectation([["a", "z"]], false, false), peg$c80 = /^[^>]/, peg$c81 = peg$classExpectation([">"], true, false), peg$c82 = ">", peg$c83 = peg$literalExpectation(">", false), peg$c84 = function(name) { return name; }, peg$c85 = "</", peg$c86 = peg$literalExpectation("</", false), peg$c87 = function(comment) { return comment; }, peg$c88 = function(text) { return located({ type: 'HTMLComment', text: text }); }, peg$c89 = "<!--", peg$c90 = peg$literalExpectation("<!--", false), peg$c91 = "-->", peg$c92 = peg$literalExpectation("-->", false), peg$c93 = /^[^\-]/, peg$c94 = peg$classExpectation(["-"], true, false), peg$c95 = function(term, defs) { return located({ type: 'DefinitionList', term: term, defs: defs.map(pair => pair[1]) }); }, peg$c96 = /^[^\n\r:]/, peg$c97 = peg$classExpectation(["\n", "\r", ":"], true, false), peg$c98 = ":", peg$c99 = peg$literalExpectation(":", false), peg$c100 = function(name) { return located({ type: 'DefinitionTerm', name: format(name) }); }, peg$c101 = function(contents) { return located({ type: 'DefinitionDescription', contents: contents }); }, peg$c102 = /^[^\n\r+\-{`*_[!<\\]/, peg$c103 = peg$classExpectation(["\n", "\r", "+", "-", "{", "`", "*", "_", "[", "!", "<", "\\"], true, false), peg$c104 = "\\", peg$c105 = peg$literalExpectation("\\", false), peg$c106 = peg$anyExpectation(), peg$c107 = "+", peg$c108 = peg$literalExpectation("+", false), peg$c109 = "+}", peg$c110 = peg$literalExpectation("+}", false), peg$c111 = "-}", peg$c112 = peg$literalExpectation("-}", false), peg$c113 = "!", peg$c114 = peg$literalExpectation("!", false), peg$c115 = "[", peg$c116 = peg$literalExpectation("[", false), peg$c117 = function(value) { return formattedText(value); }, peg$c118 = "::", peg$c119 = peg$literalExpectation("::", false), peg$c120 = function(leading, term, trailing) { // Must contain more than just the term. return leading.length + trailing.length > 0; }, peg$c121 = function(leading, term, trailing) { return located({ type: 'DefinitionParagraph', term: term, contents: leading.map(pair => pair[1]).concat([term], trailing) }); }, peg$c122 = /^[*_]/, peg$c123 = peg$classExpectation(["*", "_"], false, false), peg$c124 = function(open, name, close) { return open === close; }, peg$c125 = function(open, name, close) { return located({ type: 'DefinitionTerm', name: format(name) }); }, peg$c126 = function(contents) { return located({ type: 'Paragraph', contents: contents }); }, peg$c127 = "note", peg$c128 = peg$literalExpectation("NOTE", true), peg$c129 = function(contents) { return located({ type: 'Note', contents: contents }); }, peg$c130 = "todo", peg$c131 = peg$literalExpectation("TODO", true), peg$c132 = "tk", peg$c133 = peg$literalExpectation("TK", true), peg$c134 = function(contents) { return located({ type: 'Todo', contents: contents }); }, peg$c135 = function(contents) { return located({ type: 'Bold', contents: contents }); }, peg$c136 = function(contents) { return located({ type: 'Italic', contents: contents }); }, peg$c137 = "_", peg$c138 = peg$literalExpectation("_", false), peg$c139 = function(contents) { return located({ type: 'Ins', contents: contents }); }, peg$c140 = function(contents) { return located({ type: 'Del', contents: contents }); }, peg$c141 = "/", peg$c142 = peg$literalExpectation("/", false), peg$c143 = function(tag) { return located({ type: 'HTMLTag', tag: tag }); }, peg$c144 = "{", peg$c145 = peg$literalExpectation("{", false), peg$c146 = "++", peg$c147 = peg$literalExpectation("++", false), peg$c148 = "--", peg$c149 = peg$literalExpectation("--", false), peg$c150 = "}", peg$c151 = peg$literalExpectation("}", false), peg$c152 = function(ref, close) { if (ref === null || close === null) { error('Malformed {reference}.'); } return ref; }, peg$c153 = "`", peg$c154 = peg$literalExpectation("`", false), peg$c155 = function(code) { // https://spec.commonmark.org/0.29/#code-spans code = code.replace(/\r\n|\n|\r/g, ' ') if (code.startsWith(' ') && code.endsWith(' ') && !code.match(/^\s+$/)) { code = code.slice(1, -1) } return located({ type: 'InlineCode', code: code }); }, peg$c156 = "``", peg$c157 = peg$literalExpectation("``", false), peg$c158 = "```", peg$c159 = peg$literalExpectation("```", false), peg$c160 = function(code) { return code }, peg$c161 = "raw", peg$c162 = peg$literalExpectation("raw", false), peg$c163 = "example", peg$c164 = peg$literalExpectation("example", false), peg$c165 = "counter-example", peg$c166 = peg$literalExpectation("counter-example", false), peg$c167 = /^[^`]/, peg$c168 = peg$classExpectation(["`"], true, false), peg$c169 = function(raw, deprecatedCounterExample, lang, example, code) { // dedent codeblock by current indent level? if (deprecatedCounterExample) { console.warn(line() + ':' + column() + ': Use of `!` is deprecated, use `counter-example` instead.'); } return located({ type: 'Code', raw: raw !== null, lang: lang, example: example !== null, counter: example === 'counter-example' || deprecatedCounterExample !== null, code: code }); }, peg$c170 = /^[\-a-z0-9]/, peg$c171 = peg$classExpectation(["-", ["a", "z"], ["0", "9"]], false, false), peg$c172 = function(lang) { return lang; }, peg$c173 = function(first, rest) { return first !== null }, peg$c174 = function(first, rest) { return located({ type: 'Code', code: [first].concat(rest.map(pair => pair[1])).join('\n') }); }, peg$c175 = function(depth) { return depth >= indent; }, peg$c176 = function(depth, code) { return Array(depth - indent + 1).join(' ') + code; }, peg$c177 = "]", peg$c178 = peg$literalExpectation("]", false), peg$c179 = "(", peg$c180 = peg$literalExpectation("(", false), peg$c181 = ")", peg$c182 = peg$literalExpectation(")", false), peg$c183 = function(contents, url, title) { return located({ type: 'Link', contents: contents, url: url, title: title }); }, peg$c184 = /^[^\n\r+\-{`*!<\]\\]/, peg$c185 = peg$classExpectation(["\n", "\r", "+", "-", "{", "`", "*", "!", "<", "]", "\\"], true, false), peg$c186 = function(rawUrl) { return decodeURI(unescape(rawUrl)); }, peg$c187 = /^[^<>\\\n\r]/, peg$c188 = peg$classExpectation(["<", ">", "\\", "\n", "\r"], true, false), peg$c189 = /^[^\n\r]/, peg$c190 = peg$classExpectation(["\n", "\r"], true, false), peg$c191 = function(rawUrl) { return rawUrl; }, peg$c192 = /^[^()\\ \t\n\r]/, peg$c193 = peg$classExpectation(["(", ")", "\\", " ", "\t", "\n", "\r"], true, false), peg$c194 = /^[^ \t\n\r]/, peg$c195 = peg$classExpectation([" ", "\t", "\n", "\r"], true, false), peg$c196 = function(rawString) { return format(rawString); }, peg$c197 = "\"", peg$c198 = peg$literalExpectation("\"", false), peg$c199 = /^[^"\\\n\r]/, peg$c200 = peg$classExpectation(["\"", "\\", "\n", "\r"], true, false), peg$c201 = /^[\n\r]/, peg$c202 = peg$classExpectation(["\n", "\r"], false, false), peg$c203 = function(value) { return value; }, peg$c204 = "'", peg$c205 = peg$literalExpectation("'", false), peg$c206 = /^[^'\\\n\r]/, peg$c207 = peg$classExpectation(["'", "\\", "\n", "\r"], true, false), peg$c208 = /^[^()\\\n\r]/, peg$c209 = peg$classExpectation(["(", ")", "\\", "\n", "\r"], true, false), peg$c210 = "![", peg$c211 = peg$literalExpectation("![", false), peg$c212 = /^[^\]]/, peg$c213 = peg$classExpectation(["]"], true, false), peg$c214 = "](", peg$c215 = peg$literalExpectation("](", false), peg$c216 = function(alt, url, title) { return located({ type: 'Image', alt: format(alt), url: url, title: title, }); }, peg$c217 = function(list) { return list !== null; }, peg$c218 = function(list) { return list; }, peg$c219 = function(first, rest) { return located({ type: 'List', ordered: false, items: [first].concat(rest.map(pair => pair[1])) }); }, peg$c220 = function(first, rest) { return located({ type: 'List', ordered: true, items: [first].concat(rest.map(pair => pair[1])) }); }, peg$c221 = function(bullet, taskBox, contents, sublist) { if (sublist) { contents = contents.concat([sublist[1]]) } if (taskBox) { return located({ type: 'TaskListItem', done: taskBox.done, contents: contents }); } return located({ type: 'ListItem', contents: contents }); }, peg$c222 = /^[1-9]/, peg$c223 = peg$classExpectation([["1", "9"]], false, false), peg$c224 = " ", peg$c225 = peg$literalExpectation(" ", false), peg$c226 = "x", peg$c227 = peg$literalExpectation("x", false), peg$c228 = "X", peg$c229 = peg$literalExpectation("X", false), peg$c230 = function(done) { return located({ done: done !== ' ' }); }, peg$c231 = function(header, alignments) { return header.cells.length === alignments.length }, peg$c232 = function(header, alignments, rows) { header.alignments = alignments; rows = rows.map(pair => pair[1]); rows.forEach(row => { row.alignments = alignments; if (row.cells.length > header.cells.length) { row.cells.length = header.cells.length; } else while (row.cells.length < header.cells.length) { row.cells.push({ type: 'Text', value: '' }); } }); return located({ type: 'Table', header: header, rows: rows }); }, peg$c233 = /^[ \-]/, peg$c234 = peg$classExpectation([" ", "-"], false, false), peg$c235 = /^[|:]/, peg$c236 = peg$classExpectation(["|", ":"], false, false), peg$c237 = /^[ |:\-]/, peg$c238 = peg$classExpectation([" ", "|", ":", "-"], false, false), peg$c239 = function(cells) { return located({ type: 'TableHeader', cells: cells }); }, peg$c240 = function(cells) { return located({ type: 'TableRow', cells: cells }); }, peg$c241 = "|", peg$c242 = peg$literalExpectation("|", false), peg$c243 = function(first, rest) { return [first].concat(rest.map(pair => pair[1])); }, peg$c244 = function(left, right) { return left && right ? 'center' : left ? 'left' : right ? 'right' : null; }, peg$c245 = function(contents) { return contents; }, peg$c246 = /^[^ |\n\r+\-{`*[!<]/, peg$c247 = peg$classExpectation([" ", "|", "\n", "\r", "+", "-", "{", "`", "*", "[", "!", "<"], true, false), peg$c248 = /^[ |\n\r]/, peg$c249 = peg$classExpectation([" ", "|", "\n", "\r"], false, false), peg$c250 = "\\_", peg$c251 = peg$literalExpectation("\\_", false), peg$c252 = /^[_a-z]/, peg$c253 = peg$classExpectation(["_", ["a", "z"]], false, false), peg$c254 = function(name) { return unescape(name); }, peg$c255 = /^[_a-zA-Z0-9]/, peg$c256 = peg$classExpectation(["_", ["a", "z"], ["A", "Z"], ["0", "9"]], false, false), peg$c257 = function(call, steps) { return located({ type: 'Algorithm', call: call, steps: orderify(steps) }); }, peg$c258 = function(name, args) { return located({ type: 'Call', name: name, args: args }); }, peg$c259 = function() { return []; }, peg$c260 = ",", peg$c261 = peg$literalExpectation(",", false), peg$c262 = function(first, rest) { return [first].concat(rest.map(nodes => nodes[3])); }, peg$c263 = "\\\"", peg$c264 = peg$literalExpectation("\\\"", false), peg$c265 = /^[^"\n\r]/, peg$c266 = peg$classExpectation(["\"", "\n", "\r"], true, false), peg$c267 = function(value, closer) { if (closer === null) { error('Unclosed string literal.'); } return located({ type: 'StringLiteral', // Unescape all but quote characters within a string literal. value: '"' + unescape(value).replace(/"/g, '\\"') + '"' }); }, peg$c268 = "null", peg$c269 = peg$literalExpectation("null", false), peg$c270 = "true", peg$c271 = peg$literalExpectation("true", false), peg$c272 = "false", peg$c273 = peg$literalExpectation("false", false), peg$c274 = "undefined", peg$c275 = peg$literalExpectation("undefined", false), peg$c276 = function(value) { return located({ type: 'Keyword', value: value }); }, peg$c277 = function(name) { return located({ type: 'Variable', name: name }); }, peg$c278 = ":::", peg$c279 = peg$literalExpectation(":::", false), peg$c280 = "one of", peg$c281 = peg$literalExpectation("one of", false), peg$c282 = function(name, defType, tokens, steps) { return located({ type: 'Semantic', name: name, defType: defType.length, rhs: { type: 'RHS', tokens: tokens }, steps: orderify(steps) }); }, peg$c283 = function(token, defType, rhs) { return located({ type: 'Production', token: token, defType: defType.length, rhs: rhs }); }, peg$c284 = function(rhs) { return rhs; }, peg$c285 = function(rows) { return located({ type: 'OneOfRHS', rows: rows.map(row => row[1].map(tokens => tokens[1])) }); }, peg$c286 = function(condition, tokens) { return located({ type: 'RHS', condition: condition ? condition[0] : null, tokens: tokens }); }, peg$c287 = function(first, rest) { return located({ type: 'ListRHS', defs: [first].concat(rest.map(pair => pair[1])) }); }, peg$c288 = "~", peg$c289 = peg$literalExpectation("~", false), peg$c290 = "if", peg$c291 = peg$literalExpectation("if", false), peg$c292 = "not", peg$c293 = peg$literalExpectation("not", false), peg$c294 = function(condition, param) { return located({ type: 'Condition', param: param, not: condition === '~' || condition.indexOf('not') !== -1 }); }, peg$c295 = function(first, rest) { return [first].concat(rest.map(nodes => nodes[1])); }, peg$c296 = "?", peg$c297 = peg$literalExpectation("?", false), peg$c298 = function(token, quantifier, constraint) { if (quantifier) { token = located({ type: 'Quantified', token: token, isList: quantifier[1] === '+' || quantifier[1] === '*', isOptional: quantifier[1] === '?' || quantifier[1] === '*' }); } if (constraint) { token = located({ type: 'Constrained', token: token, constraint: constraint[1] }); } return token; }, peg$c299 = function(text, closer) { if (closer === null) { error('Unclosed quoted prose.'); } return located({ type: 'Prose', text: format(text) }); }, peg$c300 = "empty", peg$c301 = peg$literalExpectation("empty", false), peg$c302 = function() { return located({ type: 'Empty' }); }, peg$c303 = "lookahead", peg$c304 = peg$literalExpectation("lookahead", false), peg$c305 = "!=", peg$c306 = peg$literalExpectation("!=", false), peg$c307 = function(not, set, closer) { if (set === null || closer === null) { error('Malformed lookahead. Did you forget tokens?'); } return located({ type: 'Lookahead', not: not !== null, nt: set.length === 1 && set[0].type === 'NonTerminal', set: set }); }, peg$c308 = function(set, closer) { if (set === null || closer === null) { error('Malformed lookahead set. Did you forget tokens?'); } return set.map(nodes => nodes[2]); }, peg$c309 = function(token) { return [token]; }, peg$c310 = function(name, params) { return located({ type: 'NonTerminal', name: name, params: params, }); }, peg$c311 = function(params, param, closer) { if (param === null || closer === null) { error('Malformed terminal params.'); } return params.map(param => param[0]).concat(param); }, peg$c312 = /^[?!]/, peg$c313 = peg$classExpectation(["?", "!"], false, false), peg$c314 = function(conditional, name) { return located({ type: 'NonTerminalParam', conditional: conditional === '?', negated: conditional === '!', name: name }); }, peg$c315 = "but", peg$c316 = peg$literalExpectation("but", false), peg$c317 = "one", peg$c318 = peg$literalExpectation("one", false), peg$c319 = "of", peg$c320 = peg$literalExpectation("of", false), peg$c321 = "or", peg$c322 = peg$literalExpectation("or", false), peg$c323 = function(first, rest) { return located({ type: 'ButNot', tokens: [first].concat(rest.map(nodes => nodes[3])) }); }, peg$c324 = /^[^\/\n\r]/, peg$c325 = peg$classExpectation(["/", "\n", "\r"], true, false), peg$c326 = "\\/", peg$c327 = peg$literalExpectation("\\/", false), peg$c328 = function(value, closer) { if (value === null || closer === null) { error('Malformed regular expression.'); } return located({ type: 'RegExp', value: '/' + unescape(value) + '/' }); }, peg$c329 = function(inlineCode) { return located({ type: 'Terminal', value: inlineCode.code }); }, peg$c330 = /^[^ \n\r"\/`]/, peg$c331 = peg$classExpectation([" ", "\n", "\r", "\"", "/", "`"], true, false), peg$c332 = /^[^ \n\r"`,\]}]/, peg$c333 = peg$classExpectation([" ", "\n", "\r", "\"", "`", ",", "]", "}"], true, false), peg$c334 = function(value) { return located({ type: 'Terminal', value: unescape(value) }); }, peg$c335 = function(depth) { return depth >= indent && depth < indent + 4; }, peg$c336 = function(depth) { return depth >= indent + 2; }, peg$c337 = function(depth) { indentStack.push(indent); indent = depth; }, peg$c338 = function(depth) { return depth >= indent + 4; }, peg$c339 = function(depth) { indentStack.push(indent); indent = indent + 4; }, peg$c340 = function() { indentStack.length === 0 }, peg$c341 = function() { indent = indentStack.pop(); }, peg$c342 = function(sp) { return sp.replace(/\t/g, ' ').length; }, peg$c343 = /^[ \t]/, peg$c344 = peg$classExpectation([" ", "\t"], false, false), peg$c345 = "\n", peg$c346 = peg$literalExpectation("\n", false), peg$c347 = "\r\n", peg$c348 = peg$literalExpectation("\r\n", false), peg$c349 = "\r", peg$c350 = peg$literalExpectation("\r", false), peg$c351 = /^[a-zA-Z0-9]/, peg$c352 = peg$classExpectation([["a", "z"], ["A", "Z"], ["0", "9"]], false, false), peg$currPos = 0, peg$savedPos = 0, peg$posDetailsCache = [{ line: 1, column: 1 }], peg$maxFailPos = 0, peg$maxFailExpected = [], peg$silentFails = 0, peg$result; if ("startRule" in options) { if (!(options.startRule in peg$startRuleFunctions)) { throw new Error("Can't start parsing from rule \"" + options.startRule + "\"."); } peg$startRuleFunction = peg$startRuleFunctions[options.startRule]; } function text() { return input.substring(peg$savedPos, peg$currPos); } function location() { return peg$computeLocation(peg$savedPos, peg$currPos); } function expected(description, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) throw peg$buildStructuredError( [peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location ); } function error(message, location) { location = location !== void 0 ? location : peg$computeLocation(peg$savedPos, peg$currPos) throw peg$buildSimpleError(message, location); } function peg$literalExpectation(text, ignoreCase) { return { type: "literal", text: text, ignoreCase: ignoreCase }; } function peg$classExpectation(parts, inverted, ignoreCase) { return { type: "class", parts: parts, inverted: inverted, ignoreCase: ignoreCase }; } function peg$anyExpectation() { return { type: "any" }; } function peg$endExpectation() { return { type: "end" }; } function peg$otherExpectation(description) { return { type: "other", description: description }; } function peg$computePosDetails(pos) { var details = peg$posDetailsCache[pos], p; if (details) { return details; } else { p = pos - 1; while (!peg$posDetailsCache[p]) { p--; } details = peg$posDetailsCache[p]; details = { line: details.line, column: details.column }; while (p < pos) { if (input.charCodeAt(p) === 10) { details.line++; details.column = 1; } else { details.column++; } p++; } peg$posDetailsCache[pos] = details; return details; } } function peg$computeLocation(startPos, endPos) { var startPosDetails = peg$computePosDetails(startPos), endPosDetails = peg$computePosDetails(endPos); return { start: { offset: startPos, line: startPosDetails.line, column: startPosDetails.column }, end: { offset: endPos, line: endPosDetails.line, column: endPosDetails.column } }; } function peg$fail(expected) { if (peg$currPos < peg$maxFailPos) { return; } if (peg$currPos > peg$maxFailPos) { peg$maxFailPos = peg$currPos; peg$maxFailExpected = []; } peg$maxFailExpected.push(expected); } function peg$buildSimpleError(message, location) { return new peg$SyntaxError(message, null, null, location); } function peg$buildStructuredError(expected, found, location) { return new peg$SyntaxError( peg$SyntaxError.buildMessage(expected, found), expected, found, location ); } function peg$parseinitialDocument() { var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parse___(); if (s1 !== peg$FAILED) { s2 = peg$parsetitledDocument(); if (s2 !== peg$FAILED) { s3 = peg$parseEOF(); if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c0(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseimportedDocument() { var s0, s1, s2, s3; s0 = peg$currPos; s1 = peg$parse___(); if (s1 !== peg$FAILED) { s2 = peg$parseuntitledDocument(); if (s2 !== peg$FAILED) { s3 = peg$parseEOF(); if (s3 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c0(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsetitledDocument() { var s0, s1, s2, s3, s4; s0 = peg$currPos; s1 = []; s2 = peg$currPos; s3 = peg$parsehtmlComment(); if (s3 !== peg$FAILED) { s4 = peg$parse___(); if (s4 !== peg$FAILED) { s3 = [s3, s4]; s2 = s3; } else { peg$currPos = s2; s2 = peg$FAILED; } } else { peg$currPos = s2; s2 = peg$FAILED; } while (s2 !== peg$FAILED) { s1.push(s2); s2 = peg$currPos; s3 = peg$parsehtmlComment(); if (s3 !== peg$FAILED) { s4 = peg$parse___(); if (s4 !== peg$FAILED) { s3 = [s3, s4]; s2 = s3; } else { peg$currPos = s2; s2 = peg$FAILED; } } else { peg$currPos = s2; s2 = peg$FAILED; } } if (s1 !== peg$FAILED) { s2 = peg$parsetitle(); if (s2 !== peg$FAILED) { s3 = peg$parse___(); if (s3 !== peg$FAILED) { s4 = peg$parsedocumentBlocks(); if (s4 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c1(s1, s2, s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseuntitledDocument() { var s0, s1; s0 = peg$currPos; s1 = peg$parsedocumentBlocks(); if (s1 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c2(s1); } s0 = s1; return s0; } function peg$parsetitle() { var s0; s0 = peg$parsemarkdownTitle(); if (s0 === peg$FAILED) { s0 = peg$parsesetextTitle(); } return s0; } function peg$parsesetextTitle() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; s1 = peg$parseSAMEDENT(); if (s1 !== peg$FAILED) { s2 = peg$currPos; s3 = []; s4 = peg$parseNOT_NL(); if (s4 !== peg$FAILED) { while (s4 !== peg$FAILED) { s3.push(s4); s4 = peg$parseNOT_NL(); } } else { s3 = peg$FAILED; } if (s3 !== peg$FAILED) { s2 = input.substring(s2, peg$currPos); } else { s2 = s3; } if (s2 !== peg$FAILED) { s3 = peg$parseNL(); if (s3 !== peg$FAILED) { s4 = peg$currPos; if (input.substr(peg$currPos, 3) === peg$c3) { s5 = peg$c3; peg$currPos += 3; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c4); } } if (s5 !== peg$FAILED) { s6 = []; if (input.charCodeAt(peg$currPos) === 45) { s7 = peg$c5; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c6); } } while (s7 !== peg$FAILED) { s6.push(s7); if (input.charCodeAt(peg$currPos) === 45) { s7 = peg$c5; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c6); } } } if (s6 !== peg$FAILED) { s5 = [s5, s6]; s4 = s5; } else { peg$currPos = s4; s4 = peg$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } if (s4 === peg$FAILED) { s4 = peg$currPos; if (input.substr(peg$currPos, 3) === peg$c7) { s5 = peg$c7; peg$currPos += 3; } else { s5 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c8); } } if (s5 !== peg$FAILED) { s6 = []; if (input.charCodeAt(peg$currPos) === 61) { s7 = peg$c9; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c10); } } while (s7 !== peg$FAILED) { s6.push(s7); if (input.charCodeAt(peg$currPos) === 61) { s7 = peg$c9; peg$currPos++; } else { s7 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c10); } } } if (s6 !== peg$FAILED) { s5 = [s5, s6]; s4 = s5; } else { peg$currPos = s4; s4 = peg$FAILED; } } else { peg$currPos = s4; s4 = peg$FAILED; } } if (s4 !== peg$FAILED) { s5 = peg$currPos; peg$silentFails++; s6 = peg$parseEOL(); peg$silentFails--; if (s6 !== peg$FAILED) { peg$currPos = s5; s5 = void 0; } else { s5 = peg$FAILED; } if (s5 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c11(s2); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parsemarkdownTitle() { var s0, s1, s2, s3, s4, s5, s6, s7; s0 = peg$currPos; s1 = peg$parseSAMEDENT(); if (s1 !== peg$FAILED) { s2 = []; if (input.charCodeAt(peg$currPos) === 35) { s3 = peg$c12; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s3 !== peg$FAILED) { while (s3 !== peg$FAILED) { s2.push(s3); if (input.charCodeAt(peg$currPos) === 35) { s3 = peg$c12; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } } } else { s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s4 = peg$parseheaderText(); if (s4 !== peg$FAILED) { s5 = peg$parseH_END(); if (s5 !== peg$FAILED) { s6 = peg$currPos; peg$silentFails++; s7 = peg$parseEOL(); peg$silentFails--; if (s7 !== peg$FAILED) { peg$currPos = s6; s6 = void 0; } else { s6 = peg$FAILED; } if (s6 !== peg$FAILED) { peg$savedPos = s0; s1 = peg$c14(s4); s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseheaderLookahead() { var s0, s1, s2, s3; s0 = peg$currPos; peg$silentFails++; s1 = peg$currPos; s2 = peg$parseSAMEDENT(); if (s2 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 35) { s3 = peg$c12; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s3 !== peg$FAILED) { s2 = [s2, s3]; s1 = s2; } else { peg$currPos = s1; s1 = peg$FAILED; } } else { peg$currPos = s1; s1 = peg$FAILED; } peg$silentFails--; if (s1 !== peg$FAILED) { peg$currPos = s0; s0 = void 0; } else { s0 = peg$FAILED; } return s0; } function peg$parseH1() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.charCodeAt(peg$currPos) === 35) { s1 = peg$c12; peg$currPos++; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 35) { s3 = peg$c12; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } peg$silentFails--; if (s3 === peg$FAILED) { s2 = void 0; } else { peg$currPos = s2; s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseH2() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.substr(peg$currPos, 2) === peg$c15) { s1 = peg$c15; peg$currPos += 2; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c16); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 35) { s3 = peg$c12; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } peg$silentFails--; if (s3 === peg$FAILED) { s2 = void 0; } else { peg$currPos = s2; s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseH3() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.substr(peg$currPos, 3) === peg$c17) { s1 = peg$c17; peg$currPos += 3; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c18); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 35) { s3 = peg$c12; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } peg$silentFails--; if (s3 === peg$FAILED) { s2 = void 0; } else { peg$currPos = s2; s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseH4() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.substr(peg$currPos, 4) === peg$c19) { s1 = peg$c19; peg$currPos += 4; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c20); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 35) { s3 = peg$c12; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } peg$silentFails--; if (s3 === peg$FAILED) { s2 = void 0; } else { peg$currPos = s2; s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseH5() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.substr(peg$currPos, 5) === peg$c21) { s1 = peg$c21; peg$currPos += 5; } else { s1 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c22); } } if (s1 !== peg$FAILED) { s2 = peg$currPos; peg$silentFails++; if (input.charCodeAt(peg$currPos) === 35) { s3 = peg$c12; peg$currPos++; } else { s3 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } peg$silentFails--; if (s3 === peg$FAILED) { s2 = void 0; } else { peg$currPos = s2; s2 = peg$FAILED; } if (s2 !== peg$FAILED) { s3 = peg$parse_(); if (s3 !== peg$FAILED) { s1 = [s1, s2, s3]; s0 = s1; } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } } else { peg$currPos = s0; s0 = peg$FAILED; } return s0; } function peg$parseH6() { var s0, s1, s2, s3; s0 = peg$currPos; if (input.substr(peg$currPos, 6) ==