LCOV - code coverage report
Current view: top level - external - remarkable.js (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 765 4114 18.6 %
Date: 2021-03-12 10:43:40 Functions: 17 179 9.5 %

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

Generated by: LCOV version 1.15