(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('marked'), require('prismjs')) : typeof define === 'function' && define.amd ? define(['marked', 'prismjs'], factory) : (global.Docsify = factory(global.marked,global.Prism)); }(this, (function (marked,Prism) { 'use strict'; marked = 'default' in marked ? marked['default'] : marked; Prism = 'default' in Prism ? Prism['default'] : Prism; var ajax = function (url, options) { if ( options === void 0 ) options = {}; var xhr = new XMLHttpRequest(); xhr.open(options.method || 'get', url); xhr.send(); return { then: function (cb) { return xhr.addEventListener('load', cb); } } }; /** * @link from https://github.com/killercup/grock/blob/5280ae63e16c5739e9233d9009bc235ed7d79a50/styles/solarized/assets/js/behavior.coffee#L54-L81 */ var tocToTree = function (toc) { var headlines = []; var last = {}; toc.forEach(function (headline) { var level = headline.level || 1; var len = level - 1; if (last[len]) { last[len].children = last[len].children || []; last[len].children.push(headline); } else { headlines.push(headline); last[level] = headline; } }); return headlines }; var buildHeadlinesTree = function (tree, tpl) { if ( tpl === void 0 ) tpl = ''; if (!tree || !tree.length) { return '' } tree.forEach(function (node) { tpl += "
  • " + (node.title) + "
  • "; if (node.children) { tpl += "
  • ' }; var genToc = function (toc) { return buildHeadlinesTree(tocToTree(toc), '