LCOV - code coverage report
Current view: top level - external - remarkable-wikilink.js (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 641 4182 15.3 %
Date: 2021-03-12 10:43:40 Functions: 4 184 2.2 %

          Line data    Source code
       1           2 : function getDefaultExportFromNamespaceIfNotNamed(n) {
       2           0 :     return n && Object.prototype.hasOwnProperty.call(n, "default") && Object.keys(n).length === 1 ? n["default"] : n;
       3           1 : }
       4           1 : const mod = function() {
       5           2 :     var textarea;
       6           0 :     function decodeEntity(name) {
       7           0 :         textarea = textarea || document.createElement("textarea");
       8           0 :         textarea.innerHTML = "&" + name + ";";
       9           0 :         return textarea.value;
      10           0 :     }
      11           0 :     function typeOf(obj) {
      12           0 :         return Object.prototype.toString.call(obj);
      13           0 :     }
      14           0 :     function isString(obj) {
      15           0 :         return typeOf(obj) === "[object String]";
      16           0 :     }
      17           2 :     var hasOwn = Object.prototype.hasOwnProperty;
      18           0 :     function has(object, key) {
      19           0 :         return object ? hasOwn.call(object, key) : false;
      20           0 :     }
      21           0 :     function assign(obj) {
      22           0 :         var sources = [].slice.call(arguments, 1);
      23           0 :         sources.forEach(function(source) {
      24           0 :             if (!source) {
      25           0 :                 return;
      26           0 :             }
      27           0 :             if (typeof source !== "object") {
      28           0 :                 throw new TypeError(source + "must be object");
      29           0 :             }
      30           0 :             Object.keys(source).forEach(function(key) {
      31           0 :                 obj[key] = source[key];
      32           0 :             });
      33           0 :         });
      34           0 :         return obj;
      35           0 :     }
      36           2 :     var UNESCAPE_MD_RE = /\\([\\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;
      37           0 :     function unescapeMd(str) {
      38           0 :         if (str.indexOf("\\") < 0) {
      39           0 :             return str;
      40           0 :         }
      41           0 :         return str.replace(UNESCAPE_MD_RE, "$1");
      42           0 :     }
      43           0 :     function isValidEntityCode(c) {
      44           0 :         if (c >= 55296 && c <= 57343) {
      45           0 :             return false;
      46           0 :         }
      47           0 :         if (c >= 64976 && c <= 65007) {
      48           0 :             return false;
      49           0 :         }
      50           0 :         if ((c & 65535) === 65535 || (c & 65535) === 65534) {
      51           0 :             return false;
      52           0 :         }
      53           0 :         if (c >= 0 && c <= 8) {
      54           0 :             return false;
      55           0 :         }
      56           0 :         if (c === 11) {
      57           0 :             return false;
      58           0 :         }
      59           0 :         if (c >= 14 && c <= 31) {
      60           0 :             return false;
      61           0 :         }
      62           0 :         if (c >= 127 && c <= 159) {
      63           0 :             return false;
      64           0 :         }
      65           0 :         if (c > 1114111) {
      66           0 :             return false;
      67           0 :         }
      68           0 :         return true;
      69           0 :     }
      70           0 :     function fromCodePoint(c) {
      71           0 :         if (c > 65535) {
      72           0 :             c -= 65536;
      73           0 :             var surrogate1 = 55296 + (c >> 10), surrogate2 = 56320 + (c & 1023);
      74           0 :             return String.fromCharCode(surrogate1, surrogate2);
      75           0 :         }
      76           0 :         return String.fromCharCode(c);
      77           0 :     }
      78           2 :     var NAMED_ENTITY_RE = /&([a-z#][a-z0-9]{1,31});/gi;
      79           2 :     var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))/i;
      80           0 :     function replaceEntityPattern(match, name) {
      81           0 :         var code2 = 0;
      82           0 :         var decoded = decodeEntity(name);
      83           0 :         if (name !== decoded) {
      84           0 :             return decoded;
      85           0 :         } else if (name.charCodeAt(0) === 35 && DIGITAL_ENTITY_TEST_RE.test(name)) {
      86           0 :             code2 = name[1].toLowerCase() === "x" ? parseInt(name.slice(2), 16) : parseInt(name.slice(1), 10);
      87           0 :             if (isValidEntityCode(code2)) {
      88           0 :                 return fromCodePoint(code2);
      89           0 :             }
      90           0 :         }
      91           0 :         return match;
      92           0 :     }
      93           0 :     function replaceEntities(str) {
      94           0 :         if (str.indexOf("&") < 0) {
      95           0 :             return str;
      96           0 :         }
      97           0 :         return str.replace(NAMED_ENTITY_RE, replaceEntityPattern);
      98           0 :     }
      99           2 :     var HTML_ESCAPE_TEST_RE = /[&<>"]/;
     100           2 :     var HTML_ESCAPE_REPLACE_RE = /[&<>"]/g;
     101           2 :     var HTML_REPLACEMENTS = {
     102           2 :         "&": "&amp;",
     103           2 :         "<": "&lt;",
     104           2 :         ">": "&gt;",
     105           2 :         '"': "&quot;"
     106           2 :     };
     107           0 :     function replaceUnsafeChar(ch) {
     108           0 :         return HTML_REPLACEMENTS[ch];
     109           0 :     }
     110           0 :     function escapeHtml(str) {
     111           0 :         if (HTML_ESCAPE_TEST_RE.test(str)) {
     112           0 :             return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
     113           0 :         }
     114           0 :         return str;
     115           0 :     }
     116           2 :     var utils = Object.freeze({
     117           2 :         isString,
     118           2 :         has,
     119           2 :         assign,
     120           2 :         unescapeMd,
     121           2 :         isValidEntityCode,
     122           2 :         fromCodePoint,
     123           2 :         replaceEntities,
     124           2 :         escapeHtml
     125           2 :     });
     126           2 :     const utils1 = utils;
     127           2 :     var rules = {
     128           2 :     };
     129           0 :     rules.blockquote_open = function() {
     130           0 :         return "<blockquote>\n";
     131           0 :     };
     132           0 :     rules.blockquote_close = function(tokens, idx) {
     133           0 :         return "</blockquote>" + getBreak(tokens, idx);
     134           0 :     };
     135           0 :     rules.code = function(tokens, idx) {
     136           0 :         if (tokens[idx].block) {
     137           0 :             return "<pre><code>" + escapeHtml(tokens[idx].content) + "</code></pre>" + getBreak(tokens, idx);
     138           0 :         }
     139           0 :         return "<code>" + escapeHtml(tokens[idx].content) + "</code>";
     140           0 :     };
     141           0 :     rules.fence = function(tokens, idx, options, env, instance) {
     142           0 :         var token = tokens[idx];
     143           0 :         var langClass = "";
     144           0 :         var langPrefix = options.langPrefix;
     145           0 :         var langName = "", fences2, fenceName;
     146           0 :         var highlighted;
     147           0 :         if (token.params) {
     148           0 :             fences2 = token.params.split(/\s+/g);
     149           0 :             fenceName = fences2.join(" ");
     150           0 :             if (has(instance.rules.fence_custom, fences2[0])) {
     151           0 :                 return instance.rules.fence_custom[fences2[0]](tokens, idx, options, env, instance);
     152           0 :             }
     153           0 :             langName = escapeHtml(replaceEntities(unescapeMd(fenceName)));
     154           0 :             langClass = ' class="' + langPrefix + langName + '"';
     155           0 :         }
     156           0 :         if (options.highlight) {
     157           0 :             highlighted = options.highlight.apply(options.highlight, [
     158           0 :                 token.content
     159           0 :             ].concat(fences2)) || escapeHtml(token.content);
     160           0 :         } else {
     161           0 :             highlighted = escapeHtml(token.content);
     162           0 :         }
     163           0 :         return "<pre><code" + langClass + ">" + highlighted + "</code></pre>" + getBreak(tokens, idx);
     164           0 :     };
     165           2 :     rules.fence_custom = {
     166           2 :     };
     167           0 :     rules.heading_open = function(tokens, idx) {
     168           0 :         return "<h" + tokens[idx].hLevel + ">";
     169           0 :     };
     170           0 :     rules.heading_close = function(tokens, idx) {
     171           0 :         return "</h" + tokens[idx].hLevel + ">\n";
     172           0 :     };
     173           0 :     rules.hr = function(tokens, idx, options) {
     174           0 :         return (options.xhtmlOut ? "<hr />" : "<hr>") + getBreak(tokens, idx);
     175           0 :     };
     176           0 :     rules.bullet_list_open = function() {
     177           0 :         return "<ul>\n";
     178           0 :     };
     179           0 :     rules.bullet_list_close = function(tokens, idx) {
     180           0 :         return "</ul>" + getBreak(tokens, idx);
     181           0 :     };
     182           0 :     rules.list_item_open = function() {
     183           0 :         return "<li>";
     184           0 :     };
     185           0 :     rules.list_item_close = function() {
     186           0 :         return "</li>\n";
     187           0 :     };
     188           0 :     rules.ordered_list_open = function(tokens, idx) {
     189           0 :         var token = tokens[idx];
     190           0 :         var order = token.order > 1 ? ' start="' + token.order + '"' : "";
     191           0 :         return "<ol" + order + ">\n";
     192           0 :     };
     193           0 :     rules.ordered_list_close = function(tokens, idx) {
     194           0 :         return "</ol>" + getBreak(tokens, idx);
     195           0 :     };
     196           0 :     rules.paragraph_open = function(tokens, idx) {
     197           0 :         return tokens[idx].tight ? "" : "<p>";
     198           0 :     };
     199           0 :     rules.paragraph_close = function(tokens, idx) {
     200           0 :         var addBreak = !(tokens[idx].tight && idx && tokens[idx - 1].type === "inline" && !tokens[idx - 1].content);
     201           0 :         return (tokens[idx].tight ? "" : "</p>") + (addBreak ? getBreak(tokens, idx) : "");
     202           0 :     };
     203           0 :     rules.link_open = function(tokens, idx, options) {
     204           0 :         var title = tokens[idx].title ? ' title="' + escapeHtml(replaceEntities(tokens[idx].title)) + '"' : "";
     205           0 :         var target = options.linkTarget ? ' target="' + options.linkTarget + '"' : "";
     206           0 :         return '<a href="' + escapeHtml(tokens[idx].href) + '"' + title + target + ">";
     207           0 :     };
     208           0 :     rules.link_close = function() {
     209           0 :         return "</a>";
     210           0 :     };
     211           0 :     rules.image = function(tokens, idx, options) {
     212           0 :         var src = ' src="' + escapeHtml(tokens[idx].src) + '"';
     213           0 :         var title = tokens[idx].title ? ' title="' + escapeHtml(replaceEntities(tokens[idx].title)) + '"' : "";
     214           0 :         var alt = ' alt="' + (tokens[idx].alt ? escapeHtml(replaceEntities(unescapeMd(tokens[idx].alt))) : "") + '"';
     215           0 :         var suffix = options.xhtmlOut ? " /" : "";
     216           0 :         return "<img" + src + alt + title + suffix + ">";
     217           0 :     };
     218           0 :     rules.table_open = function() {
     219           0 :         return "<table>\n";
     220           0 :     };
     221           0 :     rules.table_close = function() {
     222           0 :         return "</table>\n";
     223           0 :     };
     224           0 :     rules.thead_open = function() {
     225           0 :         return "<thead>\n";
     226           0 :     };
     227           0 :     rules.thead_close = function() {
     228           0 :         return "</thead>\n";
     229           0 :     };
     230           0 :     rules.tbody_open = function() {
     231           0 :         return "<tbody>\n";
     232           0 :     };
     233           0 :     rules.tbody_close = function() {
     234           0 :         return "</tbody>\n";
     235           0 :     };
     236           0 :     rules.tr_open = function() {
     237           0 :         return "<tr>";
     238           0 :     };
     239           0 :     rules.tr_close = function() {
     240           0 :         return "</tr>\n";
     241           0 :     };
     242           0 :     rules.th_open = function(tokens, idx) {
     243           0 :         var token = tokens[idx];
     244           0 :         return "<th" + (token.align ? ' style="text-align:' + token.align + '"' : "") + ">";
     245           0 :     };
     246           0 :     rules.th_close = function() {
     247           0 :         return "</th>";
     248           0 :     };
     249           0 :     rules.td_open = function(tokens, idx) {
     250           0 :         var token = tokens[idx];
     251           0 :         return "<td" + (token.align ? ' style="text-align:' + token.align + '"' : "") + ">";
     252           0 :     };
     253           0 :     rules.td_close = function() {
     254           0 :         return "</td>";
     255           0 :     };
     256           0 :     rules.strong_open = function() {
     257           0 :         return "<strong>";
     258           0 :     };
     259           0 :     rules.strong_close = function() {
     260           0 :         return "</strong>";
     261           0 :     };
     262           0 :     rules.em_open = function() {
     263           0 :         return "<em>";
     264           0 :     };
     265           0 :     rules.em_close = function() {
     266           0 :         return "</em>";
     267           0 :     };
     268           0 :     rules.del_open = function() {
     269           0 :         return "<del>";
     270           0 :     };
     271           0 :     rules.del_close = function() {
     272           0 :         return "</del>";
     273           0 :     };
     274           0 :     rules.ins_open = function() {
     275           0 :         return "<ins>";
     276           0 :     };
     277           0 :     rules.ins_close = function() {
     278           0 :         return "</ins>";
     279           0 :     };
     280           0 :     rules.mark_open = function() {
     281           0 :         return "<mark>";
     282           0 :     };
     283           0 :     rules.mark_close = function() {
     284           0 :         return "</mark>";
     285           0 :     };
     286           0 :     rules.sub = function(tokens, idx) {
     287           0 :         return "<sub>" + escapeHtml(tokens[idx].content) + "</sub>";
     288           0 :     };
     289           0 :     rules.sup = function(tokens, idx) {
     290           0 :         return "<sup>" + escapeHtml(tokens[idx].content) + "</sup>";
     291           0 :     };
     292           0 :     rules.hardbreak = function(tokens, idx, options) {
     293           0 :         return options.xhtmlOut ? "<br />\n" : "<br>\n";
     294           0 :     };
     295           0 :     rules.softbreak = function(tokens, idx, options) {
     296           0 :         return options.breaks ? options.xhtmlOut ? "<br />\n" : "<br>\n" : "\n";
     297           0 :     };
     298           0 :     rules.text = function(tokens, idx) {
     299           0 :         return escapeHtml(tokens[idx].content);
     300           0 :     };
     301           0 :     rules.htmlblock = function(tokens, idx) {
     302           0 :         return tokens[idx].content;
     303           0 :     };
     304           0 :     rules.htmltag = function(tokens, idx) {
     305           0 :         return tokens[idx].content;
     306           0 :     };
     307           0 :     rules.abbr_open = function(tokens, idx) {
     308           0 :         return '<abbr title="' + escapeHtml(replaceEntities(tokens[idx].title)) + '">';
     309           0 :     };
     310           0 :     rules.abbr_close = function() {
     311           0 :         return "</abbr>";
     312           0 :     };
     313           0 :     rules.footnote_ref = function(tokens, idx) {
     314           0 :         var n = Number(tokens[idx].id + 1).toString();
     315           0 :         var id = "fnref" + n;
     316           0 :         if (tokens[idx].subId > 0) {
     317           0 :             id += ":" + tokens[idx].subId;
     318           0 :         }
     319           0 :         return '<sup class="footnote-ref"><a href="#fn' + n + '" id="' + id + '">[' + n + "]</a></sup>";
     320           0 :     };
     321           0 :     rules.footnote_block_open = function(tokens, idx, options) {
     322           0 :         var hr2 = options.xhtmlOut ? '<hr class="footnotes-sep" />\n' : '<hr class="footnotes-sep">\n';
     323           0 :         return hr2 + '<section class="footnotes">\n<ol class="footnotes-list">\n';
     324           0 :     };
     325           0 :     rules.footnote_block_close = function() {
     326           0 :         return "</ol>\n</section>\n";
     327           0 :     };
     328           0 :     rules.footnote_open = function(tokens, idx) {
     329           0 :         var id = Number(tokens[idx].id + 1).toString();
     330           0 :         return '<li id="fn' + id + '"  class="footnote-item">';
     331           0 :     };
     332           0 :     rules.footnote_close = function() {
     333           0 :         return "</li>\n";
     334           0 :     };
     335           0 :     rules.footnote_anchor = function(tokens, idx) {
     336           0 :         var n = Number(tokens[idx].id + 1).toString();
     337           0 :         var id = "fnref" + n;
     338           0 :         if (tokens[idx].subId > 0) {
     339           0 :             id += ":" + tokens[idx].subId;
     340           0 :         }
     341           0 :         return ' <a href="#' + id + '" class="footnote-backref">\u21A9</a>';
     342           0 :     };
     343           0 :     rules.dl_open = function() {
     344           0 :         return "<dl>\n";
     345           0 :     };
     346           0 :     rules.dt_open = function() {
     347           0 :         return "<dt>";
     348           0 :     };
     349           0 :     rules.dd_open = function() {
     350           0 :         return "<dd>";
     351           0 :     };
     352           0 :     rules.dl_close = function() {
     353           0 :         return "</dl>\n";
     354           0 :     };
     355           0 :     rules.dt_close = function() {
     356           0 :         return "</dt>\n";
     357           0 :     };
     358           0 :     rules.dd_close = function() {
     359           0 :         return "</dd>\n";
     360           0 :     };
     361           0 :     function nextToken(tokens, idx) {
     362           0 :         if ((++idx) >= tokens.length - 2) {
     363           0 :             return idx;
     364           0 :         }
     365           0 :         if (tokens[idx].type === "paragraph_open" && tokens[idx].tight && (tokens[idx + 1].type === "inline" && tokens[idx + 1].content.length === 0) && (tokens[idx + 2].type === "paragraph_close" && tokens[idx + 2].tight)) {
     366           0 :             return nextToken(tokens, idx + 2);
     367           0 :         }
     368           0 :         return idx;
     369           0 :     }
     370           0 :     var getBreak = rules.getBreak = function getBreak2(tokens, idx) {
     371           0 :         idx = nextToken(tokens, idx);
     372           0 :         if (idx < tokens.length && tokens[idx].type === "list_item_close") {
     373           0 :             return "";
     374           0 :         }
     375           0 :         return "\n";
     376           0 :     };
     377           0 :     function Renderer() {
     378           0 :         this.rules = assign({
     379           0 :         }, rules);
     380           0 :         this.getBreak = rules.getBreak;
     381           0 :     }
     382           0 :     Renderer.prototype.renderInline = function(tokens, options, env) {
     383           0 :         var _rules2 = this.rules;
     384           0 :         var len = tokens.length, i = 0;
     385           0 :         var result = "";
     386           0 :         while(len--){
     387           0 :             result += _rules2[tokens[i].type](tokens, i++, options, env, this);
     388           0 :         }
     389           0 :         return result;
     390           0 :     };
     391           0 :     Renderer.prototype.render = function(tokens, options, env) {
     392           0 :         var _rules2 = this.rules;
     393           0 :         var len = tokens.length, i = -1;
     394           0 :         var result = "";
     395           0 :         while((++i) < len){
     396           0 :             if (tokens[i].type === "inline") {
     397           0 :                 result += this.renderInline(tokens[i].children, options, env);
     398           0 :             } else {
     399           0 :                 result += _rules2[tokens[i].type](tokens, i, options, env, this);
     400           0 :             }
     401           0 :         }
     402           0 :         return result;
     403           0 :     };
     404           0 :     function Ruler() {
     405           0 :         this.__rules__ = [];
     406           0 :         this.__cache__ = null;
     407           0 :     }
     408           0 :     Ruler.prototype.__find__ = function(name) {
     409           0 :         var len = this.__rules__.length;
     410           0 :         var i = -1;
     411           0 :         while(len--){
     412           0 :             if (this.__rules__[++i].name === name) {
     413           0 :                 return i;
     414           0 :             }
     415           0 :         }
     416           0 :         return -1;
     417           0 :     };
     418           0 :     Ruler.prototype.__compile__ = function() {
     419           0 :         var self = this;
     420           0 :         var chains = [
     421           0 :             ""
     422           0 :         ];
     423           0 :         self.__rules__.forEach(function(rule) {
     424           0 :             if (!rule.enabled) {
     425           0 :                 return;
     426           0 :             }
     427           0 :             rule.alt.forEach(function(altName) {
     428           0 :                 if (chains.indexOf(altName) < 0) {
     429           0 :                     chains.push(altName);
     430           0 :                 }
     431           0 :             });
     432           0 :         });
     433           0 :         self.__cache__ = {
     434           0 :         };
     435           0 :         chains.forEach(function(chain) {
     436           0 :             self.__cache__[chain] = [];
     437           0 :             self.__rules__.forEach(function(rule) {
     438           0 :                 if (!rule.enabled) {
     439           0 :                     return;
     440           0 :                 }
     441           0 :                 if (chain && rule.alt.indexOf(chain) < 0) {
     442           0 :                     return;
     443           0 :                 }
     444           0 :                 self.__cache__[chain].push(rule.fn);
     445           0 :             });
     446           0 :         });
     447           0 :     };
     448           0 :     Ruler.prototype.at = function(name, fn, options) {
     449           0 :         var idx = this.__find__(name);
     450           0 :         var opt = options || {
     451           0 :         };
     452           0 :         if (idx === -1) {
     453           0 :             throw new Error("Parser rule not found: " + name);
     454           0 :         }
     455           0 :         this.__rules__[idx].fn = fn;
     456           0 :         this.__rules__[idx].alt = opt.alt || [];
     457           0 :         this.__cache__ = null;
     458           0 :     };
     459           0 :     Ruler.prototype.before = function(beforeName, ruleName, fn, options) {
     460           0 :         var idx = this.__find__(beforeName);
     461           0 :         var opt = options || {
     462           0 :         };
     463           0 :         if (idx === -1) {
     464           0 :             throw new Error("Parser rule not found: " + beforeName);
     465           0 :         }
     466           0 :         this.__rules__.splice(idx, 0, {
     467           0 :             name: ruleName,
     468           0 :             enabled: true,
     469           0 :             fn,
     470           0 :             alt: opt.alt || []
     471           0 :         });
     472           0 :         this.__cache__ = null;
     473           0 :     };
     474           0 :     Ruler.prototype.after = function(afterName, ruleName, fn, options) {
     475           0 :         var idx = this.__find__(afterName);
     476           0 :         var opt = options || {
     477           0 :         };
     478           0 :         if (idx === -1) {
     479           0 :             throw new Error("Parser rule not found: " + afterName);
     480           0 :         }
     481           0 :         this.__rules__.splice(idx + 1, 0, {
     482           0 :             name: ruleName,
     483           0 :             enabled: true,
     484           0 :             fn,
     485           0 :             alt: opt.alt || []
     486           0 :         });
     487           0 :         this.__cache__ = null;
     488           0 :     };
     489           0 :     Ruler.prototype.push = function(ruleName, fn, options) {
     490           0 :         var opt = options || {
     491           0 :         };
     492           0 :         this.__rules__.push({
     493           0 :             name: ruleName,
     494           0 :             enabled: true,
     495           0 :             fn,
     496           0 :             alt: opt.alt || []
     497           0 :         });
     498           0 :         this.__cache__ = null;
     499           0 :     };
     500           0 :     Ruler.prototype.enable = function(list2, strict) {
     501           0 :         list2 = !Array.isArray(list2) ? [
     502           0 :             list2
     503           0 :         ] : list2;
     504           0 :         if (strict) {
     505           0 :             this.__rules__.forEach(function(rule) {
     506           0 :                 rule.enabled = false;
     507           0 :             });
     508           0 :         }
     509           0 :         list2.forEach(function(name) {
     510           0 :             var idx = this.__find__(name);
     511           0 :             if (idx < 0) {
     512           0 :                 throw new Error("Rules manager: invalid rule name " + name);
     513           0 :             }
     514           0 :             this.__rules__[idx].enabled = true;
     515           0 :         }, this);
     516           0 :         this.__cache__ = null;
     517           0 :     };
     518           0 :     Ruler.prototype.disable = function(list2) {
     519           0 :         list2 = !Array.isArray(list2) ? [
     520           0 :             list2
     521           0 :         ] : list2;
     522           0 :         list2.forEach(function(name) {
     523           0 :             var idx = this.__find__(name);
     524           0 :             if (idx < 0) {
     525           0 :                 throw new Error("Rules manager: invalid rule name " + name);
     526           0 :             }
     527           0 :             this.__rules__[idx].enabled = false;
     528           0 :         }, this);
     529           0 :         this.__cache__ = null;
     530           0 :     };
     531           0 :     Ruler.prototype.getRules = function(chainName) {
     532           0 :         if (this.__cache__ === null) {
     533           0 :             this.__compile__();
     534           0 :         }
     535           0 :         return this.__cache__[chainName] || [];
     536           0 :     };
     537           0 :     function block(state) {
     538           0 :         if (state.inlineMode) {
     539           0 :             state.tokens.push({
     540           0 :                 type: "inline",
     541           0 :                 content: state.src.replace(/\n/g, " ").trim(),
     542           0 :                 level: 0,
     543           0 :                 lines: [
     544           0 :                     0,
     545           0 :                     1
     546           0 :                 ],
     547           0 :                 children: []
     548           0 :             });
     549           0 :         } else {
     550           0 :             state.block.parse(state.src, state.options, state.env, state.tokens);
     551           0 :         }
     552           0 :     }
     553           0 :     function StateInline(src, parserInline, options, env, outTokens) {
     554           0 :         this.src = src;
     555           0 :         this.env = env;
     556           0 :         this.options = options;
     557           0 :         this.parser = parserInline;
     558           0 :         this.tokens = outTokens;
     559           0 :         this.pos = 0;
     560           0 :         this.posMax = this.src.length;
     561           0 :         this.level = 0;
     562           0 :         this.pending = "";
     563           0 :         this.pendingLevel = 0;
     564           0 :         this.cache = [];
     565           0 :         this.isInLabel = false;
     566           0 :         this.linkLevel = 0;
     567           0 :         this.linkContent = "";
     568           0 :         this.labelUnmatchedScopes = 0;
     569           0 :     }
     570           0 :     StateInline.prototype.pushPending = function() {
     571           0 :         this.tokens.push({
     572           0 :             type: "text",
     573           0 :             content: this.pending,
     574           0 :             level: this.pendingLevel
     575           0 :         });
     576           0 :         this.pending = "";
     577           0 :     };
     578           0 :     StateInline.prototype.push = function(token) {
     579           0 :         if (this.pending) {
     580           0 :             this.pushPending();
     581           0 :         }
     582           0 :         this.tokens.push(token);
     583           0 :         this.pendingLevel = this.level;
     584           0 :     };
     585           0 :     StateInline.prototype.cacheSet = function(key, val) {
     586           0 :         for(var i = this.cache.length; i <= key; i++){
     587           0 :             this.cache.push(0);
     588           0 :         }
     589           0 :         this.cache[key] = val;
     590           0 :     };
     591           0 :     StateInline.prototype.cacheGet = function(key) {
     592           0 :         return key < this.cache.length ? this.cache[key] : 0;
     593           0 :     };
     594           0 :     function parseLinkLabel(state, start) {
     595           0 :         var level, found, marker, labelEnd = -1, max = state.posMax, oldPos = state.pos, oldFlag = state.isInLabel;
     596           0 :         if (state.isInLabel) {
     597           0 :             return -1;
     598           0 :         }
     599           0 :         if (state.labelUnmatchedScopes) {
     600           0 :             state.labelUnmatchedScopes--;
     601           0 :             return -1;
     602           0 :         }
     603           0 :         state.pos = start + 1;
     604           0 :         state.isInLabel = true;
     605           0 :         level = 1;
     606           0 :         while(state.pos < max){
     607           0 :             marker = state.src.charCodeAt(state.pos);
     608           0 :             if (marker === 91) {
     609           0 :                 level++;
     610           0 :             } else if (marker === 93) {
     611           0 :                 level--;
     612           0 :                 if (level === 0) {
     613           0 :                     found = true;
     614           0 :                     break;
     615           0 :                 }
     616           0 :             }
     617           0 :             state.parser.skipToken(state);
     618           0 :         }
     619           0 :         if (found) {
     620           0 :             labelEnd = state.pos;
     621           0 :             state.labelUnmatchedScopes = 0;
     622           0 :         } else {
     623           0 :             state.labelUnmatchedScopes = level - 1;
     624           0 :         }
     625           0 :         state.pos = oldPos;
     626           0 :         state.isInLabel = oldFlag;
     627           0 :         return labelEnd;
     628           0 :     }
     629           0 :     function parseAbbr(str, parserInline, options, env) {
     630           0 :         var state, labelEnd, pos, max, label, title;
     631           0 :         if (str.charCodeAt(0) !== 42) {
     632           0 :             return -1;
     633           0 :         }
     634           0 :         if (str.charCodeAt(1) !== 91) {
     635           0 :             return -1;
     636           0 :         }
     637           0 :         if (str.indexOf("]:") === -1) {
     638           0 :             return -1;
     639           0 :         }
     640           0 :         state = new StateInline(str, parserInline, options, env, []);
     641           0 :         labelEnd = parseLinkLabel(state, 1);
     642           0 :         if (labelEnd < 0 || str.charCodeAt(labelEnd + 1) !== 58) {
     643           0 :             return -1;
     644           0 :         }
     645           0 :         max = state.posMax;
     646           0 :         for(pos = labelEnd + 2; pos < max; pos++){
     647           0 :             if (state.src.charCodeAt(pos) === 10) {
     648           0 :                 break;
     649           0 :             }
     650           0 :         }
     651           0 :         label = str.slice(2, labelEnd);
     652           0 :         title = str.slice(labelEnd + 2, pos).trim();
     653           0 :         if (title.length === 0) {
     654           0 :             return -1;
     655           0 :         }
     656           0 :         if (!env.abbreviations) {
     657           0 :             env.abbreviations = {
     658           0 :             };
     659           0 :         }
     660           0 :         if (typeof env.abbreviations[":" + label] === "undefined") {
     661           0 :             env.abbreviations[":" + label] = title;
     662           0 :         }
     663           0 :         return pos;
     664           0 :     }
     665           0 :     function abbr(state) {
     666           0 :         var tokens = state.tokens, i, l, content, pos;
     667           0 :         if (state.inlineMode) {
     668           0 :             return;
     669           0 :         }
     670           0 :         for(i = 1, l = tokens.length - 1; i < l; i++){
     671           0 :             if (tokens[i - 1].type === "paragraph_open" && tokens[i].type === "inline" && tokens[i + 1].type === "paragraph_close") {
     672           0 :                 content = tokens[i].content;
     673           0 :                 while(content.length){
     674           0 :                     pos = parseAbbr(content, state.inline, state.options, state.env);
     675           0 :                     if (pos < 0) {
     676           0 :                         break;
     677           0 :                     }
     678           0 :                     content = content.slice(pos).trim();
     679           0 :                 }
     680           0 :                 tokens[i].content = content;
     681           0 :                 if (!content.length) {
     682           0 :                     tokens[i - 1].tight = true;
     683           0 :                     tokens[i + 1].tight = true;
     684           0 :                 }
     685           0 :             }
     686           0 :         }
     687           0 :     }
     688           0 :     function normalizeLink(url) {
     689           0 :         var normalized = replaceEntities(url);
     690           0 :         try {
     691           0 :             normalized = decodeURI(normalized);
     692           0 :         } catch (err) {
     693           0 :         }
     694           0 :         return encodeURI(normalized);
     695           0 :     }
     696           0 :     function parseLinkDestination(state, pos) {
     697           0 :         var code2, level, link, start = pos, max = state.posMax;
     698           0 :         if (state.src.charCodeAt(pos) === 60) {
     699           0 :             pos++;
     700           0 :             while(pos < max){
     701           0 :                 code2 = state.src.charCodeAt(pos);
     702           0 :                 if (code2 === 10) {
     703           0 :                     return false;
     704           0 :                 }
     705           0 :                 if (code2 === 62) {
     706           0 :                     link = normalizeLink(unescapeMd(state.src.slice(start + 1, pos)));
     707           0 :                     if (!state.parser.validateLink(link)) {
     708           0 :                         return false;
     709           0 :                     }
     710           0 :                     state.pos = pos + 1;
     711           0 :                     state.linkContent = link;
     712           0 :                     return true;
     713           0 :                 }
     714           0 :                 if (code2 === 92 && pos + 1 < max) {
     715           0 :                     pos += 2;
     716           0 :                     continue;
     717           0 :                 }
     718           0 :                 pos++;
     719           0 :             }
     720           0 :             return false;
     721           0 :         }
     722           0 :         level = 0;
     723           0 :         while(pos < max){
     724           0 :             code2 = state.src.charCodeAt(pos);
     725           0 :             if (code2 === 32) {
     726           0 :                 break;
     727           0 :             }
     728           0 :             if (code2 < 32 || code2 === 127) {
     729           0 :                 break;
     730           0 :             }
     731           0 :             if (code2 === 92 && pos + 1 < max) {
     732           0 :                 pos += 2;
     733           0 :                 continue;
     734           0 :             }
     735           0 :             if (code2 === 40) {
     736           0 :                 level++;
     737           0 :                 if (level > 1) {
     738           0 :                     break;
     739           0 :                 }
     740           0 :             }
     741           0 :             if (code2 === 41) {
     742           0 :                 level--;
     743           0 :                 if (level < 0) {
     744           0 :                     break;
     745           0 :                 }
     746           0 :             }
     747           0 :             pos++;
     748           0 :         }
     749           0 :         if (start === pos) {
     750           0 :             return false;
     751           0 :         }
     752           0 :         link = unescapeMd(state.src.slice(start, pos));
     753           0 :         if (!state.parser.validateLink(link)) {
     754           0 :             return false;
     755           0 :         }
     756           0 :         state.linkContent = link;
     757           0 :         state.pos = pos;
     758           0 :         return true;
     759           0 :     }
     760           0 :     function parseLinkTitle(state, pos) {
     761           0 :         var code2, start = pos, max = state.posMax, marker = state.src.charCodeAt(pos);
     762           0 :         if (marker !== 34 && marker !== 39 && marker !== 40) {
     763           0 :             return false;
     764           0 :         }
     765           0 :         pos++;
     766           0 :         if (marker === 40) {
     767           0 :             marker = 41;
     768           0 :         }
     769           0 :         while(pos < max){
     770           0 :             code2 = state.src.charCodeAt(pos);
     771           0 :             if (code2 === marker) {
     772           0 :                 state.pos = pos + 1;
     773           0 :                 state.linkContent = unescapeMd(state.src.slice(start + 1, pos));
     774           0 :                 return true;
     775           0 :             }
     776           0 :             if (code2 === 92 && pos + 1 < max) {
     777           0 :                 pos += 2;
     778           0 :                 continue;
     779           0 :             }
     780           0 :             pos++;
     781           0 :         }
     782           0 :         return false;
     783           0 :     }
     784           0 :     function normalizeReference(str) {
     785           0 :         return str.trim().replace(/\s+/g, " ").toUpperCase();
     786           0 :     }
     787           0 :     function parseReference(str, parser, options, env) {
     788           0 :         var state, labelEnd, pos, max, code2, start, href, title, label;
     789           0 :         if (str.charCodeAt(0) !== 91) {
     790           0 :             return -1;
     791           0 :         }
     792           0 :         if (str.indexOf("]:") === -1) {
     793           0 :             return -1;
     794           0 :         }
     795           0 :         state = new StateInline(str, parser, options, env, []);
     796           0 :         labelEnd = parseLinkLabel(state, 0);
     797           0 :         if (labelEnd < 0 || str.charCodeAt(labelEnd + 1) !== 58) {
     798           0 :             return -1;
     799           0 :         }
     800           0 :         max = state.posMax;
     801           0 :         for(pos = labelEnd + 2; pos < max; pos++){
     802           0 :             code2 = state.src.charCodeAt(pos);
     803           0 :             if (code2 !== 32 && code2 !== 10) {
     804           0 :                 break;
     805           0 :             }
     806           0 :         }
     807           0 :         if (!parseLinkDestination(state, pos)) {
     808           0 :             return -1;
     809           0 :         }
     810           0 :         href = state.linkContent;
     811           0 :         pos = state.pos;
     812           0 :         start = pos;
     813           0 :         for(pos = pos + 1; pos < max; pos++){
     814           0 :             code2 = state.src.charCodeAt(pos);
     815           0 :             if (code2 !== 32 && code2 !== 10) {
     816           0 :                 break;
     817           0 :             }
     818           0 :         }
     819           0 :         if (pos < max && start !== pos && parseLinkTitle(state, pos)) {
     820           0 :             title = state.linkContent;
     821           0 :             pos = state.pos;
     822           0 :         } else {
     823           0 :             title = "";
     824           0 :             pos = start;
     825           0 :         }
     826           0 :         while(pos < max && state.src.charCodeAt(pos) === 32){
     827           0 :             pos++;
     828           0 :         }
     829           0 :         if (pos < max && state.src.charCodeAt(pos) !== 10) {
     830           0 :             return -1;
     831           0 :         }
     832           0 :         label = normalizeReference(str.slice(1, labelEnd));
     833           0 :         if (typeof env.references[label] === "undefined") {
     834           0 :             env.references[label] = {
     835           0 :                 title,
     836           0 :                 href
     837           0 :             };
     838           0 :         }
     839           0 :         return pos;
     840           0 :     }
     841           0 :     function references(state) {
     842           0 :         var tokens = state.tokens, i, l, content, pos;
     843           0 :         state.env.references = state.env.references || {
     844           0 :         };
     845           0 :         if (state.inlineMode) {
     846           0 :             return;
     847           0 :         }
     848           0 :         for(i = 1, l = tokens.length - 1; i < l; i++){
     849           0 :             if (tokens[i].type === "inline" && tokens[i - 1].type === "paragraph_open" && tokens[i + 1].type === "paragraph_close") {
     850           0 :                 content = tokens[i].content;
     851           0 :                 while(content.length){
     852           0 :                     pos = parseReference(content, state.inline, state.options, state.env);
     853           0 :                     if (pos < 0) {
     854           0 :                         break;
     855           0 :                     }
     856           0 :                     content = content.slice(pos).trim();
     857           0 :                 }
     858           0 :                 tokens[i].content = content;
     859           0 :                 if (!content.length) {
     860           0 :                     tokens[i - 1].tight = true;
     861           0 :                     tokens[i + 1].tight = true;
     862           0 :                 }
     863           0 :             }
     864           0 :         }
     865           0 :     }
     866           0 :     function inline(state) {
     867           0 :         var tokens = state.tokens, tok, i, l;
     868           0 :         for(i = 0, l = tokens.length; i < l; i++){
     869           0 :             tok = tokens[i];
     870           0 :             if (tok.type === "inline") {
     871           0 :                 state.inline.parse(tok.content, state.options, state.env, tok.children);
     872           0 :             }
     873           0 :         }
     874           0 :     }
     875           0 :     function footnote_block(state) {
     876           0 :         var i, l, j, t, lastParagraph, list2, tokens, current, currentLabel, level = 0, insideRef = false, refTokens = {
     877           0 :         };
     878           0 :         if (!state.env.footnotes) {
     879           0 :             return;
     880           0 :         }
     881           0 :         state.tokens = state.tokens.filter(function(tok) {
     882           0 :             if (tok.type === "footnote_reference_open") {
     883           0 :                 insideRef = true;
     884           0 :                 current = [];
     885           0 :                 currentLabel = tok.label;
     886           0 :                 return false;
     887           0 :             }
     888           0 :             if (tok.type === "footnote_reference_close") {
     889           0 :                 insideRef = false;
     890           0 :                 refTokens[":" + currentLabel] = current;
     891           0 :                 return false;
     892           0 :             }
     893           0 :             if (insideRef) {
     894           0 :                 current.push(tok);
     895           0 :             }
     896           0 :             return !insideRef;
     897           0 :         });
     898           0 :         if (!state.env.footnotes.list) {
     899           0 :             return;
     900           0 :         }
     901           0 :         list2 = state.env.footnotes.list;
     902           0 :         state.tokens.push({
     903           0 :             type: "footnote_block_open",
     904           0 :             level: level++
     905           0 :         });
     906           0 :         for(i = 0, l = list2.length; i < l; i++){
     907           0 :             state.tokens.push({
     908           0 :                 type: "footnote_open",
     909           0 :                 id: i,
     910           0 :                 level: level++
     911           0 :             });
     912           0 :             if (list2[i].tokens) {
     913           0 :                 tokens = [];
     914           0 :                 tokens.push({
     915           0 :                     type: "paragraph_open",
     916           0 :                     tight: false,
     917           0 :                     level: level++
     918           0 :                 });
     919           0 :                 tokens.push({
     920           0 :                     type: "inline",
     921           0 :                     content: "",
     922           0 :                     level,
     923           0 :                     children: list2[i].tokens
     924           0 :                 });
     925           0 :                 tokens.push({
     926           0 :                     type: "paragraph_close",
     927           0 :                     tight: false,
     928           0 :                     level: --level
     929           0 :                 });
     930           0 :             } else if (list2[i].label) {
     931           0 :                 tokens = refTokens[":" + list2[i].label];
     932           0 :             }
     933           0 :             state.tokens = state.tokens.concat(tokens);
     934           0 :             if (state.tokens[state.tokens.length - 1].type === "paragraph_close") {
     935           0 :                 lastParagraph = state.tokens.pop();
     936           0 :             } else {
     937           0 :                 lastParagraph = null;
     938           0 :             }
     939           0 :             t = list2[i].count > 0 ? list2[i].count : 1;
     940           0 :             for(j = 0; j < t; j++){
     941           0 :                 state.tokens.push({
     942           0 :                     type: "footnote_anchor",
     943           0 :                     id: i,
     944           0 :                     subId: j,
     945           0 :                     level
     946           0 :                 });
     947           0 :             }
     948           0 :             if (lastParagraph) {
     949           0 :                 state.tokens.push(lastParagraph);
     950           0 :             }
     951           0 :             state.tokens.push({
     952           0 :                 type: "footnote_close",
     953           0 :                 level: --level
     954           0 :             });
     955           0 :         }
     956           0 :         state.tokens.push({
     957           0 :             type: "footnote_block_close",
     958           0 :             level: --level
     959           0 :         });
     960           0 :     }
     961           2 :     var PUNCT_CHARS = ` \n()[]'".,!?-`;
     962           0 :     function regEscape(s) {
     963           0 :         return s.replace(/([-()\[\]{}+?*.$\^|,:#<!\\])/g, "\\$1");
     964           0 :     }
     965           0 :     function abbr2(state) {
     966           0 :         var i, j, l, tokens, token, text2, nodes, pos, level, reg, m, regText, blockTokens = state.tokens;
     967           0 :         if (!state.env.abbreviations) {
     968           0 :             return;
     969           0 :         }
     970           0 :         if (!state.env.abbrRegExp) {
     971           0 :             regText = "(^|[" + PUNCT_CHARS.split("").map(regEscape).join("") + "])(" + Object.keys(state.env.abbreviations).map(function(x) {
     972           0 :                 return x.substr(1);
     973           0 :             }).sort(function(a, b) {
     974           0 :                 return b.length - a.length;
     975           0 :             }).map(regEscape).join("|") + ")($|[" + PUNCT_CHARS.split("").map(regEscape).join("") + "])";
     976           0 :             state.env.abbrRegExp = new RegExp(regText, "g");
     977           0 :         }
     978           0 :         reg = state.env.abbrRegExp;
     979           0 :         for(j = 0, l = blockTokens.length; j < l; j++){
     980           0 :             if (blockTokens[j].type !== "inline") {
     981           0 :                 continue;
     982           0 :             }
     983           0 :             tokens = blockTokens[j].children;
     984           0 :             for(i = tokens.length - 1; i >= 0; i--){
     985           0 :                 token = tokens[i];
     986           0 :                 if (token.type !== "text") {
     987           0 :                     continue;
     988           0 :                 }
     989           0 :                 pos = 0;
     990           0 :                 text2 = token.content;
     991           0 :                 reg.lastIndex = 0;
     992           0 :                 level = token.level;
     993           0 :                 nodes = [];
     994           0 :                 while(m = reg.exec(text2)){
     995           0 :                     if (reg.lastIndex > pos) {
     996           0 :                         nodes.push({
     997           0 :                             type: "text",
     998           0 :                             content: text2.slice(pos, m.index + m[1].length),
     999           0 :                             level
    1000           0 :                         });
    1001           0 :                     }
    1002           0 :                     nodes.push({
    1003           0 :                         type: "abbr_open",
    1004           0 :                         title: state.env.abbreviations[":" + m[2]],
    1005           0 :                         level: level++
    1006           0 :                     });
    1007           0 :                     nodes.push({
    1008           0 :                         type: "text",
    1009           0 :                         content: m[2],
    1010           0 :                         level
    1011           0 :                     });
    1012           0 :                     nodes.push({
    1013           0 :                         type: "abbr_close",
    1014           0 :                         level: --level
    1015           0 :                     });
    1016           0 :                     pos = reg.lastIndex - m[3].length;
    1017           0 :                 }
    1018           0 :                 if (!nodes.length) {
    1019           0 :                     continue;
    1020           0 :                 }
    1021           0 :                 if (pos < text2.length) {
    1022           0 :                     nodes.push({
    1023           0 :                         type: "text",
    1024           0 :                         content: text2.slice(pos),
    1025           0 :                         level
    1026           0 :                     });
    1027           0 :                 }
    1028           0 :                 blockTokens[j].children = tokens = [].concat(tokens.slice(0, i), nodes, tokens.slice(i + 1));
    1029           0 :             }
    1030           0 :         }
    1031           0 :     }
    1032           2 :     var RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/;
    1033           2 :     var SCOPED_ABBR_RE = /\((c|tm|r|p)\)/ig;
    1034           2 :     var SCOPED_ABBR = {
    1035           2 :         c: "\xA9",
    1036           2 :         r: "\xAE",
    1037           2 :         p: "\xA7",
    1038           2 :         tm: "\u2122"
    1039           2 :     };
    1040           0 :     function replaceScopedAbbr(str) {
    1041           0 :         if (str.indexOf("(") < 0) {
    1042           0 :             return str;
    1043           0 :         }
    1044           0 :         return str.replace(SCOPED_ABBR_RE, function(match, name) {
    1045           0 :             return SCOPED_ABBR[name.toLowerCase()];
    1046           0 :         });
    1047           0 :     }
    1048           0 :     function replace(state) {
    1049           0 :         var i, token, text2, inlineTokens, blkIdx;
    1050           0 :         if (!state.options.typographer) {
    1051           0 :             return;
    1052           0 :         }
    1053           0 :         for(blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--){
    1054           0 :             if (state.tokens[blkIdx].type !== "inline") {
    1055           0 :                 continue;
    1056           0 :             }
    1057           0 :             inlineTokens = state.tokens[blkIdx].children;
    1058           0 :             for(i = inlineTokens.length - 1; i >= 0; i--){
    1059           0 :                 token = inlineTokens[i];
    1060           0 :                 if (token.type === "text") {
    1061           0 :                     text2 = token.content;
    1062           0 :                     text2 = replaceScopedAbbr(text2);
    1063           0 :                     if (RARE_RE.test(text2)) {
    1064           0 :                         text2 = text2.replace(/\+-/g, "\xB1").replace(/\.{2,}/g, "\u2026").replace(/([?!])…/g, "$1..").replace(/([?!]){4,}/g, "$1$1$1").replace(/,{2,}/g, ",").replace(/(^|[^-])---([^-]|$)/mg, "$1\u2014$2").replace(/(^|\s)--(\s|$)/mg, "$1\u2013$2").replace(/(^|[^-\s])--([^-\s]|$)/mg, "$1\u2013$2");
    1065           0 :                     }
    1066           0 :                     token.content = text2;
    1067           0 :                 }
    1068           0 :             }
    1069           0 :         }
    1070           0 :     }
    1071           2 :     var QUOTE_TEST_RE = /['"]/;
    1072           2 :     var QUOTE_RE = /['"]/g;
    1073           2 :     var PUNCT_RE = /[-\s()\[\]]/;
    1074           2 :     var APOSTROPHE = "\u2019";
    1075           0 :     function isLetter(str, pos) {
    1076           0 :         if (pos < 0 || pos >= str.length) {
    1077           0 :             return false;
    1078           0 :         }
    1079           0 :         return !PUNCT_RE.test(str[pos]);
    1080           0 :     }
    1081           0 :     function replaceAt(str, index, ch) {
    1082           0 :         return str.substr(0, index) + ch + str.substr(index + 1);
    1083           0 :     }
    1084           0 :     function smartquotes(state) {
    1085           0 :         var i, token, text2, t, pos, max, thisLevel, lastSpace, nextSpace, item, canOpen, canClose, j, isSingle, blkIdx, tokens, stack;
    1086           0 :         if (!state.options.typographer) {
    1087           0 :             return;
    1088           0 :         }
    1089           0 :         stack = [];
    1090           0 :         for(blkIdx = state.tokens.length - 1; blkIdx >= 0; blkIdx--){
    1091           0 :             if (state.tokens[blkIdx].type !== "inline") {
    1092           0 :                 continue;
    1093           0 :             }
    1094           0 :             tokens = state.tokens[blkIdx].children;
    1095           0 :             stack.length = 0;
    1096           0 :             for(i = 0; i < tokens.length; i++){
    1097           0 :                 token = tokens[i];
    1098           0 :                 if (token.type !== "text" || QUOTE_TEST_RE.test(token.text)) {
    1099           0 :                     continue;
    1100           0 :                 }
    1101           0 :                 thisLevel = tokens[i].level;
    1102           0 :                 for(j = stack.length - 1; j >= 0; j--){
    1103           0 :                     if (stack[j].level <= thisLevel) {
    1104           0 :                         break;
    1105           0 :                     }
    1106           0 :                 }
    1107           0 :                 stack.length = j + 1;
    1108           0 :                 text2 = token.content;
    1109           0 :                 pos = 0;
    1110           0 :                 max = text2.length;
    1111           0 :                 OUTER: while(pos < max){
    1112           0 :                     QUOTE_RE.lastIndex = pos;
    1113           0 :                     t = QUOTE_RE.exec(text2);
    1114           0 :                     if (!t) {
    1115           0 :                         break;
    1116           0 :                     }
    1117           0 :                     lastSpace = !isLetter(text2, t.index - 1);
    1118           0 :                     pos = t.index + 1;
    1119           0 :                     isSingle = t[0] === "'";
    1120           0 :                     nextSpace = !isLetter(text2, pos);
    1121           0 :                     if (!nextSpace && !lastSpace) {
    1122           0 :                         if (isSingle) {
    1123           0 :                             token.content = replaceAt(token.content, t.index, APOSTROPHE);
    1124           0 :                         }
    1125           0 :                         continue;
    1126           0 :                     }
    1127           0 :                     canOpen = !nextSpace;
    1128           0 :                     canClose = !lastSpace;
    1129           0 :                     if (canClose) {
    1130           0 :                         for(j = stack.length - 1; j >= 0; j--){
    1131           0 :                             item = stack[j];
    1132           0 :                             if (stack[j].level < thisLevel) {
    1133           0 :                                 break;
    1134           0 :                             }
    1135           0 :                             if (item.single === isSingle && stack[j].level === thisLevel) {
    1136           0 :                                 item = stack[j];
    1137           0 :                                 if (isSingle) {
    1138           0 :                                     tokens[item.token].content = replaceAt(tokens[item.token].content, item.pos, state.options.quotes[2]);
    1139           0 :                                     token.content = replaceAt(token.content, t.index, state.options.quotes[3]);
    1140           0 :                                 } else {
    1141           0 :                                     tokens[item.token].content = replaceAt(tokens[item.token].content, item.pos, state.options.quotes[0]);
    1142           0 :                                     token.content = replaceAt(token.content, t.index, state.options.quotes[1]);
    1143           0 :                                 }
    1144           0 :                                 stack.length = j;
    1145           0 :                                 continue OUTER;
    1146           0 :                             }
    1147           0 :                         }
    1148           0 :                     }
    1149           0 :                     if (canOpen) {
    1150           0 :                         stack.push({
    1151           0 :                             token: i,
    1152           0 :                             pos: t.index,
    1153           0 :                             single: isSingle,
    1154           0 :                             level: thisLevel
    1155           0 :                         });
    1156           0 :                     } else if (canClose && isSingle) {
    1157           0 :                         token.content = replaceAt(token.content, t.index, APOSTROPHE);
    1158           0 :                     }
    1159           0 :                 }
    1160           0 :             }
    1161           0 :         }
    1162           0 :     }
    1163           2 :     var _rules = [
    1164           2 :         [
    1165           2 :             "block",
    1166           2 :             block
    1167           2 :         ],
    1168           2 :         [
    1169           2 :             "abbr",
    1170           2 :             abbr
    1171           2 :         ],
    1172           2 :         [
    1173           2 :             "references",
    1174           2 :             references
    1175           2 :         ],
    1176           2 :         [
    1177           2 :             "inline",
    1178           2 :             inline
    1179           2 :         ],
    1180           2 :         [
    1181           2 :             "footnote_tail",
    1182           2 :             footnote_block
    1183           2 :         ],
    1184           2 :         [
    1185           2 :             "abbr2",
    1186           2 :             abbr2
    1187           2 :         ],
    1188           2 :         [
    1189           2 :             "replacements",
    1190           2 :             replace
    1191           2 :         ],
    1192           2 :         [
    1193           2 :             "smartquotes",
    1194           2 :             smartquotes
    1195           2 :         ]
    1196           2 :     ];
    1197           0 :     function Core() {
    1198           0 :         this.options = {
    1199           0 :         };
    1200           0 :         this.ruler = new Ruler();
    1201           0 :         for(var i = 0; i < _rules.length; i++){
    1202           0 :             this.ruler.push(_rules[i][0], _rules[i][1]);
    1203           0 :         }
    1204           0 :     }
    1205           0 :     Core.prototype.process = function(state) {
    1206           0 :         var i, l, rules2;
    1207           0 :         rules2 = this.ruler.getRules("");
    1208           0 :         for(i = 0, l = rules2.length; i < l; i++){
    1209           0 :             rules2[i](state);
    1210           0 :         }
    1211           0 :     };
    1212           0 :     function StateBlock(src, parser, options, env, tokens) {
    1213           0 :         var ch, s, start, pos, len, indent, indent_found;
    1214           0 :         this.src = src;
    1215           0 :         this.parser = parser;
    1216           0 :         this.options = options;
    1217           0 :         this.env = env;
    1218           0 :         this.tokens = tokens;
    1219           0 :         this.bMarks = [];
    1220           0 :         this.eMarks = [];
    1221           0 :         this.tShift = [];
    1222           0 :         this.blkIndent = 0;
    1223           0 :         this.line = 0;
    1224           0 :         this.lineMax = 0;
    1225           0 :         this.tight = false;
    1226           0 :         this.parentType = "root";
    1227           0 :         this.ddIndent = -1;
    1228           0 :         this.level = 0;
    1229           0 :         this.result = "";
    1230           0 :         s = this.src;
    1231           0 :         indent = 0;
    1232           0 :         indent_found = false;
    1233           0 :         for(start = pos = indent = 0, len = s.length; pos < len; pos++){
    1234           0 :             ch = s.charCodeAt(pos);
    1235           0 :             if (!indent_found) {
    1236           0 :                 if (ch === 32) {
    1237           0 :                     indent++;
    1238           0 :                     continue;
    1239           0 :                 } else {
    1240           0 :                     indent_found = true;
    1241           0 :                 }
    1242           0 :             }
    1243           0 :             if (ch === 10 || pos === len - 1) {
    1244           0 :                 if (ch !== 10) {
    1245           0 :                     pos++;
    1246           0 :                 }
    1247           0 :                 this.bMarks.push(start);
    1248           0 :                 this.eMarks.push(pos);
    1249           0 :                 this.tShift.push(indent);
    1250           0 :                 indent_found = false;
    1251           0 :                 indent = 0;
    1252           0 :                 start = pos + 1;
    1253           0 :             }
    1254           0 :         }
    1255           0 :         this.bMarks.push(s.length);
    1256           0 :         this.eMarks.push(s.length);
    1257           0 :         this.tShift.push(0);
    1258           0 :         this.lineMax = this.bMarks.length - 1;
    1259           0 :     }
    1260           0 :     StateBlock.prototype.isEmpty = function isEmpty(line) {
    1261           0 :         return this.bMarks[line] + this.tShift[line] >= this.eMarks[line];
    1262           0 :     };
    1263           0 :     StateBlock.prototype.skipEmptyLines = function skipEmptyLines(from) {
    1264           0 :         for(var max = this.lineMax; from < max; from++){
    1265           0 :             if (this.bMarks[from] + this.tShift[from] < this.eMarks[from]) {
    1266           0 :                 break;
    1267           0 :             }
    1268           0 :         }
    1269           0 :         return from;
    1270           0 :     };
    1271           0 :     StateBlock.prototype.skipSpaces = function skipSpaces(pos) {
    1272           0 :         for(var max = this.src.length; pos < max; pos++){
    1273           0 :             if (this.src.charCodeAt(pos) !== 32) {
    1274           0 :                 break;
    1275           0 :             }
    1276           0 :         }
    1277           0 :         return pos;
    1278           0 :     };
    1279           0 :     StateBlock.prototype.skipChars = function skipChars(pos, code2) {
    1280           0 :         for(var max = this.src.length; pos < max; pos++){
    1281           0 :             if (this.src.charCodeAt(pos) !== code2) {
    1282           0 :                 break;
    1283           0 :             }
    1284           0 :         }
    1285           0 :         return pos;
    1286           0 :     };
    1287           0 :     StateBlock.prototype.skipCharsBack = function skipCharsBack(pos, code2, min) {
    1288           0 :         if (pos <= min) {
    1289           0 :             return pos;
    1290           0 :         }
    1291           0 :         while(pos > min){
    1292           0 :             if (code2 !== this.src.charCodeAt(--pos)) {
    1293           0 :                 return pos + 1;
    1294           0 :             }
    1295           0 :         }
    1296           0 :         return pos;
    1297           0 :     };
    1298           0 :     StateBlock.prototype.getLines = function getLines(begin, end, indent, keepLastLF) {
    1299           0 :         var i, first, last, queue, shift, line = begin;
    1300           0 :         if (begin >= end) {
    1301           0 :             return "";
    1302           0 :         }
    1303           0 :         if (line + 1 === end) {
    1304           0 :             first = this.bMarks[line] + Math.min(this.tShift[line], indent);
    1305           0 :             last = keepLastLF ? this.eMarks[line] + 1 : this.eMarks[line];
    1306           0 :             return this.src.slice(first, last);
    1307           0 :         }
    1308           0 :         queue = new Array(end - begin);
    1309           0 :         for(i = 0; line < end; line++, i++){
    1310           0 :             shift = this.tShift[line];
    1311           0 :             if (shift > indent) {
    1312           0 :                 shift = indent;
    1313           0 :             }
    1314           0 :             if (shift < 0) {
    1315           0 :                 shift = 0;
    1316           0 :             }
    1317           0 :             first = this.bMarks[line] + shift;
    1318           0 :             if (line + 1 < end || keepLastLF) {
    1319           0 :                 last = this.eMarks[line] + 1;
    1320           0 :             } else {
    1321           0 :                 last = this.eMarks[line];
    1322           0 :             }
    1323           0 :             queue[i] = this.src.slice(first, last);
    1324           0 :         }
    1325           0 :         return queue.join("");
    1326           0 :     };
    1327           0 :     function code(state, startLine, endLine) {
    1328           0 :         var nextLine, last;
    1329           0 :         if (state.tShift[startLine] - state.blkIndent < 4) {
    1330           0 :             return false;
    1331           0 :         }
    1332           0 :         last = nextLine = startLine + 1;
    1333           0 :         while(nextLine < endLine){
    1334           0 :             if (state.isEmpty(nextLine)) {
    1335           0 :                 nextLine++;
    1336           0 :                 continue;
    1337           0 :             }
    1338           0 :             if (state.tShift[nextLine] - state.blkIndent >= 4) {
    1339           0 :                 nextLine++;
    1340           0 :                 last = nextLine;
    1341           0 :                 continue;
    1342           0 :             }
    1343           0 :             break;
    1344           0 :         }
    1345           0 :         state.line = nextLine;
    1346           0 :         state.tokens.push({
    1347           0 :             type: "code",
    1348           0 :             content: state.getLines(startLine, last, 4 + state.blkIndent, true),
    1349           0 :             block: true,
    1350           0 :             lines: [
    1351           0 :                 startLine,
    1352           0 :                 state.line
    1353           0 :             ],
    1354           0 :             level: state.level
    1355           0 :         });
    1356           0 :         return true;
    1357           0 :     }
    1358           0 :     function fences(state, startLine, endLine, silent) {
    1359           0 :         var marker, len, params, nextLine, mem, haveEndMarker = false, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
    1360           0 :         if (pos + 3 > max) {
    1361           0 :             return false;
    1362           0 :         }
    1363           0 :         marker = state.src.charCodeAt(pos);
    1364           0 :         if (marker !== 126 && marker !== 96) {
    1365           0 :             return false;
    1366           0 :         }
    1367           0 :         mem = pos;
    1368           0 :         pos = state.skipChars(pos, marker);
    1369           0 :         len = pos - mem;
    1370           0 :         if (len < 3) {
    1371           0 :             return false;
    1372           0 :         }
    1373           0 :         params = state.src.slice(pos, max).trim();
    1374           0 :         if (params.indexOf("`") >= 0) {
    1375           0 :             return false;
    1376           0 :         }
    1377           0 :         if (silent) {
    1378           0 :             return true;
    1379           0 :         }
    1380           0 :         nextLine = startLine;
    1381           0 :         for(;;){
    1382           0 :             nextLine++;
    1383           0 :             if (nextLine >= endLine) {
    1384           0 :                 break;
    1385           0 :             }
    1386           0 :             pos = mem = state.bMarks[nextLine] + state.tShift[nextLine];
    1387           0 :             max = state.eMarks[nextLine];
    1388           0 :             if (pos < max && state.tShift[nextLine] < state.blkIndent) {
    1389           0 :                 break;
    1390           0 :             }
    1391           0 :             if (state.src.charCodeAt(pos) !== marker) {
    1392           0 :                 continue;
    1393           0 :             }
    1394           0 :             if (state.tShift[nextLine] - state.blkIndent >= 4) {
    1395           0 :                 continue;
    1396           0 :             }
    1397           0 :             pos = state.skipChars(pos, marker);
    1398           0 :             if (pos - mem < len) {
    1399           0 :                 continue;
    1400           0 :             }
    1401           0 :             pos = state.skipSpaces(pos);
    1402           0 :             if (pos < max) {
    1403           0 :                 continue;
    1404           0 :             }
    1405           0 :             haveEndMarker = true;
    1406           0 :             break;
    1407           0 :         }
    1408           0 :         len = state.tShift[startLine];
    1409           0 :         state.line = nextLine + (haveEndMarker ? 1 : 0);
    1410           0 :         state.tokens.push({
    1411           0 :             type: "fence",
    1412           0 :             params,
    1413           0 :             content: state.getLines(startLine + 1, nextLine, len, true),
    1414           0 :             lines: [
    1415           0 :                 startLine,
    1416           0 :                 state.line
    1417           0 :             ],
    1418           0 :             level: state.level
    1419           0 :         });
    1420           0 :         return true;
    1421           0 :     }
    1422           0 :     function blockquote(state, startLine, endLine, silent) {
    1423           0 :         var nextLine, lastLineEmpty, oldTShift, oldBMarks, oldIndent, oldParentType, lines, terminatorRules, i, l, terminate, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
    1424           0 :         if (pos > max) {
    1425           0 :             return false;
    1426           0 :         }
    1427           0 :         if (state.src.charCodeAt(pos++) !== 62) {
    1428           0 :             return false;
    1429           0 :         }
    1430           0 :         if (state.level >= state.options.maxNesting) {
    1431           0 :             return false;
    1432           0 :         }
    1433           0 :         if (silent) {
    1434           0 :             return true;
    1435           0 :         }
    1436           0 :         if (state.src.charCodeAt(pos) === 32) {
    1437           0 :             pos++;
    1438           0 :         }
    1439           0 :         oldIndent = state.blkIndent;
    1440           0 :         state.blkIndent = 0;
    1441           0 :         oldBMarks = [
    1442           0 :             state.bMarks[startLine]
    1443           0 :         ];
    1444           0 :         state.bMarks[startLine] = pos;
    1445           0 :         pos = pos < max ? state.skipSpaces(pos) : pos;
    1446           0 :         lastLineEmpty = pos >= max;
    1447           0 :         oldTShift = [
    1448           0 :             state.tShift[startLine]
    1449           0 :         ];
    1450           0 :         state.tShift[startLine] = pos - state.bMarks[startLine];
    1451           0 :         terminatorRules = state.parser.ruler.getRules("blockquote");
    1452           0 :         for(nextLine = startLine + 1; nextLine < endLine; nextLine++){
    1453           0 :             pos = state.bMarks[nextLine] + state.tShift[nextLine];
    1454           0 :             max = state.eMarks[nextLine];
    1455           0 :             if (pos >= max) {
    1456           0 :                 break;
    1457           0 :             }
    1458           0 :             if (state.src.charCodeAt(pos++) === 62) {
    1459           0 :                 if (state.src.charCodeAt(pos) === 32) {
    1460           0 :                     pos++;
    1461           0 :                 }
    1462           0 :                 oldBMarks.push(state.bMarks[nextLine]);
    1463           0 :                 state.bMarks[nextLine] = pos;
    1464           0 :                 pos = pos < max ? state.skipSpaces(pos) : pos;
    1465           0 :                 lastLineEmpty = pos >= max;
    1466           0 :                 oldTShift.push(state.tShift[nextLine]);
    1467           0 :                 state.tShift[nextLine] = pos - state.bMarks[nextLine];
    1468           0 :                 continue;
    1469           0 :             }
    1470           0 :             if (lastLineEmpty) {
    1471           0 :                 break;
    1472           0 :             }
    1473           0 :             terminate = false;
    1474           0 :             for(i = 0, l = terminatorRules.length; i < l; i++){
    1475           0 :                 if (terminatorRules[i](state, nextLine, endLine, true)) {
    1476           0 :                     terminate = true;
    1477           0 :                     break;
    1478           0 :                 }
    1479           0 :             }
    1480           0 :             if (terminate) {
    1481           0 :                 break;
    1482           0 :             }
    1483           0 :             oldBMarks.push(state.bMarks[nextLine]);
    1484           0 :             oldTShift.push(state.tShift[nextLine]);
    1485           0 :             state.tShift[nextLine] = -1337;
    1486           0 :         }
    1487           0 :         oldParentType = state.parentType;
    1488           0 :         state.parentType = "blockquote";
    1489           0 :         state.tokens.push({
    1490           0 :             type: "blockquote_open",
    1491           0 :             lines: lines = [
    1492           0 :                 startLine,
    1493           0 :                 0
    1494           0 :             ],
    1495           0 :             level: state.level++
    1496           0 :         });
    1497           0 :         state.parser.tokenize(state, startLine, nextLine);
    1498           0 :         state.tokens.push({
    1499           0 :             type: "blockquote_close",
    1500           0 :             level: --state.level
    1501           0 :         });
    1502           0 :         state.parentType = oldParentType;
    1503           0 :         lines[1] = state.line;
    1504           0 :         for(i = 0; i < oldTShift.length; i++){
    1505           0 :             state.bMarks[i + startLine] = oldBMarks[i];
    1506           0 :             state.tShift[i + startLine] = oldTShift[i];
    1507           0 :         }
    1508           0 :         state.blkIndent = oldIndent;
    1509           0 :         return true;
    1510           0 :     }
    1511           0 :     function hr(state, startLine, endLine, silent) {
    1512           0 :         var marker, cnt, ch, pos = state.bMarks[startLine], max = state.eMarks[startLine];
    1513           0 :         pos += state.tShift[startLine];
    1514           0 :         if (pos > max) {
    1515           0 :             return false;
    1516           0 :         }
    1517           0 :         marker = state.src.charCodeAt(pos++);
    1518           0 :         if (marker !== 42 && marker !== 45 && marker !== 95) {
    1519           0 :             return false;
    1520           0 :         }
    1521           0 :         cnt = 1;
    1522           0 :         while(pos < max){
    1523           0 :             ch = state.src.charCodeAt(pos++);
    1524           0 :             if (ch !== marker && ch !== 32) {
    1525           0 :                 return false;
    1526           0 :             }
    1527           0 :             if (ch === marker) {
    1528           0 :                 cnt++;
    1529           0 :             }
    1530           0 :         }
    1531           0 :         if (cnt < 3) {
    1532           0 :             return false;
    1533           0 :         }
    1534           0 :         if (silent) {
    1535           0 :             return true;
    1536           0 :         }
    1537           0 :         state.line = startLine + 1;
    1538           0 :         state.tokens.push({
    1539           0 :             type: "hr",
    1540           0 :             lines: [
    1541           0 :                 startLine,
    1542           0 :                 state.line
    1543           0 :             ],
    1544           0 :             level: state.level
    1545           0 :         });
    1546           0 :         return true;
    1547           0 :     }
    1548           0 :     function skipBulletListMarker(state, startLine) {
    1549           0 :         var marker, pos, max;
    1550           0 :         pos = state.bMarks[startLine] + state.tShift[startLine];
    1551           0 :         max = state.eMarks[startLine];
    1552           0 :         if (pos >= max) {
    1553           0 :             return -1;
    1554           0 :         }
    1555           0 :         marker = state.src.charCodeAt(pos++);
    1556           0 :         if (marker !== 42 && marker !== 45 && marker !== 43) {
    1557           0 :             return -1;
    1558           0 :         }
    1559           0 :         if (pos < max && state.src.charCodeAt(pos) !== 32) {
    1560           0 :             return -1;
    1561           0 :         }
    1562           0 :         return pos;
    1563           0 :     }
    1564           0 :     function skipOrderedListMarker(state, startLine) {
    1565           0 :         var ch, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
    1566           0 :         if (pos + 1 >= max) {
    1567           0 :             return -1;
    1568           0 :         }
    1569           0 :         ch = state.src.charCodeAt(pos++);
    1570           0 :         if (ch < 48 || ch > 57) {
    1571           0 :             return -1;
    1572           0 :         }
    1573           0 :         for(;;){
    1574           0 :             if (pos >= max) {
    1575           0 :                 return -1;
    1576           0 :             }
    1577           0 :             ch = state.src.charCodeAt(pos++);
    1578           0 :             if (ch >= 48 && ch <= 57) {
    1579           0 :                 continue;
    1580           0 :             }
    1581           0 :             if (ch === 41 || ch === 46) {
    1582           0 :                 break;
    1583           0 :             }
    1584           0 :             return -1;
    1585           0 :         }
    1586           0 :         if (pos < max && state.src.charCodeAt(pos) !== 32) {
    1587           0 :             return -1;
    1588           0 :         }
    1589           0 :         return pos;
    1590           0 :     }
    1591           0 :     function markTightParagraphs(state, idx) {
    1592           0 :         var i, l, level = state.level + 2;
    1593           0 :         for(i = idx + 2, l = state.tokens.length - 2; i < l; i++){
    1594           0 :             if (state.tokens[i].level === level && state.tokens[i].type === "paragraph_open") {
    1595           0 :                 state.tokens[i + 2].tight = true;
    1596           0 :                 state.tokens[i].tight = true;
    1597           0 :                 i += 2;
    1598           0 :             }
    1599           0 :         }
    1600           0 :     }
    1601           0 :     function list(state, startLine, endLine, silent) {
    1602           0 :         var nextLine, indent, oldTShift, oldIndent, oldTight, oldParentType, start, posAfterMarker, max, indentAfterMarker, markerValue, markerCharCode, isOrdered, contentStart, listTokIdx, prevEmptyEnd, listLines, itemLines, tight = true, terminatorRules, i, l, terminate;
    1603           0 :         if ((posAfterMarker = skipOrderedListMarker(state, startLine)) >= 0) {
    1604           0 :             isOrdered = true;
    1605           0 :         } else if ((posAfterMarker = skipBulletListMarker(state, startLine)) >= 0) {
    1606           0 :             isOrdered = false;
    1607           0 :         } else {
    1608           0 :             return false;
    1609           0 :         }
    1610           0 :         if (state.level >= state.options.maxNesting) {
    1611           0 :             return false;
    1612           0 :         }
    1613           0 :         markerCharCode = state.src.charCodeAt(posAfterMarker - 1);
    1614           0 :         if (silent) {
    1615           0 :             return true;
    1616           0 :         }
    1617           0 :         listTokIdx = state.tokens.length;
    1618           0 :         if (isOrdered) {
    1619           0 :             start = state.bMarks[startLine] + state.tShift[startLine];
    1620           0 :             markerValue = Number(state.src.substr(start, posAfterMarker - start - 1));
    1621           0 :             state.tokens.push({
    1622           0 :                 type: "ordered_list_open",
    1623           0 :                 order: markerValue,
    1624           0 :                 lines: listLines = [
    1625           0 :                     startLine,
    1626           0 :                     0
    1627           0 :                 ],
    1628           0 :                 level: state.level++
    1629           0 :             });
    1630           0 :         } else {
    1631           0 :             state.tokens.push({
    1632           0 :                 type: "bullet_list_open",
    1633           0 :                 lines: listLines = [
    1634           0 :                     startLine,
    1635           0 :                     0
    1636           0 :                 ],
    1637           0 :                 level: state.level++
    1638           0 :             });
    1639           0 :         }
    1640           0 :         nextLine = startLine;
    1641           0 :         prevEmptyEnd = false;
    1642           0 :         terminatorRules = state.parser.ruler.getRules("list");
    1643           0 :         while(nextLine < endLine){
    1644           0 :             contentStart = state.skipSpaces(posAfterMarker);
    1645           0 :             max = state.eMarks[nextLine];
    1646           0 :             if (contentStart >= max) {
    1647           0 :                 indentAfterMarker = 1;
    1648           0 :             } else {
    1649           0 :                 indentAfterMarker = contentStart - posAfterMarker;
    1650           0 :             }
    1651           0 :             if (indentAfterMarker > 4) {
    1652           0 :                 indentAfterMarker = 1;
    1653           0 :             }
    1654           0 :             if (indentAfterMarker < 1) {
    1655           0 :                 indentAfterMarker = 1;
    1656           0 :             }
    1657           0 :             indent = posAfterMarker - state.bMarks[nextLine] + indentAfterMarker;
    1658           0 :             state.tokens.push({
    1659           0 :                 type: "list_item_open",
    1660           0 :                 lines: itemLines = [
    1661           0 :                     startLine,
    1662           0 :                     0
    1663           0 :                 ],
    1664           0 :                 level: state.level++
    1665           0 :             });
    1666           0 :             oldIndent = state.blkIndent;
    1667           0 :             oldTight = state.tight;
    1668           0 :             oldTShift = state.tShift[startLine];
    1669           0 :             oldParentType = state.parentType;
    1670           0 :             state.tShift[startLine] = contentStart - state.bMarks[startLine];
    1671           0 :             state.blkIndent = indent;
    1672           0 :             state.tight = true;
    1673           0 :             state.parentType = "list";
    1674           0 :             state.parser.tokenize(state, startLine, endLine, true);
    1675           0 :             if (!state.tight || prevEmptyEnd) {
    1676           0 :                 tight = false;
    1677           0 :             }
    1678           0 :             prevEmptyEnd = state.line - startLine > 1 && state.isEmpty(state.line - 1);
    1679           0 :             state.blkIndent = oldIndent;
    1680           0 :             state.tShift[startLine] = oldTShift;
    1681           0 :             state.tight = oldTight;
    1682           0 :             state.parentType = oldParentType;
    1683           0 :             state.tokens.push({
    1684           0 :                 type: "list_item_close",
    1685           0 :                 level: --state.level
    1686           0 :             });
    1687           0 :             nextLine = startLine = state.line;
    1688           0 :             itemLines[1] = nextLine;
    1689           0 :             contentStart = state.bMarks[startLine];
    1690           0 :             if (nextLine >= endLine) {
    1691           0 :                 break;
    1692           0 :             }
    1693           0 :             if (state.isEmpty(nextLine)) {
    1694           0 :                 break;
    1695           0 :             }
    1696           0 :             if (state.tShift[nextLine] < state.blkIndent) {
    1697           0 :                 break;
    1698           0 :             }
    1699           0 :             terminate = false;
    1700           0 :             for(i = 0, l = terminatorRules.length; i < l; i++){
    1701           0 :                 if (terminatorRules[i](state, nextLine, endLine, true)) {
    1702           0 :                     terminate = true;
    1703           0 :                     break;
    1704           0 :                 }
    1705           0 :             }
    1706           0 :             if (terminate) {
    1707           0 :                 break;
    1708           0 :             }
    1709           0 :             if (isOrdered) {
    1710           0 :                 posAfterMarker = skipOrderedListMarker(state, nextLine);
    1711           0 :                 if (posAfterMarker < 0) {
    1712           0 :                     break;
    1713           0 :                 }
    1714           0 :             } else {
    1715           0 :                 posAfterMarker = skipBulletListMarker(state, nextLine);
    1716           0 :                 if (posAfterMarker < 0) {
    1717           0 :                     break;
    1718           0 :                 }
    1719           0 :             }
    1720           0 :             if (markerCharCode !== state.src.charCodeAt(posAfterMarker - 1)) {
    1721           0 :                 break;
    1722           0 :             }
    1723           0 :         }
    1724           0 :         state.tokens.push({
    1725           0 :             type: isOrdered ? "ordered_list_close" : "bullet_list_close",
    1726           0 :             level: --state.level
    1727           0 :         });
    1728           0 :         listLines[1] = nextLine;
    1729           0 :         state.line = nextLine;
    1730           0 :         if (tight) {
    1731           0 :             markTightParagraphs(state, listTokIdx);
    1732           0 :         }
    1733           0 :         return true;
    1734           0 :     }
    1735           0 :     function footnote(state, startLine, endLine, silent) {
    1736           0 :         var oldBMark, oldTShift, oldParentType, pos, label, start = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
    1737           0 :         if (start + 4 > max) {
    1738           0 :             return false;
    1739           0 :         }
    1740           0 :         if (state.src.charCodeAt(start) !== 91) {
    1741           0 :             return false;
    1742           0 :         }
    1743           0 :         if (state.src.charCodeAt(start + 1) !== 94) {
    1744           0 :             return false;
    1745           0 :         }
    1746           0 :         if (state.level >= state.options.maxNesting) {
    1747           0 :             return false;
    1748           0 :         }
    1749           0 :         for(pos = start + 2; pos < max; pos++){
    1750           0 :             if (state.src.charCodeAt(pos) === 32) {
    1751           0 :                 return false;
    1752           0 :             }
    1753           0 :             if (state.src.charCodeAt(pos) === 93) {
    1754           0 :                 break;
    1755           0 :             }
    1756           0 :         }
    1757           0 :         if (pos === start + 2) {
    1758           0 :             return false;
    1759           0 :         }
    1760           0 :         if (pos + 1 >= max || state.src.charCodeAt(++pos) !== 58) {
    1761           0 :             return false;
    1762           0 :         }
    1763           0 :         if (silent) {
    1764           0 :             return true;
    1765           0 :         }
    1766           0 :         pos++;
    1767           0 :         if (!state.env.footnotes) {
    1768           0 :             state.env.footnotes = {
    1769           0 :             };
    1770           0 :         }
    1771           0 :         if (!state.env.footnotes.refs) {
    1772           0 :             state.env.footnotes.refs = {
    1773           0 :             };
    1774           0 :         }
    1775           0 :         label = state.src.slice(start + 2, pos - 2);
    1776           0 :         state.env.footnotes.refs[":" + label] = -1;
    1777           0 :         state.tokens.push({
    1778           0 :             type: "footnote_reference_open",
    1779           0 :             label,
    1780           0 :             level: state.level++
    1781           0 :         });
    1782           0 :         oldBMark = state.bMarks[startLine];
    1783           0 :         oldTShift = state.tShift[startLine];
    1784           0 :         oldParentType = state.parentType;
    1785           0 :         state.tShift[startLine] = state.skipSpaces(pos) - pos;
    1786           0 :         state.bMarks[startLine] = pos;
    1787           0 :         state.blkIndent += 4;
    1788           0 :         state.parentType = "footnote";
    1789           0 :         if (state.tShift[startLine] < state.blkIndent) {
    1790           0 :             state.tShift[startLine] += state.blkIndent;
    1791           0 :             state.bMarks[startLine] -= state.blkIndent;
    1792           0 :         }
    1793           0 :         state.parser.tokenize(state, startLine, endLine, true);
    1794           0 :         state.parentType = oldParentType;
    1795           0 :         state.blkIndent -= 4;
    1796           0 :         state.tShift[startLine] = oldTShift;
    1797           0 :         state.bMarks[startLine] = oldBMark;
    1798           0 :         state.tokens.push({
    1799           0 :             type: "footnote_reference_close",
    1800           0 :             level: --state.level
    1801           0 :         });
    1802           0 :         return true;
    1803           0 :     }
    1804           0 :     function heading(state, startLine, endLine, silent) {
    1805           0 :         var ch, level, tmp, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
    1806           0 :         if (pos >= max) {
    1807           0 :             return false;
    1808           0 :         }
    1809           0 :         ch = state.src.charCodeAt(pos);
    1810           0 :         if (ch !== 35 || pos >= max) {
    1811           0 :             return false;
    1812           0 :         }
    1813           0 :         level = 1;
    1814           0 :         ch = state.src.charCodeAt(++pos);
    1815           0 :         while(ch === 35 && pos < max && level <= 6){
    1816           0 :             level++;
    1817           0 :             ch = state.src.charCodeAt(++pos);
    1818           0 :         }
    1819           0 :         if (level > 6 || pos < max && ch !== 32) {
    1820           0 :             return false;
    1821           0 :         }
    1822           0 :         if (silent) {
    1823           0 :             return true;
    1824           0 :         }
    1825           0 :         max = state.skipCharsBack(max, 32, pos);
    1826           0 :         tmp = state.skipCharsBack(max, 35, pos);
    1827           0 :         if (tmp > pos && state.src.charCodeAt(tmp - 1) === 32) {
    1828           0 :             max = tmp;
    1829           0 :         }
    1830           0 :         state.line = startLine + 1;
    1831           0 :         state.tokens.push({
    1832           0 :             type: "heading_open",
    1833           0 :             hLevel: level,
    1834           0 :             lines: [
    1835           0 :                 startLine,
    1836           0 :                 state.line
    1837           0 :             ],
    1838           0 :             level: state.level
    1839           0 :         });
    1840           0 :         if (pos < max) {
    1841           0 :             state.tokens.push({
    1842           0 :                 type: "inline",
    1843           0 :                 content: state.src.slice(pos, max).trim(),
    1844           0 :                 level: state.level + 1,
    1845           0 :                 lines: [
    1846           0 :                     startLine,
    1847           0 :                     state.line
    1848           0 :                 ],
    1849           0 :                 children: []
    1850           0 :             });
    1851           0 :         }
    1852           0 :         state.tokens.push({
    1853           0 :             type: "heading_close",
    1854           0 :             hLevel: level,
    1855           0 :             level: state.level
    1856           0 :         });
    1857           0 :         return true;
    1858           0 :     }
    1859           0 :     function lheading(state, startLine, endLine) {
    1860           0 :         var marker, pos, max, next = startLine + 1;
    1861           0 :         if (next >= endLine) {
    1862           0 :             return false;
    1863           0 :         }
    1864           0 :         if (state.tShift[next] < state.blkIndent) {
    1865           0 :             return false;
    1866           0 :         }
    1867           0 :         if (state.tShift[next] - state.blkIndent > 3) {
    1868           0 :             return false;
    1869           0 :         }
    1870           0 :         pos = state.bMarks[next] + state.tShift[next];
    1871           0 :         max = state.eMarks[next];
    1872           0 :         if (pos >= max) {
    1873           0 :             return false;
    1874           0 :         }
    1875           0 :         marker = state.src.charCodeAt(pos);
    1876           0 :         if (marker !== 45 && marker !== 61) {
    1877           0 :             return false;
    1878           0 :         }
    1879           0 :         pos = state.skipChars(pos, marker);
    1880           0 :         pos = state.skipSpaces(pos);
    1881           0 :         if (pos < max) {
    1882           0 :             return false;
    1883           0 :         }
    1884           0 :         pos = state.bMarks[startLine] + state.tShift[startLine];
    1885           0 :         state.line = next + 1;
    1886           0 :         state.tokens.push({
    1887           0 :             type: "heading_open",
    1888           0 :             hLevel: marker === 61 ? 1 : 2,
    1889           0 :             lines: [
    1890           0 :                 startLine,
    1891           0 :                 state.line
    1892           0 :             ],
    1893           0 :             level: state.level
    1894           0 :         });
    1895           0 :         state.tokens.push({
    1896           0 :             type: "inline",
    1897           0 :             content: state.src.slice(pos, state.eMarks[startLine]).trim(),
    1898           0 :             level: state.level + 1,
    1899           0 :             lines: [
    1900           0 :                 startLine,
    1901           0 :                 state.line - 1
    1902           0 :             ],
    1903           0 :             children: []
    1904           0 :         });
    1905           0 :         state.tokens.push({
    1906           0 :             type: "heading_close",
    1907           0 :             hLevel: marker === 61 ? 1 : 2,
    1908           0 :             level: state.level
    1909           0 :         });
    1910           0 :         return true;
    1911           0 :     }
    1912           2 :     var html_blocks = {
    1913           2 :     };
    1914           2 :     [
    1915           2 :         "article",
    1916           2 :         "aside",
    1917           2 :         "button",
    1918           2 :         "blockquote",
    1919           2 :         "body",
    1920           2 :         "canvas",
    1921           2 :         "caption",
    1922           2 :         "col",
    1923           2 :         "colgroup",
    1924           2 :         "dd",
    1925           2 :         "div",
    1926           2 :         "dl",
    1927           2 :         "dt",
    1928           2 :         "embed",
    1929           2 :         "fieldset",
    1930           2 :         "figcaption",
    1931           2 :         "figure",
    1932           2 :         "footer",
    1933           2 :         "form",
    1934           2 :         "h1",
    1935           2 :         "h2",
    1936           2 :         "h3",
    1937           2 :         "h4",
    1938           2 :         "h5",
    1939           2 :         "h6",
    1940           2 :         "header",
    1941           2 :         "hgroup",
    1942           2 :         "hr",
    1943           2 :         "iframe",
    1944           2 :         "li",
    1945           2 :         "map",
    1946           2 :         "object",
    1947           2 :         "ol",
    1948           2 :         "output",
    1949           2 :         "p",
    1950           2 :         "pre",
    1951           2 :         "progress",
    1952           2 :         "script",
    1953           2 :         "section",
    1954           2 :         "style",
    1955           2 :         "table",
    1956           2 :         "tbody",
    1957           2 :         "td",
    1958           2 :         "textarea",
    1959           2 :         "tfoot",
    1960           2 :         "th",
    1961           2 :         "tr",
    1962           2 :         "thead",
    1963           2 :         "ul",
    1964           2 :         "video"
    1965           2 :     ].forEach(function(name) {
    1966          52 :         html_blocks[name] = true;
    1967           2 :     });
    1968           2 :     var HTML_TAG_OPEN_RE = /^<([a-zA-Z]{1,15})[\s\/>]/;
    1969           2 :     var HTML_TAG_CLOSE_RE = /^<\/([a-zA-Z]{1,15})[\s>]/;
    1970           0 :     function isLetter$1(ch) {
    1971           0 :         var lc = ch | 32;
    1972           0 :         return lc >= 97 && lc <= 122;
    1973           0 :     }
    1974           0 :     function htmlblock(state, startLine, endLine, silent) {
    1975           0 :         var ch, match, nextLine, pos = state.bMarks[startLine], max = state.eMarks[startLine], shift = state.tShift[startLine];
    1976           0 :         pos += shift;
    1977           0 :         if (!state.options.html) {
    1978           0 :             return false;
    1979           0 :         }
    1980           0 :         if (shift > 3 || pos + 2 >= max) {
    1981           0 :             return false;
    1982           0 :         }
    1983           0 :         if (state.src.charCodeAt(pos) !== 60) {
    1984           0 :             return false;
    1985           0 :         }
    1986           0 :         ch = state.src.charCodeAt(pos + 1);
    1987           0 :         if (ch === 33 || ch === 63) {
    1988           0 :             if (silent) {
    1989           0 :                 return true;
    1990           0 :             }
    1991           0 :         } else if (ch === 47 || isLetter$1(ch)) {
    1992           0 :             if (ch === 47) {
    1993           0 :                 match = state.src.slice(pos, max).match(HTML_TAG_CLOSE_RE);
    1994           0 :                 if (!match) {
    1995           0 :                     return false;
    1996           0 :                 }
    1997           0 :             } else {
    1998           0 :                 match = state.src.slice(pos, max).match(HTML_TAG_OPEN_RE);
    1999           0 :                 if (!match) {
    2000           0 :                     return false;
    2001           0 :                 }
    2002           0 :             }
    2003           0 :             if (html_blocks[match[1].toLowerCase()] !== true) {
    2004           0 :                 return false;
    2005           0 :             }
    2006           0 :             if (silent) {
    2007           0 :                 return true;
    2008           0 :             }
    2009           0 :         } else {
    2010           0 :             return false;
    2011           0 :         }
    2012           0 :         nextLine = startLine + 1;
    2013           0 :         while(nextLine < state.lineMax && !state.isEmpty(nextLine)){
    2014           0 :             nextLine++;
    2015           0 :         }
    2016           0 :         state.line = nextLine;
    2017           0 :         state.tokens.push({
    2018           0 :             type: "htmlblock",
    2019           0 :             level: state.level,
    2020           0 :             lines: [
    2021           0 :                 startLine,
    2022           0 :                 state.line
    2023           0 :             ],
    2024           0 :             content: state.getLines(startLine, nextLine, 0, true)
    2025           0 :         });
    2026           0 :         return true;
    2027           0 :     }
    2028           0 :     function getLine(state, line) {
    2029           0 :         var pos = state.bMarks[line] + state.blkIndent, max = state.eMarks[line];
    2030           0 :         return state.src.substr(pos, max - pos);
    2031           0 :     }
    2032           0 :     function table(state, startLine, endLine, silent) {
    2033           0 :         var ch, lineText, pos, i, nextLine, rows, cell, aligns, t, tableLines, tbodyLines;
    2034           0 :         if (startLine + 2 > endLine) {
    2035           0 :             return false;
    2036           0 :         }
    2037           0 :         nextLine = startLine + 1;
    2038           0 :         if (state.tShift[nextLine] < state.blkIndent) {
    2039           0 :             return false;
    2040           0 :         }
    2041           0 :         pos = state.bMarks[nextLine] + state.tShift[nextLine];
    2042           0 :         if (pos >= state.eMarks[nextLine]) {
    2043           0 :             return false;
    2044           0 :         }
    2045           0 :         ch = state.src.charCodeAt(pos);
    2046           0 :         if (ch !== 124 && ch !== 45 && ch !== 58) {
    2047           0 :             return false;
    2048           0 :         }
    2049           0 :         lineText = getLine(state, startLine + 1);
    2050           0 :         if (!/^[-:| ]+$/.test(lineText)) {
    2051           0 :             return false;
    2052           0 :         }
    2053           0 :         rows = lineText.split("|");
    2054           0 :         if (rows <= 2) {
    2055           0 :             return false;
    2056           0 :         }
    2057           0 :         aligns = [];
    2058           0 :         for(i = 0; i < rows.length; i++){
    2059           0 :             t = rows[i].trim();
    2060           0 :             if (!t) {
    2061           0 :                 if (i === 0 || i === rows.length - 1) {
    2062           0 :                     continue;
    2063           0 :                 } else {
    2064           0 :                     return false;
    2065           0 :                 }
    2066           0 :             }
    2067           0 :             if (!/^:?-+:?$/.test(t)) {
    2068           0 :                 return false;
    2069           0 :             }
    2070           0 :             if (t.charCodeAt(t.length - 1) === 58) {
    2071           0 :                 aligns.push(t.charCodeAt(0) === 58 ? "center" : "right");
    2072           0 :             } else if (t.charCodeAt(0) === 58) {
    2073           0 :                 aligns.push("left");
    2074           0 :             } else {
    2075           0 :                 aligns.push("");
    2076           0 :             }
    2077           0 :         }
    2078           0 :         lineText = getLine(state, startLine).trim();
    2079           0 :         if (lineText.indexOf("|") === -1) {
    2080           0 :             return false;
    2081           0 :         }
    2082           0 :         rows = lineText.replace(/^\||\|$/g, "").split("|");
    2083           0 :         if (aligns.length !== rows.length) {
    2084           0 :             return false;
    2085           0 :         }
    2086           0 :         if (silent) {
    2087           0 :             return true;
    2088           0 :         }
    2089           0 :         state.tokens.push({
    2090           0 :             type: "table_open",
    2091           0 :             lines: tableLines = [
    2092           0 :                 startLine,
    2093           0 :                 0
    2094           0 :             ],
    2095           0 :             level: state.level++
    2096           0 :         });
    2097           0 :         state.tokens.push({
    2098           0 :             type: "thead_open",
    2099           0 :             lines: [
    2100           0 :                 startLine,
    2101           0 :                 startLine + 1
    2102           0 :             ],
    2103           0 :             level: state.level++
    2104           0 :         });
    2105           0 :         state.tokens.push({
    2106           0 :             type: "tr_open",
    2107           0 :             lines: [
    2108           0 :                 startLine,
    2109           0 :                 startLine + 1
    2110           0 :             ],
    2111           0 :             level: state.level++
    2112           0 :         });
    2113           0 :         for(i = 0; i < rows.length; i++){
    2114           0 :             state.tokens.push({
    2115           0 :                 type: "th_open",
    2116           0 :                 align: aligns[i],
    2117           0 :                 lines: [
    2118           0 :                     startLine,
    2119           0 :                     startLine + 1
    2120           0 :                 ],
    2121           0 :                 level: state.level++
    2122           0 :             });
    2123           0 :             state.tokens.push({
    2124           0 :                 type: "inline",
    2125           0 :                 content: rows[i].trim(),
    2126           0 :                 lines: [
    2127           0 :                     startLine,
    2128           0 :                     startLine + 1
    2129           0 :                 ],
    2130           0 :                 level: state.level,
    2131           0 :                 children: []
    2132           0 :             });
    2133           0 :             state.tokens.push({
    2134           0 :                 type: "th_close",
    2135           0 :                 level: --state.level
    2136           0 :             });
    2137           0 :         }
    2138           0 :         state.tokens.push({
    2139           0 :             type: "tr_close",
    2140           0 :             level: --state.level
    2141           0 :         });
    2142           0 :         state.tokens.push({
    2143           0 :             type: "thead_close",
    2144           0 :             level: --state.level
    2145           0 :         });
    2146           0 :         state.tokens.push({
    2147           0 :             type: "tbody_open",
    2148           0 :             lines: tbodyLines = [
    2149           0 :                 startLine + 2,
    2150           0 :                 0
    2151           0 :             ],
    2152           0 :             level: state.level++
    2153           0 :         });
    2154           0 :         for(nextLine = startLine + 2; nextLine < endLine; nextLine++){
    2155           0 :             if (state.tShift[nextLine] < state.blkIndent) {
    2156           0 :                 break;
    2157           0 :             }
    2158           0 :             lineText = getLine(state, nextLine).trim();
    2159           0 :             if (lineText.indexOf("|") === -1) {
    2160           0 :                 break;
    2161           0 :             }
    2162           0 :             rows = lineText.replace(/^\||\|$/g, "").split("|");
    2163           0 :             state.tokens.push({
    2164           0 :                 type: "tr_open",
    2165           0 :                 level: state.level++
    2166           0 :             });
    2167           0 :             for(i = 0; i < rows.length; i++){
    2168           0 :                 state.tokens.push({
    2169           0 :                     type: "td_open",
    2170           0 :                     align: aligns[i],
    2171           0 :                     level: state.level++
    2172           0 :                 });
    2173           0 :                 cell = rows[i].substring(rows[i].charCodeAt(0) === 124 ? 1 : 0, rows[i].charCodeAt(rows[i].length - 1) === 124 ? rows[i].length - 1 : rows[i].length).trim();
    2174           0 :                 state.tokens.push({
    2175           0 :                     type: "inline",
    2176           0 :                     content: cell,
    2177           0 :                     level: state.level,
    2178           0 :                     children: []
    2179           0 :                 });
    2180           0 :                 state.tokens.push({
    2181           0 :                     type: "td_close",
    2182           0 :                     level: --state.level
    2183           0 :                 });
    2184           0 :             }
    2185           0 :             state.tokens.push({
    2186           0 :                 type: "tr_close",
    2187           0 :                 level: --state.level
    2188           0 :             });
    2189           0 :         }
    2190           0 :         state.tokens.push({
    2191           0 :             type: "tbody_close",
    2192           0 :             level: --state.level
    2193           0 :         });
    2194           0 :         state.tokens.push({
    2195           0 :             type: "table_close",
    2196           0 :             level: --state.level
    2197           0 :         });
    2198           0 :         tableLines[1] = tbodyLines[1] = nextLine;
    2199           0 :         state.line = nextLine;
    2200           0 :         return true;
    2201           0 :     }
    2202           0 :     function skipMarker(state, line) {
    2203           0 :         var pos, marker, start = state.bMarks[line] + state.tShift[line], max = state.eMarks[line];
    2204           0 :         if (start >= max) {
    2205           0 :             return -1;
    2206           0 :         }
    2207           0 :         marker = state.src.charCodeAt(start++);
    2208           0 :         if (marker !== 126 && marker !== 58) {
    2209           0 :             return -1;
    2210           0 :         }
    2211           0 :         pos = state.skipSpaces(start);
    2212           0 :         if (start === pos) {
    2213           0 :             return -1;
    2214           0 :         }
    2215           0 :         if (pos >= max) {
    2216           0 :             return -1;
    2217           0 :         }
    2218           0 :         return pos;
    2219           0 :     }
    2220           0 :     function markTightParagraphs$1(state, idx) {
    2221           0 :         var i, l, level = state.level + 2;
    2222           0 :         for(i = idx + 2, l = state.tokens.length - 2; i < l; i++){
    2223           0 :             if (state.tokens[i].level === level && state.tokens[i].type === "paragraph_open") {
    2224           0 :                 state.tokens[i + 2].tight = true;
    2225           0 :                 state.tokens[i].tight = true;
    2226           0 :                 i += 2;
    2227           0 :             }
    2228           0 :         }
    2229           0 :     }
    2230           0 :     function deflist(state, startLine, endLine, silent) {
    2231           0 :         var contentStart, ddLine, dtLine, itemLines, listLines, listTokIdx, nextLine, oldIndent, oldDDIndent, oldParentType, oldTShift, oldTight, prevEmptyEnd, tight;
    2232           0 :         if (silent) {
    2233           0 :             if (state.ddIndent < 0) {
    2234           0 :                 return false;
    2235           0 :             }
    2236           0 :             return skipMarker(state, startLine) >= 0;
    2237           0 :         }
    2238           0 :         nextLine = startLine + 1;
    2239           0 :         if (state.isEmpty(nextLine)) {
    2240           0 :             if ((++nextLine) > endLine) {
    2241           0 :                 return false;
    2242           0 :             }
    2243           0 :         }
    2244           0 :         if (state.tShift[nextLine] < state.blkIndent) {
    2245           0 :             return false;
    2246           0 :         }
    2247           0 :         contentStart = skipMarker(state, nextLine);
    2248           0 :         if (contentStart < 0) {
    2249           0 :             return false;
    2250           0 :         }
    2251           0 :         if (state.level >= state.options.maxNesting) {
    2252           0 :             return false;
    2253           0 :         }
    2254           0 :         listTokIdx = state.tokens.length;
    2255           0 :         state.tokens.push({
    2256           0 :             type: "dl_open",
    2257           0 :             lines: listLines = [
    2258           0 :                 startLine,
    2259           0 :                 0
    2260           0 :             ],
    2261           0 :             level: state.level++
    2262           0 :         });
    2263           0 :         dtLine = startLine;
    2264           0 :         ddLine = nextLine;
    2265           0 :         OUTER: for(;;){
    2266           0 :             tight = true;
    2267           0 :             prevEmptyEnd = false;
    2268           0 :             state.tokens.push({
    2269           0 :                 type: "dt_open",
    2270           0 :                 lines: [
    2271           0 :                     dtLine,
    2272           0 :                     dtLine
    2273           0 :                 ],
    2274           0 :                 level: state.level++
    2275           0 :             });
    2276           0 :             state.tokens.push({
    2277           0 :                 type: "inline",
    2278           0 :                 content: state.getLines(dtLine, dtLine + 1, state.blkIndent, false).trim(),
    2279           0 :                 level: state.level + 1,
    2280           0 :                 lines: [
    2281           0 :                     dtLine,
    2282           0 :                     dtLine
    2283           0 :                 ],
    2284           0 :                 children: []
    2285           0 :             });
    2286           0 :             state.tokens.push({
    2287           0 :                 type: "dt_close",
    2288           0 :                 level: --state.level
    2289           0 :             });
    2290           0 :             for(;;){
    2291           0 :                 state.tokens.push({
    2292           0 :                     type: "dd_open",
    2293           0 :                     lines: itemLines = [
    2294           0 :                         nextLine,
    2295           0 :                         0
    2296           0 :                     ],
    2297           0 :                     level: state.level++
    2298           0 :                 });
    2299           0 :                 oldTight = state.tight;
    2300           0 :                 oldDDIndent = state.ddIndent;
    2301           0 :                 oldIndent = state.blkIndent;
    2302           0 :                 oldTShift = state.tShift[ddLine];
    2303           0 :                 oldParentType = state.parentType;
    2304           0 :                 state.blkIndent = state.ddIndent = state.tShift[ddLine] + 2;
    2305           0 :                 state.tShift[ddLine] = contentStart - state.bMarks[ddLine];
    2306           0 :                 state.tight = true;
    2307           0 :                 state.parentType = "deflist";
    2308           0 :                 state.parser.tokenize(state, ddLine, endLine, true);
    2309           0 :                 if (!state.tight || prevEmptyEnd) {
    2310           0 :                     tight = false;
    2311           0 :                 }
    2312           0 :                 prevEmptyEnd = state.line - ddLine > 1 && state.isEmpty(state.line - 1);
    2313           0 :                 state.tShift[ddLine] = oldTShift;
    2314           0 :                 state.tight = oldTight;
    2315           0 :                 state.parentType = oldParentType;
    2316           0 :                 state.blkIndent = oldIndent;
    2317           0 :                 state.ddIndent = oldDDIndent;
    2318           0 :                 state.tokens.push({
    2319           0 :                     type: "dd_close",
    2320           0 :                     level: --state.level
    2321           0 :                 });
    2322           0 :                 itemLines[1] = nextLine = state.line;
    2323           0 :                 if (nextLine >= endLine) {
    2324           0 :                     break OUTER;
    2325           0 :                 }
    2326           0 :                 if (state.tShift[nextLine] < state.blkIndent) {
    2327           0 :                     break OUTER;
    2328           0 :                 }
    2329           0 :                 contentStart = skipMarker(state, nextLine);
    2330           0 :                 if (contentStart < 0) {
    2331           0 :                     break;
    2332           0 :                 }
    2333           0 :                 ddLine = nextLine;
    2334           0 :             }
    2335           0 :             if (nextLine >= endLine) {
    2336           0 :                 break;
    2337           0 :             }
    2338           0 :             dtLine = nextLine;
    2339           0 :             if (state.isEmpty(dtLine)) {
    2340           0 :                 break;
    2341           0 :             }
    2342           0 :             if (state.tShift[dtLine] < state.blkIndent) {
    2343           0 :                 break;
    2344           0 :             }
    2345           0 :             ddLine = dtLine + 1;
    2346           0 :             if (ddLine >= endLine) {
    2347           0 :                 break;
    2348           0 :             }
    2349           0 :             if (state.isEmpty(ddLine)) {
    2350           0 :                 ddLine++;
    2351           0 :             }
    2352           0 :             if (ddLine >= endLine) {
    2353           0 :                 break;
    2354           0 :             }
    2355           0 :             if (state.tShift[ddLine] < state.blkIndent) {
    2356           0 :                 break;
    2357           0 :             }
    2358           0 :             contentStart = skipMarker(state, ddLine);
    2359           0 :             if (contentStart < 0) {
    2360           0 :                 break;
    2361           0 :             }
    2362           0 :         }
    2363           0 :         state.tokens.push({
    2364           0 :             type: "dl_close",
    2365           0 :             level: --state.level
    2366           0 :         });
    2367           0 :         listLines[1] = nextLine;
    2368           0 :         state.line = nextLine;
    2369           0 :         if (tight) {
    2370           0 :             markTightParagraphs$1(state, listTokIdx);
    2371           0 :         }
    2372           0 :         return true;
    2373           0 :     }
    2374           0 :     function paragraph(state, startLine) {
    2375           0 :         var endLine, content, terminate, i, l, nextLine = startLine + 1, terminatorRules;
    2376           0 :         endLine = state.lineMax;
    2377           0 :         if (nextLine < endLine && !state.isEmpty(nextLine)) {
    2378           0 :             terminatorRules = state.parser.ruler.getRules("paragraph");
    2379           0 :             for(; nextLine < endLine && !state.isEmpty(nextLine); nextLine++){
    2380           0 :                 if (state.tShift[nextLine] - state.blkIndent > 3) {
    2381           0 :                     continue;
    2382           0 :                 }
    2383           0 :                 terminate = false;
    2384           0 :                 for(i = 0, l = terminatorRules.length; i < l; i++){
    2385           0 :                     if (terminatorRules[i](state, nextLine, endLine, true)) {
    2386           0 :                         terminate = true;
    2387           0 :                         break;
    2388           0 :                     }
    2389           0 :                 }
    2390           0 :                 if (terminate) {
    2391           0 :                     break;
    2392           0 :                 }
    2393           0 :             }
    2394           0 :         }
    2395           0 :         content = state.getLines(startLine, nextLine, state.blkIndent, false).trim();
    2396           0 :         state.line = nextLine;
    2397           0 :         if (content.length) {
    2398           0 :             state.tokens.push({
    2399           0 :                 type: "paragraph_open",
    2400           0 :                 tight: false,
    2401           0 :                 lines: [
    2402           0 :                     startLine,
    2403           0 :                     state.line
    2404           0 :                 ],
    2405           0 :                 level: state.level
    2406           0 :             });
    2407           0 :             state.tokens.push({
    2408           0 :                 type: "inline",
    2409           0 :                 content,
    2410           0 :                 level: state.level + 1,
    2411           0 :                 lines: [
    2412           0 :                     startLine,
    2413           0 :                     state.line
    2414           0 :                 ],
    2415           0 :                 children: []
    2416           0 :             });
    2417           0 :             state.tokens.push({
    2418           0 :                 type: "paragraph_close",
    2419           0 :                 tight: false,
    2420           0 :                 level: state.level
    2421           0 :             });
    2422           0 :         }
    2423           0 :         return true;
    2424           0 :     }
    2425           2 :     var _rules$1 = [
    2426           2 :         [
    2427           2 :             "code",
    2428           2 :             code
    2429           2 :         ],
    2430           2 :         [
    2431           2 :             "fences",
    2432           2 :             fences,
    2433           2 :             [
    2434           2 :                 "paragraph",
    2435           2 :                 "blockquote",
    2436           2 :                 "list"
    2437           2 :             ]
    2438           2 :         ],
    2439           2 :         [
    2440           2 :             "blockquote",
    2441           2 :             blockquote,
    2442           2 :             [
    2443           2 :                 "paragraph",
    2444           2 :                 "blockquote",
    2445           2 :                 "list"
    2446           2 :             ]
    2447           2 :         ],
    2448           2 :         [
    2449           2 :             "hr",
    2450           2 :             hr,
    2451           2 :             [
    2452           2 :                 "paragraph",
    2453           2 :                 "blockquote",
    2454           2 :                 "list"
    2455           2 :             ]
    2456           2 :         ],
    2457           2 :         [
    2458           2 :             "list",
    2459           2 :             list,
    2460           2 :             [
    2461           2 :                 "paragraph",
    2462           2 :                 "blockquote"
    2463           2 :             ]
    2464           2 :         ],
    2465           2 :         [
    2466           2 :             "footnote",
    2467           2 :             footnote,
    2468           2 :             [
    2469           2 :                 "paragraph"
    2470           2 :             ]
    2471           2 :         ],
    2472           2 :         [
    2473           2 :             "heading",
    2474           2 :             heading,
    2475           2 :             [
    2476           2 :                 "paragraph",
    2477           2 :                 "blockquote"
    2478           2 :             ]
    2479           2 :         ],
    2480           2 :         [
    2481           2 :             "lheading",
    2482           2 :             lheading
    2483           2 :         ],
    2484           2 :         [
    2485           2 :             "htmlblock",
    2486           2 :             htmlblock,
    2487           2 :             [
    2488           2 :                 "paragraph",
    2489           2 :                 "blockquote"
    2490           2 :             ]
    2491           2 :         ],
    2492           2 :         [
    2493           2 :             "table",
    2494           2 :             table,
    2495           2 :             [
    2496           2 :                 "paragraph"
    2497           2 :             ]
    2498           2 :         ],
    2499           2 :         [
    2500           2 :             "deflist",
    2501           2 :             deflist,
    2502           2 :             [
    2503           2 :                 "paragraph"
    2504           2 :             ]
    2505           2 :         ],
    2506           2 :         [
    2507           2 :             "paragraph",
    2508           2 :             paragraph
    2509           2 :         ]
    2510           2 :     ];
    2511           0 :     function ParserBlock() {
    2512           0 :         this.ruler = new Ruler();
    2513           0 :         for(var i = 0; i < _rules$1.length; i++){
    2514           0 :             this.ruler.push(_rules$1[i][0], _rules$1[i][1], {
    2515           0 :                 alt: (_rules$1[i][2] || []).slice()
    2516           0 :             });
    2517           0 :         }
    2518           0 :     }
    2519           0 :     ParserBlock.prototype.tokenize = function(state, startLine, endLine) {
    2520           0 :         var rules2 = this.ruler.getRules("");
    2521           0 :         var len = rules2.length;
    2522           0 :         var line = startLine;
    2523           0 :         var hasEmptyLines = false;
    2524           0 :         var ok, i;
    2525           0 :         while(line < endLine){
    2526           0 :             state.line = line = state.skipEmptyLines(line);
    2527           0 :             if (line >= endLine) {
    2528           0 :                 break;
    2529           0 :             }
    2530           0 :             if (state.tShift[line] < state.blkIndent) {
    2531           0 :                 break;
    2532           0 :             }
    2533           0 :             for(i = 0; i < len; i++){
    2534           0 :                 ok = rules2[i](state, line, endLine, false);
    2535           0 :                 if (ok) {
    2536           0 :                     break;
    2537           0 :                 }
    2538           0 :             }
    2539           0 :             state.tight = !hasEmptyLines;
    2540           0 :             if (state.isEmpty(state.line - 1)) {
    2541           0 :                 hasEmptyLines = true;
    2542           0 :             }
    2543           0 :             line = state.line;
    2544           0 :             if (line < endLine && state.isEmpty(line)) {
    2545           0 :                 hasEmptyLines = true;
    2546           0 :                 line++;
    2547           0 :                 if (line < endLine && state.parentType === "list" && state.isEmpty(line)) {
    2548           0 :                     break;
    2549           0 :                 }
    2550           0 :                 state.line = line;
    2551           0 :             }
    2552           0 :         }
    2553           0 :     };
    2554           2 :     var TABS_SCAN_RE = /[\n\t]/g;
    2555           2 :     var NEWLINES_RE = /\r[\n\u0085]|[\u2424\u2028\u0085]/g;
    2556           2 :     var SPACES_RE = /\u00a0/g;
    2557           0 :     ParserBlock.prototype.parse = function(str, options, env, outTokens) {
    2558           0 :         var state, lineStart = 0, lastTabPos = 0;
    2559           0 :         if (!str) {
    2560           0 :             return [];
    2561           0 :         }
    2562           0 :         str = str.replace(SPACES_RE, " ");
    2563           0 :         str = str.replace(NEWLINES_RE, "\n");
    2564           0 :         if (str.indexOf("  ") >= 0) {
    2565           0 :             str = str.replace(TABS_SCAN_RE, function(match, offset) {
    2566           0 :                 var result;
    2567           0 :                 if (str.charCodeAt(offset) === 10) {
    2568           0 :                     lineStart = offset + 1;
    2569           0 :                     lastTabPos = 0;
    2570           0 :                     return match;
    2571           0 :                 }
    2572           0 :                 result = "    ".slice((offset - lineStart - lastTabPos) % 4);
    2573           0 :                 lastTabPos = offset - lineStart + 1;
    2574           0 :                 return result;
    2575           0 :             });
    2576           0 :         }
    2577           0 :         state = new StateBlock(str, this, options, env, outTokens);
    2578           0 :         this.tokenize(state, state.line, state.lineMax);
    2579           0 :     };
    2580           0 :     function isTerminatorChar(ch) {
    2581           0 :         switch(ch){
    2582           0 :             case 10:
    2583           0 :             case 92:
    2584           0 :             case 96:
    2585           0 :             case 42:
    2586           0 :             case 95:
    2587           0 :             case 94:
    2588           0 :             case 91:
    2589           0 :             case 93:
    2590           0 :             case 33:
    2591           0 :             case 38:
    2592           0 :             case 60:
    2593           0 :             case 62:
    2594           0 :             case 123:
    2595           0 :             case 125:
    2596           0 :             case 36:
    2597           0 :             case 37:
    2598           0 :             case 64:
    2599           0 :             case 126:
    2600           0 :             case 43:
    2601           0 :             case 61:
    2602           0 :             case 58:
    2603           0 :                 return true;
    2604           0 :             default:
    2605           0 :                 return false;
    2606           0 :         }
    2607           0 :     }
    2608           0 :     function text(state, silent) {
    2609           0 :         var pos = state.pos;
    2610           0 :         while(pos < state.posMax && !isTerminatorChar(state.src.charCodeAt(pos))){
    2611           0 :             pos++;
    2612           0 :         }
    2613           0 :         if (pos === state.pos) {
    2614           0 :             return false;
    2615           0 :         }
    2616           0 :         if (!silent) {
    2617           0 :             state.pending += state.src.slice(state.pos, pos);
    2618           0 :         }
    2619           0 :         state.pos = pos;
    2620           0 :         return true;
    2621           0 :     }
    2622           0 :     function newline(state, silent) {
    2623           0 :         var pmax, max, pos = state.pos;
    2624           0 :         if (state.src.charCodeAt(pos) !== 10) {
    2625           0 :             return false;
    2626           0 :         }
    2627           0 :         pmax = state.pending.length - 1;
    2628           0 :         max = state.posMax;
    2629           0 :         if (!silent) {
    2630           0 :             if (pmax >= 0 && state.pending.charCodeAt(pmax) === 32) {
    2631           0 :                 if (pmax >= 1 && state.pending.charCodeAt(pmax - 1) === 32) {
    2632           0 :                     for(var i = pmax - 2; i >= 0; i--){
    2633           0 :                         if (state.pending.charCodeAt(i) !== 32) {
    2634           0 :                             state.pending = state.pending.substring(0, i + 1);
    2635           0 :                             break;
    2636           0 :                         }
    2637           0 :                     }
    2638           0 :                     state.push({
    2639           0 :                         type: "hardbreak",
    2640           0 :                         level: state.level
    2641           0 :                     });
    2642           0 :                 } else {
    2643           0 :                     state.pending = state.pending.slice(0, -1);
    2644           0 :                     state.push({
    2645           0 :                         type: "softbreak",
    2646           0 :                         level: state.level
    2647           0 :                     });
    2648           0 :                 }
    2649           0 :             } else {
    2650           0 :                 state.push({
    2651           0 :                     type: "softbreak",
    2652           0 :                     level: state.level
    2653           0 :                 });
    2654           0 :             }
    2655           0 :         }
    2656           0 :         pos++;
    2657           0 :         while(pos < max && state.src.charCodeAt(pos) === 32){
    2658           0 :             pos++;
    2659           0 :         }
    2660           0 :         state.pos = pos;
    2661           0 :         return true;
    2662           0 :     }
    2663           2 :     var ESCAPED = [];
    2664           2 :     for(var i = 0; i < 256; i++){
    2665         258 :         ESCAPED.push(0);
    2666           2 :     }
    2667           2 :     "\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(ch) {
    2668          34 :         ESCAPED[ch.charCodeAt(0)] = 1;
    2669           2 :     });
    2670           0 :     function escape(state, silent) {
    2671           0 :         var ch, pos = state.pos, max = state.posMax;
    2672           0 :         if (state.src.charCodeAt(pos) !== 92) {
    2673           0 :             return false;
    2674           0 :         }
    2675           0 :         pos++;
    2676           0 :         if (pos < max) {
    2677           0 :             ch = state.src.charCodeAt(pos);
    2678           0 :             if (ch < 256 && ESCAPED[ch] !== 0) {
    2679           0 :                 if (!silent) {
    2680           0 :                     state.pending += state.src[pos];
    2681           0 :                 }
    2682           0 :                 state.pos += 2;
    2683           0 :                 return true;
    2684           0 :             }
    2685           0 :             if (ch === 10) {
    2686           0 :                 if (!silent) {
    2687           0 :                     state.push({
    2688           0 :                         type: "hardbreak",
    2689           0 :                         level: state.level
    2690           0 :                     });
    2691           0 :                 }
    2692           0 :                 pos++;
    2693           0 :                 while(pos < max && state.src.charCodeAt(pos) === 32){
    2694           0 :                     pos++;
    2695           0 :                 }
    2696           0 :                 state.pos = pos;
    2697           0 :                 return true;
    2698           0 :             }
    2699           0 :         }
    2700           0 :         if (!silent) {
    2701           0 :             state.pending += "\\";
    2702           0 :         }
    2703           0 :         state.pos++;
    2704           0 :         return true;
    2705           0 :     }
    2706           0 :     function backticks(state, silent) {
    2707           0 :         var start, max, marker, matchStart, matchEnd, pos = state.pos, ch = state.src.charCodeAt(pos);
    2708           0 :         if (ch !== 96) {
    2709           0 :             return false;
    2710           0 :         }
    2711           0 :         start = pos;
    2712           0 :         pos++;
    2713           0 :         max = state.posMax;
    2714           0 :         while(pos < max && state.src.charCodeAt(pos) === 96){
    2715           0 :             pos++;
    2716           0 :         }
    2717           0 :         marker = state.src.slice(start, pos);
    2718           0 :         matchStart = matchEnd = pos;
    2719           0 :         while((matchStart = state.src.indexOf("`", matchEnd)) !== -1){
    2720           0 :             matchEnd = matchStart + 1;
    2721           0 :             while(matchEnd < max && state.src.charCodeAt(matchEnd) === 96){
    2722           0 :                 matchEnd++;
    2723           0 :             }
    2724           0 :             if (matchEnd - matchStart === marker.length) {
    2725           0 :                 if (!silent) {
    2726           0 :                     state.push({
    2727           0 :                         type: "code",
    2728           0 :                         content: state.src.slice(pos, matchStart).replace(/[ \n]+/g, " ").trim(),
    2729           0 :                         block: false,
    2730           0 :                         level: state.level
    2731           0 :                     });
    2732           0 :                 }
    2733           0 :                 state.pos = matchEnd;
    2734           0 :                 return true;
    2735           0 :             }
    2736           0 :         }
    2737           0 :         if (!silent) {
    2738           0 :             state.pending += marker;
    2739           0 :         }
    2740           0 :         state.pos += marker.length;
    2741           0 :         return true;
    2742           0 :     }
    2743           0 :     function del(state, silent) {
    2744           0 :         var found, pos, stack, max = state.posMax, start = state.pos, lastChar, nextChar;
    2745           0 :         if (state.src.charCodeAt(start) !== 126) {
    2746           0 :             return false;
    2747           0 :         }
    2748           0 :         if (silent) {
    2749           0 :             return false;
    2750           0 :         }
    2751           0 :         if (start + 4 >= max) {
    2752           0 :             return false;
    2753           0 :         }
    2754           0 :         if (state.src.charCodeAt(start + 1) !== 126) {
    2755           0 :             return false;
    2756           0 :         }
    2757           0 :         if (state.level >= state.options.maxNesting) {
    2758           0 :             return false;
    2759           0 :         }
    2760           0 :         lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
    2761           0 :         nextChar = state.src.charCodeAt(start + 2);
    2762           0 :         if (lastChar === 126) {
    2763           0 :             return false;
    2764           0 :         }
    2765           0 :         if (nextChar === 126) {
    2766           0 :             return false;
    2767           0 :         }
    2768           0 :         if (nextChar === 32 || nextChar === 10) {
    2769           0 :             return false;
    2770           0 :         }
    2771           0 :         pos = start + 2;
    2772           0 :         while(pos < max && state.src.charCodeAt(pos) === 126){
    2773           0 :             pos++;
    2774           0 :         }
    2775           0 :         if (pos > start + 3) {
    2776           0 :             state.pos += pos - start;
    2777           0 :             if (!silent) {
    2778           0 :                 state.pending += state.src.slice(start, pos);
    2779           0 :             }
    2780           0 :             return true;
    2781           0 :         }
    2782           0 :         state.pos = start + 2;
    2783           0 :         stack = 1;
    2784           0 :         while(state.pos + 1 < max){
    2785           0 :             if (state.src.charCodeAt(state.pos) === 126) {
    2786           0 :                 if (state.src.charCodeAt(state.pos + 1) === 126) {
    2787           0 :                     lastChar = state.src.charCodeAt(state.pos - 1);
    2788           0 :                     nextChar = state.pos + 2 < max ? state.src.charCodeAt(state.pos + 2) : -1;
    2789           0 :                     if (nextChar !== 126 && lastChar !== 126) {
    2790           0 :                         if (lastChar !== 32 && lastChar !== 10) {
    2791           0 :                             stack--;
    2792           0 :                         } else if (nextChar !== 32 && nextChar !== 10) {
    2793           0 :                             stack++;
    2794           0 :                         }
    2795           0 :                         if (stack <= 0) {
    2796           0 :                             found = true;
    2797           0 :                             break;
    2798           0 :                         }
    2799           0 :                     }
    2800           0 :                 }
    2801           0 :             }
    2802           0 :             state.parser.skipToken(state);
    2803           0 :         }
    2804           0 :         if (!found) {
    2805           0 :             state.pos = start;
    2806           0 :             return false;
    2807           0 :         }
    2808           0 :         state.posMax = state.pos;
    2809           0 :         state.pos = start + 2;
    2810           0 :         if (!silent) {
    2811           0 :             state.push({
    2812           0 :                 type: "del_open",
    2813           0 :                 level: state.level++
    2814           0 :             });
    2815           0 :             state.parser.tokenize(state);
    2816           0 :             state.push({
    2817           0 :                 type: "del_close",
    2818           0 :                 level: --state.level
    2819           0 :             });
    2820           0 :         }
    2821           0 :         state.pos = state.posMax + 2;
    2822           0 :         state.posMax = max;
    2823           0 :         return true;
    2824           0 :     }
    2825           0 :     function ins(state, silent) {
    2826           0 :         var found, pos, stack, max = state.posMax, start = state.pos, lastChar, nextChar;
    2827           0 :         if (state.src.charCodeAt(start) !== 43) {
    2828           0 :             return false;
    2829           0 :         }
    2830           0 :         if (silent) {
    2831           0 :             return false;
    2832           0 :         }
    2833           0 :         if (start + 4 >= max) {
    2834           0 :             return false;
    2835           0 :         }
    2836           0 :         if (state.src.charCodeAt(start + 1) !== 43) {
    2837           0 :             return false;
    2838           0 :         }
    2839           0 :         if (state.level >= state.options.maxNesting) {
    2840           0 :             return false;
    2841           0 :         }
    2842           0 :         lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
    2843           0 :         nextChar = state.src.charCodeAt(start + 2);
    2844           0 :         if (lastChar === 43) {
    2845           0 :             return false;
    2846           0 :         }
    2847           0 :         if (nextChar === 43) {
    2848           0 :             return false;
    2849           0 :         }
    2850           0 :         if (nextChar === 32 || nextChar === 10) {
    2851           0 :             return false;
    2852           0 :         }
    2853           0 :         pos = start + 2;
    2854           0 :         while(pos < max && state.src.charCodeAt(pos) === 43){
    2855           0 :             pos++;
    2856           0 :         }
    2857           0 :         if (pos !== start + 2) {
    2858           0 :             state.pos += pos - start;
    2859           0 :             if (!silent) {
    2860           0 :                 state.pending += state.src.slice(start, pos);
    2861           0 :             }
    2862           0 :             return true;
    2863           0 :         }
    2864           0 :         state.pos = start + 2;
    2865           0 :         stack = 1;
    2866           0 :         while(state.pos + 1 < max){
    2867           0 :             if (state.src.charCodeAt(state.pos) === 43) {
    2868           0 :                 if (state.src.charCodeAt(state.pos + 1) === 43) {
    2869           0 :                     lastChar = state.src.charCodeAt(state.pos - 1);
    2870           0 :                     nextChar = state.pos + 2 < max ? state.src.charCodeAt(state.pos + 2) : -1;
    2871           0 :                     if (nextChar !== 43 && lastChar !== 43) {
    2872           0 :                         if (lastChar !== 32 && lastChar !== 10) {
    2873           0 :                             stack--;
    2874           0 :                         } else if (nextChar !== 32 && nextChar !== 10) {
    2875           0 :                             stack++;
    2876           0 :                         }
    2877           0 :                         if (stack <= 0) {
    2878           0 :                             found = true;
    2879           0 :                             break;
    2880           0 :                         }
    2881           0 :                     }
    2882           0 :                 }
    2883           0 :             }
    2884           0 :             state.parser.skipToken(state);
    2885           0 :         }
    2886           0 :         if (!found) {
    2887           0 :             state.pos = start;
    2888           0 :             return false;
    2889           0 :         }
    2890           0 :         state.posMax = state.pos;
    2891           0 :         state.pos = start + 2;
    2892           0 :         if (!silent) {
    2893           0 :             state.push({
    2894           0 :                 type: "ins_open",
    2895           0 :                 level: state.level++
    2896           0 :             });
    2897           0 :             state.parser.tokenize(state);
    2898           0 :             state.push({
    2899           0 :                 type: "ins_close",
    2900           0 :                 level: --state.level
    2901           0 :             });
    2902           0 :         }
    2903           0 :         state.pos = state.posMax + 2;
    2904           0 :         state.posMax = max;
    2905           0 :         return true;
    2906           0 :     }
    2907           0 :     function mark(state, silent) {
    2908           0 :         var found, pos, stack, max = state.posMax, start = state.pos, lastChar, nextChar;
    2909           0 :         if (state.src.charCodeAt(start) !== 61) {
    2910           0 :             return false;
    2911           0 :         }
    2912           0 :         if (silent) {
    2913           0 :             return false;
    2914           0 :         }
    2915           0 :         if (start + 4 >= max) {
    2916           0 :             return false;
    2917           0 :         }
    2918           0 :         if (state.src.charCodeAt(start + 1) !== 61) {
    2919           0 :             return false;
    2920           0 :         }
    2921           0 :         if (state.level >= state.options.maxNesting) {
    2922           0 :             return false;
    2923           0 :         }
    2924           0 :         lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
    2925           0 :         nextChar = state.src.charCodeAt(start + 2);
    2926           0 :         if (lastChar === 61) {
    2927           0 :             return false;
    2928           0 :         }
    2929           0 :         if (nextChar === 61) {
    2930           0 :             return false;
    2931           0 :         }
    2932           0 :         if (nextChar === 32 || nextChar === 10) {
    2933           0 :             return false;
    2934           0 :         }
    2935           0 :         pos = start + 2;
    2936           0 :         while(pos < max && state.src.charCodeAt(pos) === 61){
    2937           0 :             pos++;
    2938           0 :         }
    2939           0 :         if (pos !== start + 2) {
    2940           0 :             state.pos += pos - start;
    2941           0 :             if (!silent) {
    2942           0 :                 state.pending += state.src.slice(start, pos);
    2943           0 :             }
    2944           0 :             return true;
    2945           0 :         }
    2946           0 :         state.pos = start + 2;
    2947           0 :         stack = 1;
    2948           0 :         while(state.pos + 1 < max){
    2949           0 :             if (state.src.charCodeAt(state.pos) === 61) {
    2950           0 :                 if (state.src.charCodeAt(state.pos + 1) === 61) {
    2951           0 :                     lastChar = state.src.charCodeAt(state.pos - 1);
    2952           0 :                     nextChar = state.pos + 2 < max ? state.src.charCodeAt(state.pos + 2) : -1;
    2953           0 :                     if (nextChar !== 61 && lastChar !== 61) {
    2954           0 :                         if (lastChar !== 32 && lastChar !== 10) {
    2955           0 :                             stack--;
    2956           0 :                         } else if (nextChar !== 32 && nextChar !== 10) {
    2957           0 :                             stack++;
    2958           0 :                         }
    2959           0 :                         if (stack <= 0) {
    2960           0 :                             found = true;
    2961           0 :                             break;
    2962           0 :                         }
    2963           0 :                     }
    2964           0 :                 }
    2965           0 :             }
    2966           0 :             state.parser.skipToken(state);
    2967           0 :         }
    2968           0 :         if (!found) {
    2969           0 :             state.pos = start;
    2970           0 :             return false;
    2971           0 :         }
    2972           0 :         state.posMax = state.pos;
    2973           0 :         state.pos = start + 2;
    2974           0 :         if (!silent) {
    2975           0 :             state.push({
    2976           0 :                 type: "mark_open",
    2977           0 :                 level: state.level++
    2978           0 :             });
    2979           0 :             state.parser.tokenize(state);
    2980           0 :             state.push({
    2981           0 :                 type: "mark_close",
    2982           0 :                 level: --state.level
    2983           0 :             });
    2984           0 :         }
    2985           0 :         state.pos = state.posMax + 2;
    2986           0 :         state.posMax = max;
    2987           0 :         return true;
    2988           0 :     }
    2989           0 :     function isAlphaNum(code2) {
    2990           0 :         return code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 90 || code2 >= 97 && code2 <= 122;
    2991           0 :     }
    2992           0 :     function scanDelims(state, start) {
    2993           0 :         var pos = start, lastChar, nextChar, count, can_open = true, can_close = true, max = state.posMax, marker = state.src.charCodeAt(start);
    2994           0 :         lastChar = start > 0 ? state.src.charCodeAt(start - 1) : -1;
    2995           0 :         while(pos < max && state.src.charCodeAt(pos) === marker){
    2996           0 :             pos++;
    2997           0 :         }
    2998           0 :         if (pos >= max) {
    2999           0 :             can_open = false;
    3000           0 :         }
    3001           0 :         count = pos - start;
    3002           0 :         if (count >= 4) {
    3003           0 :             can_open = can_close = false;
    3004           0 :         } else {
    3005           0 :             nextChar = pos < max ? state.src.charCodeAt(pos) : -1;
    3006           0 :             if (nextChar === 32 || nextChar === 10) {
    3007           0 :                 can_open = false;
    3008           0 :             }
    3009           0 :             if (lastChar === 32 || lastChar === 10) {
    3010           0 :                 can_close = false;
    3011           0 :             }
    3012           0 :             if (marker === 95) {
    3013           0 :                 if (isAlphaNum(lastChar)) {
    3014           0 :                     can_open = false;
    3015           0 :                 }
    3016           0 :                 if (isAlphaNum(nextChar)) {
    3017           0 :                     can_close = false;
    3018           0 :                 }
    3019           0 :             }
    3020           0 :         }
    3021           0 :         return {
    3022           0 :             can_open,
    3023           0 :             can_close,
    3024           0 :             delims: count
    3025           0 :         };
    3026           0 :     }
    3027           0 :     function emphasis(state, silent) {
    3028           0 :         var startCount, count, found, oldCount, newCount, stack, res, max = state.posMax, start = state.pos, marker = state.src.charCodeAt(start);
    3029           0 :         if (marker !== 95 && marker !== 42) {
    3030           0 :             return false;
    3031           0 :         }
    3032           0 :         if (silent) {
    3033           0 :             return false;
    3034           0 :         }
    3035           0 :         res = scanDelims(state, start);
    3036           0 :         startCount = res.delims;
    3037           0 :         if (!res.can_open) {
    3038           0 :             state.pos += startCount;
    3039           0 :             if (!silent) {
    3040           0 :                 state.pending += state.src.slice(start, state.pos);
    3041           0 :             }
    3042           0 :             return true;
    3043           0 :         }
    3044           0 :         if (state.level >= state.options.maxNesting) {
    3045           0 :             return false;
    3046           0 :         }
    3047           0 :         state.pos = start + startCount;
    3048           0 :         stack = [
    3049           0 :             startCount
    3050           0 :         ];
    3051           0 :         while(state.pos < max){
    3052           0 :             if (state.src.charCodeAt(state.pos) === marker) {
    3053           0 :                 res = scanDelims(state, state.pos);
    3054           0 :                 count = res.delims;
    3055           0 :                 if (res.can_close) {
    3056           0 :                     oldCount = stack.pop();
    3057           0 :                     newCount = count;
    3058           0 :                     while(oldCount !== newCount){
    3059           0 :                         if (newCount < oldCount) {
    3060           0 :                             stack.push(oldCount - newCount);
    3061           0 :                             break;
    3062           0 :                         }
    3063           0 :                         newCount -= oldCount;
    3064           0 :                         if (stack.length === 0) {
    3065           0 :                             break;
    3066           0 :                         }
    3067           0 :                         state.pos += oldCount;
    3068           0 :                         oldCount = stack.pop();
    3069           0 :                     }
    3070           0 :                     if (stack.length === 0) {
    3071           0 :                         startCount = oldCount;
    3072           0 :                         found = true;
    3073           0 :                         break;
    3074           0 :                     }
    3075           0 :                     state.pos += count;
    3076           0 :                     continue;
    3077           0 :                 }
    3078           0 :                 if (res.can_open) {
    3079           0 :                     stack.push(count);
    3080           0 :                 }
    3081           0 :                 state.pos += count;
    3082           0 :                 continue;
    3083           0 :             }
    3084           0 :             state.parser.skipToken(state);
    3085           0 :         }
    3086           0 :         if (!found) {
    3087           0 :             state.pos = start;
    3088           0 :             return false;
    3089           0 :         }
    3090           0 :         state.posMax = state.pos;
    3091           0 :         state.pos = start + startCount;
    3092           0 :         if (!silent) {
    3093           0 :             if (startCount === 2 || startCount === 3) {
    3094           0 :                 state.push({
    3095           0 :                     type: "strong_open",
    3096           0 :                     level: state.level++
    3097           0 :                 });
    3098           0 :             }
    3099           0 :             if (startCount === 1 || startCount === 3) {
    3100           0 :                 state.push({
    3101           0 :                     type: "em_open",
    3102           0 :                     level: state.level++
    3103           0 :                 });
    3104           0 :             }
    3105           0 :             state.parser.tokenize(state);
    3106           0 :             if (startCount === 1 || startCount === 3) {
    3107           0 :                 state.push({
    3108           0 :                     type: "em_close",
    3109           0 :                     level: --state.level
    3110           0 :                 });
    3111           0 :             }
    3112           0 :             if (startCount === 2 || startCount === 3) {
    3113           0 :                 state.push({
    3114           0 :                     type: "strong_close",
    3115           0 :                     level: --state.level
    3116           0 :                 });
    3117           0 :             }
    3118           0 :         }
    3119           0 :         state.pos = state.posMax + startCount;
    3120           0 :         state.posMax = max;
    3121           0 :         return true;
    3122           0 :     }
    3123           2 :     var UNESCAPE_RE = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;
    3124           0 :     function sub(state, silent) {
    3125           0 :         var found, content, max = state.posMax, start = state.pos;
    3126           0 :         if (state.src.charCodeAt(start) !== 126) {
    3127           0 :             return false;
    3128           0 :         }
    3129           0 :         if (silent) {
    3130           0 :             return false;
    3131           0 :         }
    3132           0 :         if (start + 2 >= max) {
    3133           0 :             return false;
    3134           0 :         }
    3135           0 :         if (state.level >= state.options.maxNesting) {
    3136           0 :             return false;
    3137           0 :         }
    3138           0 :         state.pos = start + 1;
    3139           0 :         while(state.pos < max){
    3140           0 :             if (state.src.charCodeAt(state.pos) === 126) {
    3141           0 :                 found = true;
    3142           0 :                 break;
    3143           0 :             }
    3144           0 :             state.parser.skipToken(state);
    3145           0 :         }
    3146           0 :         if (!found || start + 1 === state.pos) {
    3147           0 :             state.pos = start;
    3148           0 :             return false;
    3149           0 :         }
    3150           0 :         content = state.src.slice(start + 1, state.pos);
    3151           0 :         if (content.match(/(^|[^\\])(\\\\)*\s/)) {
    3152           0 :             state.pos = start;
    3153           0 :             return false;
    3154           0 :         }
    3155           0 :         state.posMax = state.pos;
    3156           0 :         state.pos = start + 1;
    3157           0 :         if (!silent) {
    3158           0 :             state.push({
    3159           0 :                 type: "sub",
    3160           0 :                 level: state.level,
    3161           0 :                 content: content.replace(UNESCAPE_RE, "$1")
    3162           0 :             });
    3163           0 :         }
    3164           0 :         state.pos = state.posMax + 1;
    3165           0 :         state.posMax = max;
    3166           0 :         return true;
    3167           0 :     }
    3168           2 :     var UNESCAPE_RE$1 = /\\([ \\!"#$%&'()*+,.\/:;<=>?@[\]^_`{|}~-])/g;
    3169           0 :     function sup(state, silent) {
    3170           0 :         var found, content, max = state.posMax, start = state.pos;
    3171           0 :         if (state.src.charCodeAt(start) !== 94) {
    3172           0 :             return false;
    3173           0 :         }
    3174           0 :         if (silent) {
    3175           0 :             return false;
    3176           0 :         }
    3177           0 :         if (start + 2 >= max) {
    3178           0 :             return false;
    3179           0 :         }
    3180           0 :         if (state.level >= state.options.maxNesting) {
    3181           0 :             return false;
    3182           0 :         }
    3183           0 :         state.pos = start + 1;
    3184           0 :         while(state.pos < max){
    3185           0 :             if (state.src.charCodeAt(state.pos) === 94) {
    3186           0 :                 found = true;
    3187           0 :                 break;
    3188           0 :             }
    3189           0 :             state.parser.skipToken(state);
    3190           0 :         }
    3191           0 :         if (!found || start + 1 === state.pos) {
    3192           0 :             state.pos = start;
    3193           0 :             return false;
    3194           0 :         }
    3195           0 :         content = state.src.slice(start + 1, state.pos);
    3196           0 :         if (content.match(/(^|[^\\])(\\\\)*\s/)) {
    3197           0 :             state.pos = start;
    3198           0 :             return false;
    3199           0 :         }
    3200           0 :         state.posMax = state.pos;
    3201           0 :         state.pos = start + 1;
    3202           0 :         if (!silent) {
    3203           0 :             state.push({
    3204           0 :                 type: "sup",
    3205           0 :                 level: state.level,
    3206           0 :                 content: content.replace(UNESCAPE_RE$1, "$1")
    3207           0 :             });
    3208           0 :         }
    3209           0 :         state.pos = state.posMax + 1;
    3210           0 :         state.posMax = max;
    3211           0 :         return true;
    3212           0 :     }
    3213           0 :     function links(state, silent) {
    3214           0 :         var labelStart, labelEnd, label, href, title, pos, ref, code2, isImage = false, oldPos = state.pos, max = state.posMax, start = state.pos, marker = state.src.charCodeAt(start);
    3215           0 :         if (marker === 33) {
    3216           0 :             isImage = true;
    3217           0 :             marker = state.src.charCodeAt(++start);
    3218           0 :         }
    3219           0 :         if (marker !== 91) {
    3220           0 :             return false;
    3221           0 :         }
    3222           0 :         if (state.level >= state.options.maxNesting) {
    3223           0 :             return false;
    3224           0 :         }
    3225           0 :         labelStart = start + 1;
    3226           0 :         labelEnd = parseLinkLabel(state, start);
    3227           0 :         if (labelEnd < 0) {
    3228           0 :             return false;
    3229           0 :         }
    3230           0 :         pos = labelEnd + 1;
    3231           0 :         if (pos < max && state.src.charCodeAt(pos) === 40) {
    3232           0 :             pos++;
    3233           0 :             for(; pos < max; pos++){
    3234           0 :                 code2 = state.src.charCodeAt(pos);
    3235           0 :                 if (code2 !== 32 && code2 !== 10) {
    3236           0 :                     break;
    3237           0 :                 }
    3238           0 :             }
    3239           0 :             if (pos >= max) {
    3240           0 :                 return false;
    3241           0 :             }
    3242           0 :             start = pos;
    3243           0 :             if (parseLinkDestination(state, pos)) {
    3244           0 :                 href = state.linkContent;
    3245           0 :                 pos = state.pos;
    3246           0 :             } else {
    3247           0 :                 href = "";
    3248           0 :             }
    3249           0 :             start = pos;
    3250           0 :             for(; pos < max; pos++){
    3251           0 :                 code2 = state.src.charCodeAt(pos);
    3252           0 :                 if (code2 !== 32 && code2 !== 10) {
    3253           0 :                     break;
    3254           0 :                 }
    3255           0 :             }
    3256           0 :             if (pos < max && start !== pos && parseLinkTitle(state, pos)) {
    3257           0 :                 title = state.linkContent;
    3258           0 :                 pos = state.pos;
    3259           0 :                 for(; pos < max; pos++){
    3260           0 :                     code2 = state.src.charCodeAt(pos);
    3261           0 :                     if (code2 !== 32 && code2 !== 10) {
    3262           0 :                         break;
    3263           0 :                     }
    3264           0 :                 }
    3265           0 :             } else {
    3266           0 :                 title = "";
    3267           0 :             }
    3268           0 :             if (pos >= max || state.src.charCodeAt(pos) !== 41) {
    3269           0 :                 state.pos = oldPos;
    3270           0 :                 return false;
    3271           0 :             }
    3272           0 :             pos++;
    3273           0 :         } else {
    3274           0 :             if (state.linkLevel > 0) {
    3275           0 :                 return false;
    3276           0 :             }
    3277           0 :             for(; pos < max; pos++){
    3278           0 :                 code2 = state.src.charCodeAt(pos);
    3279           0 :                 if (code2 !== 32 && code2 !== 10) {
    3280           0 :                     break;
    3281           0 :                 }
    3282           0 :             }
    3283           0 :             if (pos < max && state.src.charCodeAt(pos) === 91) {
    3284           0 :                 start = pos + 1;
    3285           0 :                 pos = parseLinkLabel(state, pos);
    3286           0 :                 if (pos >= 0) {
    3287           0 :                     label = state.src.slice(start, pos++);
    3288           0 :                 } else {
    3289           0 :                     pos = start - 1;
    3290           0 :                 }
    3291           0 :             }
    3292           0 :             if (!label) {
    3293           0 :                 if (typeof label === "undefined") {
    3294           0 :                     pos = labelEnd + 1;
    3295           0 :                 }
    3296           0 :                 label = state.src.slice(labelStart, labelEnd);
    3297           0 :             }
    3298           0 :             ref = state.env.references[normalizeReference(label)];
    3299           0 :             if (!ref) {
    3300           0 :                 state.pos = oldPos;
    3301           0 :                 return false;
    3302           0 :             }
    3303           0 :             href = ref.href;
    3304           0 :             title = ref.title;
    3305           0 :         }
    3306           0 :         if (!silent) {
    3307           0 :             state.pos = labelStart;
    3308           0 :             state.posMax = labelEnd;
    3309           0 :             if (isImage) {
    3310           0 :                 state.push({
    3311           0 :                     type: "image",
    3312           0 :                     src: href,
    3313           0 :                     title,
    3314           0 :                     alt: state.src.substr(labelStart, labelEnd - labelStart),
    3315           0 :                     level: state.level
    3316           0 :                 });
    3317           0 :             } else {
    3318           0 :                 state.push({
    3319           0 :                     type: "link_open",
    3320           0 :                     href,
    3321           0 :                     title,
    3322           0 :                     level: state.level++
    3323           0 :                 });
    3324           0 :                 state.linkLevel++;
    3325           0 :                 state.parser.tokenize(state);
    3326           0 :                 state.linkLevel--;
    3327           0 :                 state.push({
    3328           0 :                     type: "link_close",
    3329           0 :                     level: --state.level
    3330           0 :                 });
    3331           0 :             }
    3332           0 :         }
    3333           0 :         state.pos = pos;
    3334           0 :         state.posMax = max;
    3335           0 :         return true;
    3336           0 :     }
    3337           0 :     function footnote_inline(state, silent) {
    3338           0 :         var labelStart, labelEnd, footnoteId, oldLength, max = state.posMax, start = state.pos;
    3339           0 :         if (start + 2 >= max) {
    3340           0 :             return false;
    3341           0 :         }
    3342           0 :         if (state.src.charCodeAt(start) !== 94) {
    3343           0 :             return false;
    3344           0 :         }
    3345           0 :         if (state.src.charCodeAt(start + 1) !== 91) {
    3346           0 :             return false;
    3347           0 :         }
    3348           0 :         if (state.level >= state.options.maxNesting) {
    3349           0 :             return false;
    3350           0 :         }
    3351           0 :         labelStart = start + 2;
    3352           0 :         labelEnd = parseLinkLabel(state, start + 1);
    3353           0 :         if (labelEnd < 0) {
    3354           0 :             return false;
    3355           0 :         }
    3356           0 :         if (!silent) {
    3357           0 :             if (!state.env.footnotes) {
    3358           0 :                 state.env.footnotes = {
    3359           0 :                 };
    3360           0 :             }
    3361           0 :             if (!state.env.footnotes.list) {
    3362           0 :                 state.env.footnotes.list = [];
    3363           0 :             }
    3364           0 :             footnoteId = state.env.footnotes.list.length;
    3365           0 :             state.pos = labelStart;
    3366           0 :             state.posMax = labelEnd;
    3367           0 :             state.push({
    3368           0 :                 type: "footnote_ref",
    3369           0 :                 id: footnoteId,
    3370           0 :                 level: state.level
    3371           0 :             });
    3372           0 :             state.linkLevel++;
    3373           0 :             oldLength = state.tokens.length;
    3374           0 :             state.parser.tokenize(state);
    3375           0 :             state.env.footnotes.list[footnoteId] = {
    3376           0 :                 tokens: state.tokens.splice(oldLength)
    3377           0 :             };
    3378           0 :             state.linkLevel--;
    3379           0 :         }
    3380           0 :         state.pos = labelEnd + 1;
    3381           0 :         state.posMax = max;
    3382           0 :         return true;
    3383           0 :     }
    3384           0 :     function footnote_ref(state, silent) {
    3385           0 :         var label, pos, footnoteId, footnoteSubId, max = state.posMax, start = state.pos;
    3386           0 :         if (start + 3 > max) {
    3387           0 :             return false;
    3388           0 :         }
    3389           0 :         if (!state.env.footnotes || !state.env.footnotes.refs) {
    3390           0 :             return false;
    3391           0 :         }
    3392           0 :         if (state.src.charCodeAt(start) !== 91) {
    3393           0 :             return false;
    3394           0 :         }
    3395           0 :         if (state.src.charCodeAt(start + 1) !== 94) {
    3396           0 :             return false;
    3397           0 :         }
    3398           0 :         if (state.level >= state.options.maxNesting) {
    3399           0 :             return false;
    3400           0 :         }
    3401           0 :         for(pos = start + 2; pos < max; pos++){
    3402           0 :             if (state.src.charCodeAt(pos) === 32) {
    3403           0 :                 return false;
    3404           0 :             }
    3405           0 :             if (state.src.charCodeAt(pos) === 10) {
    3406           0 :                 return false;
    3407           0 :             }
    3408           0 :             if (state.src.charCodeAt(pos) === 93) {
    3409           0 :                 break;
    3410           0 :             }
    3411           0 :         }
    3412           0 :         if (pos === start + 2) {
    3413           0 :             return false;
    3414           0 :         }
    3415           0 :         if (pos >= max) {
    3416           0 :             return false;
    3417           0 :         }
    3418           0 :         pos++;
    3419           0 :         label = state.src.slice(start + 2, pos - 1);
    3420           0 :         if (typeof state.env.footnotes.refs[":" + label] === "undefined") {
    3421           0 :             return false;
    3422           0 :         }
    3423           0 :         if (!silent) {
    3424           0 :             if (!state.env.footnotes.list) {
    3425           0 :                 state.env.footnotes.list = [];
    3426           0 :             }
    3427           0 :             if (state.env.footnotes.refs[":" + label] < 0) {
    3428           0 :                 footnoteId = state.env.footnotes.list.length;
    3429           0 :                 state.env.footnotes.list[footnoteId] = {
    3430           0 :                     label,
    3431           0 :                     count: 0
    3432           0 :                 };
    3433           0 :                 state.env.footnotes.refs[":" + label] = footnoteId;
    3434           0 :             } else {
    3435           0 :                 footnoteId = state.env.footnotes.refs[":" + label];
    3436           0 :             }
    3437           0 :             footnoteSubId = state.env.footnotes.list[footnoteId].count;
    3438           0 :             state.env.footnotes.list[footnoteId].count++;
    3439           0 :             state.push({
    3440           0 :                 type: "footnote_ref",
    3441           0 :                 id: footnoteId,
    3442           0 :                 subId: footnoteSubId,
    3443           0 :                 level: state.level
    3444           0 :             });
    3445           0 :         }
    3446           0 :         state.pos = pos;
    3447           0 :         state.posMax = max;
    3448           0 :         return true;
    3449           0 :     }
    3450           2 :     var url_schemas = [
    3451           2 :         "coap",
    3452           2 :         "doi",
    3453           2 :         "javascript",
    3454           2 :         "aaa",
    3455           2 :         "aaas",
    3456           2 :         "about",
    3457           2 :         "acap",
    3458           2 :         "cap",
    3459           2 :         "cid",
    3460           2 :         "crid",
    3461           2 :         "data",
    3462           2 :         "dav",
    3463           2 :         "dict",
    3464           2 :         "dns",
    3465           2 :         "file",
    3466           2 :         "ftp",
    3467           2 :         "geo",
    3468           2 :         "go",
    3469           2 :         "gopher",
    3470           2 :         "h323",
    3471           2 :         "http",
    3472           2 :         "https",
    3473           2 :         "iax",
    3474           2 :         "icap",
    3475           2 :         "im",
    3476           2 :         "imap",
    3477           2 :         "info",
    3478           2 :         "ipp",
    3479           2 :         "iris",
    3480           2 :         "iris.beep",
    3481           2 :         "iris.xpc",
    3482           2 :         "iris.xpcs",
    3483           2 :         "iris.lwz",
    3484           2 :         "ldap",
    3485           2 :         "mailto",
    3486           2 :         "mid",
    3487           2 :         "msrp",
    3488           2 :         "msrps",
    3489           2 :         "mtqp",
    3490           2 :         "mupdate",
    3491           2 :         "news",
    3492           2 :         "nfs",
    3493           2 :         "ni",
    3494           2 :         "nih",
    3495           2 :         "nntp",
    3496           2 :         "opaquelocktoken",
    3497           2 :         "pop",
    3498           2 :         "pres",
    3499           2 :         "rtsp",
    3500           2 :         "service",
    3501           2 :         "session",
    3502           2 :         "shttp",
    3503           2 :         "sieve",
    3504           2 :         "sip",
    3505           2 :         "sips",
    3506           2 :         "sms",
    3507           2 :         "snmp",
    3508           2 :         "soap.beep",
    3509           2 :         "soap.beeps",
    3510           2 :         "tag",
    3511           2 :         "tel",
    3512           2 :         "telnet",
    3513           2 :         "tftp",
    3514           2 :         "thismessage",
    3515           2 :         "tn3270",
    3516           2 :         "tip",
    3517           2 :         "tv",
    3518           2 :         "urn",
    3519           2 :         "vemmi",
    3520           2 :         "ws",
    3521           2 :         "wss",
    3522           2 :         "xcon",
    3523           2 :         "xcon-userid",
    3524           2 :         "xmlrpc.beep",
    3525           2 :         "xmlrpc.beeps",
    3526           2 :         "xmpp",
    3527           2 :         "z39.50r",
    3528           2 :         "z39.50s",
    3529           2 :         "adiumxtra",
    3530           2 :         "afp",
    3531           2 :         "afs",
    3532           2 :         "aim",
    3533           2 :         "apt",
    3534           2 :         "attachment",
    3535           2 :         "aw",
    3536           2 :         "beshare",
    3537           2 :         "bitcoin",
    3538           2 :         "bolo",
    3539           2 :         "callto",
    3540           2 :         "chrome",
    3541           2 :         "chrome-extension",
    3542           2 :         "com-eventbrite-attendee",
    3543           2 :         "content",
    3544           2 :         "cvs",
    3545           2 :         "dlna-playsingle",
    3546           2 :         "dlna-playcontainer",
    3547           2 :         "dtn",
    3548           2 :         "dvb",
    3549           2 :         "ed2k",
    3550           2 :         "facetime",
    3551           2 :         "feed",
    3552           2 :         "finger",
    3553           2 :         "fish",
    3554           2 :         "gg",
    3555           2 :         "git",
    3556           2 :         "gizmoproject",
    3557           2 :         "gtalk",
    3558           2 :         "hcp",
    3559           2 :         "icon",
    3560           2 :         "ipn",
    3561           2 :         "irc",
    3562           2 :         "irc6",
    3563           2 :         "ircs",
    3564           2 :         "itms",
    3565           2 :         "jar",
    3566           2 :         "jms",
    3567           2 :         "keyparc",
    3568           2 :         "lastfm",
    3569           2 :         "ldaps",
    3570           2 :         "magnet",
    3571           2 :         "maps",
    3572           2 :         "market",
    3573           2 :         "message",
    3574           2 :         "mms",
    3575           2 :         "ms-help",
    3576           2 :         "msnim",
    3577           2 :         "mumble",
    3578           2 :         "mvn",
    3579           2 :         "notes",
    3580           2 :         "oid",
    3581           2 :         "palm",
    3582           2 :         "paparazzi",
    3583           2 :         "platform",
    3584           2 :         "proxy",
    3585           2 :         "psyc",
    3586           2 :         "query",
    3587           2 :         "res",
    3588           2 :         "resource",
    3589           2 :         "rmi",
    3590           2 :         "rsync",
    3591           2 :         "rtmp",
    3592           2 :         "secondlife",
    3593           2 :         "sftp",
    3594           2 :         "sgn",
    3595           2 :         "skype",
    3596           2 :         "smb",
    3597           2 :         "soldat",
    3598           2 :         "spotify",
    3599           2 :         "ssh",
    3600           2 :         "steam",
    3601           2 :         "svn",
    3602           2 :         "teamspeak",
    3603           2 :         "things",
    3604           2 :         "udp",
    3605           2 :         "unreal",
    3606           2 :         "ut2004",
    3607           2 :         "ventrilo",
    3608           2 :         "view-source",
    3609           2 :         "webcal",
    3610           2 :         "wtai",
    3611           2 :         "wyciwyg",
    3612           2 :         "xfire",
    3613           2 :         "xri",
    3614           2 :         "ymsgr"
    3615           2 :     ];
    3616           2 :     var EMAIL_RE = /^<([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/;
    3617           2 :     var AUTOLINK_RE = /^<([a-zA-Z.\-]{1,25}):([^<>\x00-\x20]*)>/;
    3618           0 :     function autolink(state, silent) {
    3619           0 :         var tail, linkMatch, emailMatch, url, fullUrl, pos = state.pos;
    3620           0 :         if (state.src.charCodeAt(pos) !== 60) {
    3621           0 :             return false;
    3622           0 :         }
    3623           0 :         tail = state.src.slice(pos);
    3624           0 :         if (tail.indexOf(">") < 0) {
    3625           0 :             return false;
    3626           0 :         }
    3627           0 :         linkMatch = tail.match(AUTOLINK_RE);
    3628           0 :         if (linkMatch) {
    3629           0 :             if (url_schemas.indexOf(linkMatch[1].toLowerCase()) < 0) {
    3630           0 :                 return false;
    3631           0 :             }
    3632           0 :             url = linkMatch[0].slice(1, -1);
    3633           0 :             fullUrl = normalizeLink(url);
    3634           0 :             if (!state.parser.validateLink(url)) {
    3635           0 :                 return false;
    3636           0 :             }
    3637           0 :             if (!silent) {
    3638           0 :                 state.push({
    3639           0 :                     type: "link_open",
    3640           0 :                     href: fullUrl,
    3641           0 :                     level: state.level
    3642           0 :                 });
    3643           0 :                 state.push({
    3644           0 :                     type: "text",
    3645           0 :                     content: url,
    3646           0 :                     level: state.level + 1
    3647           0 :                 });
    3648           0 :                 state.push({
    3649           0 :                     type: "link_close",
    3650           0 :                     level: state.level
    3651           0 :                 });
    3652           0 :             }
    3653           0 :             state.pos += linkMatch[0].length;
    3654           0 :             return true;
    3655           0 :         }
    3656           0 :         emailMatch = tail.match(EMAIL_RE);
    3657           0 :         if (emailMatch) {
    3658           0 :             url = emailMatch[0].slice(1, -1);
    3659           0 :             fullUrl = normalizeLink("mailto:" + url);
    3660           0 :             if (!state.parser.validateLink(fullUrl)) {
    3661           0 :                 return false;
    3662           0 :             }
    3663           0 :             if (!silent) {
    3664           0 :                 state.push({
    3665           0 :                     type: "link_open",
    3666           0 :                     href: fullUrl,
    3667           0 :                     level: state.level
    3668           0 :                 });
    3669           0 :                 state.push({
    3670           0 :                     type: "text",
    3671           0 :                     content: url,
    3672           0 :                     level: state.level + 1
    3673           0 :                 });
    3674           0 :                 state.push({
    3675           0 :                     type: "link_close",
    3676           0 :                     level: state.level
    3677           0 :                 });
    3678           0 :             }
    3679           0 :             state.pos += emailMatch[0].length;
    3680           0 :             return true;
    3681           0 :         }
    3682           0 :         return false;
    3683           0 :     }
    3684           2 :     function replace$1(regex, options) {
    3685           6 :         regex = regex.source;
    3686           6 :         options = options || "";
    3687           6 :         return function self(name, val) {
    3688          22 :             if (!name) {
    3689          26 :                 return new RegExp(regex, options);
    3690          22 :             }
    3691           0 :             val = val.source || val;
    3692          22 :             regex = regex.replace(name, val);
    3693          22 :             return self;
    3694           6 :         };
    3695           2 :     }
    3696           2 :     var attr_name = /[a-zA-Z_:][a-zA-Z0-9:._-]*/;
    3697           2 :     var unquoted = /[^"'=<>`\x00-\x20]+/;
    3698           2 :     var single_quoted = /'[^']*'/;
    3699           2 :     var double_quoted = /"[^"]*"/;
    3700           2 :     var attr_value = replace$1(/(?:unquoted|single_quoted|double_quoted)/)("unquoted", unquoted)("single_quoted", single_quoted)("double_quoted", double_quoted)();
    3701           2 :     var attribute = replace$1(/(?:\s+attr_name(?:\s*=\s*attr_value)?)/)("attr_name", attr_name)("attr_value", attr_value)();
    3702           2 :     var open_tag = replace$1(/<[A-Za-z][A-Za-z0-9]*attribute*\s*\/?>/)("attribute", attribute)();
    3703           2 :     var close_tag = /<\/[A-Za-z][A-Za-z0-9]*\s*>/;
    3704           2 :     var comment = /<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->/;
    3705           2 :     var processing = /<[?].*?[?]>/;
    3706           2 :     var declaration = /<![A-Z]+\s+[^>]*>/;
    3707           2 :     var cdata = /<!\[CDATA\[[\s\S]*?\]\]>/;
    3708           2 :     var HTML_TAG_RE = replace$1(/^(?:open_tag|close_tag|comment|processing|declaration|cdata)/)("open_tag", open_tag)("close_tag", close_tag)("comment", comment)("processing", processing)("declaration", declaration)("cdata", cdata)();
    3709           0 :     function isLetter$2(ch) {
    3710           0 :         var lc = ch | 32;
    3711           0 :         return lc >= 97 && lc <= 122;
    3712           0 :     }
    3713           0 :     function htmltag(state, silent) {
    3714           0 :         var ch, match, max, pos = state.pos;
    3715           0 :         if (!state.options.html) {
    3716           0 :             return false;
    3717           0 :         }
    3718           0 :         max = state.posMax;
    3719           0 :         if (state.src.charCodeAt(pos) !== 60 || pos + 2 >= max) {
    3720           0 :             return false;
    3721           0 :         }
    3722           0 :         ch = state.src.charCodeAt(pos + 1);
    3723           0 :         if (ch !== 33 && ch !== 63 && ch !== 47 && !isLetter$2(ch)) {
    3724           0 :             return false;
    3725           0 :         }
    3726           0 :         match = state.src.slice(pos).match(HTML_TAG_RE);
    3727           0 :         if (!match) {
    3728           0 :             return false;
    3729           0 :         }
    3730           0 :         if (!silent) {
    3731           0 :             state.push({
    3732           0 :                 type: "htmltag",
    3733           0 :                 content: state.src.slice(pos, pos + match[0].length),
    3734           0 :                 level: state.level
    3735           0 :             });
    3736           0 :         }
    3737           0 :         state.pos += match[0].length;
    3738           0 :         return true;
    3739           0 :     }
    3740           2 :     var DIGITAL_RE = /^&#((?:x[a-f0-9]{1,8}|[0-9]{1,8}));/i;
    3741           2 :     var NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i;
    3742           0 :     function entity(state, silent) {
    3743           0 :         var ch, code2, match, pos = state.pos, max = state.posMax;
    3744           0 :         if (state.src.charCodeAt(pos) !== 38) {
    3745           0 :             return false;
    3746           0 :         }
    3747           0 :         if (pos + 1 < max) {
    3748           0 :             ch = state.src.charCodeAt(pos + 1);
    3749           0 :             if (ch === 35) {
    3750           0 :                 match = state.src.slice(pos).match(DIGITAL_RE);
    3751           0 :                 if (match) {
    3752           0 :                     if (!silent) {
    3753           0 :                         code2 = match[1][0].toLowerCase() === "x" ? parseInt(match[1].slice(1), 16) : parseInt(match[1], 10);
    3754           0 :                         state.pending += isValidEntityCode(code2) ? fromCodePoint(code2) : fromCodePoint(65533);
    3755           0 :                     }
    3756           0 :                     state.pos += match[0].length;
    3757           0 :                     return true;
    3758           0 :                 }
    3759           0 :             } else {
    3760           0 :                 match = state.src.slice(pos).match(NAMED_RE);
    3761           0 :                 if (match) {
    3762           0 :                     var decoded = decodeEntity(match[1]);
    3763           0 :                     if (match[1] !== decoded) {
    3764           0 :                         if (!silent) {
    3765           0 :                             state.pending += decoded;
    3766           0 :                         }
    3767           0 :                         state.pos += match[0].length;
    3768           0 :                         return true;
    3769           0 :                     }
    3770           0 :                 }
    3771           0 :             }
    3772           0 :         }
    3773           0 :         if (!silent) {
    3774           0 :             state.pending += "&";
    3775           0 :         }
    3776           0 :         state.pos++;
    3777           0 :         return true;
    3778           0 :     }
    3779           2 :     var _rules$2 = [
    3780           2 :         [
    3781           2 :             "text",
    3782           2 :             text
    3783           2 :         ],
    3784           2 :         [
    3785           2 :             "newline",
    3786           2 :             newline
    3787           2 :         ],
    3788           2 :         [
    3789           2 :             "escape",
    3790           2 :             escape
    3791           2 :         ],
    3792           2 :         [
    3793           2 :             "backticks",
    3794           2 :             backticks
    3795           2 :         ],
    3796           2 :         [
    3797           2 :             "del",
    3798           2 :             del
    3799           2 :         ],
    3800           2 :         [
    3801           2 :             "ins",
    3802           2 :             ins
    3803           2 :         ],
    3804           2 :         [
    3805           2 :             "mark",
    3806           2 :             mark
    3807           2 :         ],
    3808           2 :         [
    3809           2 :             "emphasis",
    3810           2 :             emphasis
    3811           2 :         ],
    3812           2 :         [
    3813           2 :             "sub",
    3814           2 :             sub
    3815           2 :         ],
    3816           2 :         [
    3817           2 :             "sup",
    3818           2 :             sup
    3819           2 :         ],
    3820           2 :         [
    3821           2 :             "links",
    3822           2 :             links
    3823           2 :         ],
    3824           2 :         [
    3825           2 :             "footnote_inline",
    3826           2 :             footnote_inline
    3827           2 :         ],
    3828           2 :         [
    3829           2 :             "footnote_ref",
    3830           2 :             footnote_ref
    3831           2 :         ],
    3832           2 :         [
    3833           2 :             "autolink",
    3834           2 :             autolink
    3835           2 :         ],
    3836           2 :         [
    3837           2 :             "htmltag",
    3838           2 :             htmltag
    3839           2 :         ],
    3840           2 :         [
    3841           2 :             "entity",
    3842           2 :             entity
    3843           2 :         ]
    3844           2 :     ];
    3845           0 :     function ParserInline() {
    3846           0 :         this.ruler = new Ruler();
    3847           0 :         for(var i1 = 0; i1 < _rules$2.length; i1++){
    3848           0 :             this.ruler.push(_rules$2[i1][0], _rules$2[i1][1]);
    3849           0 :         }
    3850           0 :         this.validateLink = validateLink;
    3851           0 :     }
    3852           0 :     ParserInline.prototype.skipToken = function(state) {
    3853           0 :         var rules2 = this.ruler.getRules("");
    3854           0 :         var len = rules2.length;
    3855           0 :         var pos = state.pos;
    3856           0 :         var i1, cached_pos;
    3857           0 :         if ((cached_pos = state.cacheGet(pos)) > 0) {
    3858           0 :             state.pos = cached_pos;
    3859           0 :             return;
    3860           0 :         }
    3861           0 :         for(i1 = 0; i1 < len; i1++){
    3862           0 :             if (rules2[i1](state, true)) {
    3863           0 :                 state.cacheSet(pos, state.pos);
    3864           0 :                 return;
    3865           0 :             }
    3866           0 :         }
    3867           0 :         state.pos++;
    3868           0 :         state.cacheSet(pos, state.pos);
    3869           0 :     };
    3870           0 :     ParserInline.prototype.tokenize = function(state) {
    3871           0 :         var rules2 = this.ruler.getRules("");
    3872           0 :         var len = rules2.length;
    3873           0 :         var end = state.posMax;
    3874           0 :         var ok, i1;
    3875           0 :         while(state.pos < end){
    3876           0 :             for(i1 = 0; i1 < len; i1++){
    3877           0 :                 ok = rules2[i1](state, false);
    3878           0 :                 if (ok) {
    3879           0 :                     break;
    3880           0 :                 }
    3881           0 :             }
    3882           0 :             if (ok) {
    3883           0 :                 if (state.pos >= end) {
    3884           0 :                     break;
    3885           0 :                 }
    3886           0 :                 continue;
    3887           0 :             }
    3888           0 :             state.pending += state.src[state.pos++];
    3889           0 :         }
    3890           0 :         if (state.pending) {
    3891           0 :             state.pushPending();
    3892           0 :         }
    3893           0 :     };
    3894           0 :     ParserInline.prototype.parse = function(str, options, env, outTokens) {
    3895           0 :         var state = new StateInline(str, this, options, env, outTokens);
    3896           0 :         this.tokenize(state);
    3897           0 :     };
    3898           0 :     function validateLink(url) {
    3899           0 :         var BAD_PROTOCOLS = [
    3900           0 :             "vbscript",
    3901           0 :             "javascript",
    3902           0 :             "file",
    3903           0 :             "data"
    3904           0 :         ];
    3905           0 :         var str = url.trim().toLowerCase();
    3906           0 :         str = replaceEntities(str);
    3907           0 :         if (str.indexOf(":") !== -1 && BAD_PROTOCOLS.indexOf(str.split(":")[0]) !== -1) {
    3908           0 :             return false;
    3909           0 :         }
    3910           0 :         return true;
    3911           0 :     }
    3912           2 :     var defaultConfig = {
    3913           2 :         options: {
    3914           2 :             html: false,
    3915           2 :             xhtmlOut: false,
    3916           2 :             breaks: false,
    3917           2 :             langPrefix: "language-",
    3918           2 :             linkTarget: "",
    3919           2 :             typographer: false,
    3920           2 :             quotes: "\u201C\u201D\u2018\u2019",
    3921           2 :             highlight: null,
    3922           2 :             maxNesting: 20
    3923           2 :         },
    3924           2 :         components: {
    3925           2 :             core: {
    3926           2 :                 rules: [
    3927           2 :                     "block",
    3928           2 :                     "inline",
    3929           2 :                     "references",
    3930           2 :                     "replacements",
    3931           2 :                     "smartquotes",
    3932           2 :                     "references",
    3933           2 :                     "abbr2",
    3934           2 :                     "footnote_tail"
    3935           2 :                 ]
    3936           2 :             },
    3937           2 :             block: {
    3938           2 :                 rules: [
    3939           2 :                     "blockquote",
    3940           2 :                     "code",
    3941           2 :                     "fences",
    3942           2 :                     "footnote",
    3943           2 :                     "heading",
    3944           2 :                     "hr",
    3945           2 :                     "htmlblock",
    3946           2 :                     "lheading",
    3947           2 :                     "list",
    3948           2 :                     "paragraph",
    3949           2 :                     "table"
    3950           2 :                 ]
    3951           2 :             },
    3952           2 :             inline: {
    3953           2 :                 rules: [
    3954           2 :                     "autolink",
    3955           2 :                     "backticks",
    3956           2 :                     "del",
    3957           2 :                     "emphasis",
    3958           2 :                     "entity",
    3959           2 :                     "escape",
    3960           2 :                     "footnote_ref",
    3961           2 :                     "htmltag",
    3962           2 :                     "links",
    3963           2 :                     "newline",
    3964           2 :                     "text"
    3965           2 :                 ]
    3966           2 :             }
    3967           2 :         }
    3968           2 :     };
    3969           2 :     var fullConfig = {
    3970           2 :         options: {
    3971           2 :             html: false,
    3972           2 :             xhtmlOut: false,
    3973           2 :             breaks: false,
    3974           2 :             langPrefix: "language-",
    3975           2 :             linkTarget: "",
    3976           2 :             typographer: false,
    3977           2 :             quotes: "\u201C\u201D\u2018\u2019",
    3978           2 :             highlight: null,
    3979           2 :             maxNesting: 20
    3980           2 :         },
    3981           2 :         components: {
    3982           2 :             core: {
    3983           2 :             },
    3984           2 :             block: {
    3985           2 :             },
    3986           2 :             inline: {
    3987           2 :             }
    3988           2 :         }
    3989           2 :     };
    3990           2 :     var commonmarkConfig = {
    3991           2 :         options: {
    3992           2 :             html: true,
    3993           2 :             xhtmlOut: true,
    3994           2 :             breaks: false,
    3995           2 :             langPrefix: "language-",
    3996           2 :             linkTarget: "",
    3997           2 :             typographer: false,
    3998           2 :             quotes: "\u201C\u201D\u2018\u2019",
    3999           2 :             highlight: null,
    4000           2 :             maxNesting: 20
    4001           2 :         },
    4002           2 :         components: {
    4003           2 :             core: {
    4004           2 :                 rules: [
    4005           2 :                     "block",
    4006           2 :                     "inline",
    4007           2 :                     "references",
    4008           2 :                     "abbr2"
    4009           2 :                 ]
    4010           2 :             },
    4011           2 :             block: {
    4012           2 :                 rules: [
    4013           2 :                     "blockquote",
    4014           2 :                     "code",
    4015           2 :                     "fences",
    4016           2 :                     "heading",
    4017           2 :                     "hr",
    4018           2 :                     "htmlblock",
    4019           2 :                     "lheading",
    4020           2 :                     "list",
    4021           2 :                     "paragraph"
    4022           2 :                 ]
    4023           2 :             },
    4024           2 :             inline: {
    4025           2 :                 rules: [
    4026           2 :                     "autolink",
    4027           2 :                     "backticks",
    4028           2 :                     "emphasis",
    4029           2 :                     "entity",
    4030           2 :                     "escape",
    4031           2 :                     "htmltag",
    4032           2 :                     "links",
    4033           2 :                     "newline",
    4034           2 :                     "text"
    4035           2 :                 ]
    4036           2 :             }
    4037           2 :         }
    4038           2 :     };
    4039           2 :     var config = {
    4040           2 :         default: defaultConfig,
    4041           2 :         full: fullConfig,
    4042           2 :         commonmark: commonmarkConfig
    4043           2 :     };
    4044           0 :     function StateCore(instance, str, env) {
    4045           0 :         this.src = str;
    4046           0 :         this.env = env;
    4047           0 :         this.options = instance.options;
    4048           0 :         this.tokens = [];
    4049           0 :         this.inlineMode = false;
    4050           0 :         this.inline = instance.inline;
    4051           0 :         this.block = instance.block;
    4052           0 :         this.renderer = instance.renderer;
    4053           0 :         this.typographer = instance.typographer;
    4054           0 :     }
    4055           0 :     function Remarkable(preset, options) {
    4056           0 :         if (typeof preset !== "string") {
    4057           0 :             options = preset;
    4058           0 :             preset = "default";
    4059           0 :         }
    4060           0 :         if (options && options.linkify != null) {
    4061           0 :             console.warn("linkify option is removed. Use linkify plugin instead:\n\nimport Remarkable from 'remarkable';\nimport linkify from 'remarkable/linkify';\nnew Remarkable().use(linkify)\n");
    4062           0 :         }
    4063           0 :         this.inline = new ParserInline();
    4064           0 :         this.block = new ParserBlock();
    4065           0 :         this.core = new Core();
    4066           0 :         this.renderer = new Renderer();
    4067           0 :         this.ruler = new Ruler();
    4068           0 :         this.options = {
    4069           0 :         };
    4070           0 :         this.configure(config[preset]);
    4071           0 :         this.set(options || {
    4072           0 :         });
    4073           0 :     }
    4074           0 :     Remarkable.prototype.set = function(options) {
    4075           0 :         assign(this.options, options);
    4076           0 :     };
    4077           0 :     Remarkable.prototype.configure = function(presets) {
    4078           0 :         var self = this;
    4079           0 :         if (!presets) {
    4080           0 :             throw new Error("Wrong `remarkable` preset, check name/content");
    4081           0 :         }
    4082           0 :         if (presets.options) {
    4083           0 :             self.set(presets.options);
    4084           0 :         }
    4085           0 :         if (presets.components) {
    4086           0 :             Object.keys(presets.components).forEach(function(name) {
    4087           0 :                 if (presets.components[name].rules) {
    4088           0 :                     self[name].ruler.enable(presets.components[name].rules, true);
    4089           0 :                 }
    4090           0 :             });
    4091           0 :         }
    4092           0 :     };
    4093           0 :     Remarkable.prototype.use = function(plugin, options) {
    4094           0 :         plugin(this, options);
    4095           0 :         return this;
    4096           0 :     };
    4097           0 :     Remarkable.prototype.parse = function(str, env) {
    4098           0 :         var state = new StateCore(this, str, env);
    4099           0 :         this.core.process(state);
    4100           0 :         return state.tokens;
    4101           0 :     };
    4102           0 :     Remarkable.prototype.render = function(str, env) {
    4103           0 :         env = env || {
    4104           0 :         };
    4105           0 :         return this.renderer.render(this.parse(str, env), this.options, env);
    4106           0 :     };
    4107           0 :     Remarkable.prototype.parseInline = function(str, env) {
    4108           0 :         var state = new StateCore(this, str, env);
    4109           0 :         state.inlineMode = true;
    4110           0 :         this.core.process(state);
    4111           0 :         return state.tokens;
    4112           0 :     };
    4113           0 :     Remarkable.prototype.renderInline = function(str, env) {
    4114           0 :         env = env || {
    4115           0 :         };
    4116           0 :         return this.renderer.render(this.parseInline(str, env), this.options, env);
    4117           0 :     };
    4118           2 :     const Remarkable1 = Remarkable;
    4119           2 :     return {
    4120           2 :         Remarkable: Remarkable,
    4121           2 :         utils: utils
    4122           1 :     };
    4123           1 : }();
    4124           1 : var require$$0 = getDefaultExportFromNamespaceIfNotNamed(mod);
    4125           0 : const { utils: { escapeHtml  }  } = require$$0;
    4126           0 : function wikilinkRule(state, silent) {
    4127           0 :     const { pos: start , src , posMax  } = state;
    4128           0 :     const ch = src.charCodeAt(start);
    4129           0 :     if (ch !== 91) return false;
    4130           0 :     if (start + 4 >= posMax) return false;
    4131           0 :     if (src.charCodeAt(start + 1) !== 91) return false;
    4132           0 :     const labelStart = start + 2;
    4133           0 :     let labelEnd = start + 2;
    4134           0 :     state.pos = start + 2;
    4135           0 :     let found = false;
    4136           0 :     while(state.pos + 1 < posMax){
    4137           0 :         if (src.charCodeAt(state.pos) === 93) {
    4138           0 :             if (src.charCodeAt(state.pos + 1) === 93) {
    4139           0 :                 labelEnd = state.pos;
    4140           0 :                 found = true;
    4141           0 :                 break;
    4142           0 :             }
    4143           0 :         }
    4144           0 :         state.parser.skipToken(state);
    4145           0 :     }
    4146           0 :     if (!found) {
    4147           0 :         state.pos = start;
    4148           0 :         return false;
    4149           0 :     }
    4150           0 :     state.posMax = state.pos;
    4151           0 :     state.pos = start + 2;
    4152           0 :     if (!silent) {
    4153           0 :         state.push({
    4154           0 :             type: "wikilink_open",
    4155           0 :             href: src.substring(labelStart, labelEnd),
    4156           0 :             level: state.level++
    4157           0 :         });
    4158           0 :         state.linkLevel++;
    4159           0 :         state.parser.tokenize(state);
    4160           0 :         state.linkLevel--;
    4161           0 :         state.push({
    4162           0 :             type: "wikilink_close",
    4163           0 :             level: --state.level
    4164           0 :         });
    4165           0 :     }
    4166           0 :     state.pos = state.posMax + 2;
    4167           0 :     state.posMax = posMax;
    4168           0 :     return true;
    4169           1 : }
    4170           0 : const wikilink_open = function(tokens, idx, options) {
    4171           0 :     return `<a href="${escapeHtml(encodeURIComponent(tokens[idx].href))}" class="wikilink">`;
    4172           1 : };
    4173           0 : const wikilink_close = function() {
    4174           0 :     return "</a>";
    4175           1 : };
    4176           1 : var remarkableWikilink = function wikilink(md, opts) {
    4177           2 :     md.inline.ruler.push("wikilink", wikilinkRule);
    4178           2 :     md.renderer.rules.wikilink_open = wikilink_open;
    4179           1 :     md.renderer.rules.wikilink_close = wikilink_close;
    4180           1 : };
    4181           0 : export { remarkableWikilink as default };

Generated by: LCOV version 1.15