module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;
/******/
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			i: moduleId,
/******/ 			l: false,
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ 		// Flag the module as loaded
/******/ 		module.l = true;
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/******/
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
/******/
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
/******/
/******/ 	// identity function for calling harmory imports with the correct context
/******/ 	__webpack_require__.i = function(value) { return value; };
/******/
/******/ 	// define getter function for harmory exports
/******/ 	__webpack_require__.d = function(exports, name, getter) {
/******/ 		Object.defineProperty(exports, name, {
/******/ 			configurable: false,
/******/ 			enumerable: true,
/******/ 			get: getter
/******/ 		});
/******/ 	};
/******/
/******/ 	// getDefaultExport function for compatibility with non-harmony modules
/******/ 	__webpack_require__.n = function(module) {
/******/ 		var getter = module && module.__esModule ?
/******/ 			function getDefault() { return module['default']; } :
/******/ 			function getModuleExports() { return module; };
/******/ 		__webpack_require__.d(getter, 'a', getter);
/******/ 		return getter;
/******/ 	};
/******/
/******/ 	// Object.prototype.hasOwnProperty.call
/******/ 	__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "/";
/******/
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(__webpack_require__.s = 144);
/******/ })
/************************************************************************/
/******/ ({

/***/ "./src/markdown-ast-interface.js":
/***/ function(module, exports, __webpack_require__) {

"use strict";
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.decorateNode = undefined;

var _typeof2 = __webpack_require__(22);

var _typeof3 = _interopRequireDefault(_typeof2);

var _toConsumableArray2 = __webpack_require__(6);

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _promise = __webpack_require__(4);

var _promise2 = _interopRequireDefault(_promise);

var _keys = __webpack_require__(7);

var _keys2 = _interopRequireDefault(_keys);

var _assign = __webpack_require__(1);

var _assign2 = _interopRequireDefault(_assign);

exports.isNode = isNode;
exports.createBlock = createBlock;

var _string = __webpack_require__(18);

var _cloneDeep = __webpack_require__(122);

var _cloneDeep2 = _interopRequireDefault(_cloneDeep);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = function (doc) {
  var ast = doc.ast;

  if (!doc.ast) {
    console.log('Could not find', doc);
  }

  doc.ast = (0, _assign2.default)(ast, {
    children: ast.children.map(function (node) {
      return _decorateNode(doc, node);
    })
  });

  if (!doc.chain) {
    Object.defineProperty(doc, 'chain', {
      enumerable: false,
      get: function get() {
        return require('lodash').chain(doc);
      }
    });
  }

  return (0, _assign2.default)(doc, {
    decorateNode: function decorateNode(node) {
      return _decorateNode(doc, node);
    },
    createTree: function createTree() {
      var headings = doc.createHeadingsMap('headingPath');

      var tree = {};

      (0, _keys2.default)(headings).forEach(function (headingPath) {
        var treePath = headingPath.split('/').map(function (v) {
          return (0, _string.camelCase)((0, _string.kebabCase)(v));
        });
        lodash.set(tree, treePath, headings[headingPath]);
      });

      return tree;
    },
    createHeadingsMap: function createHeadingsMap() {
      var keyBy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'accessor';
      var stayChained = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

      var obj = doc.chain.invoke('selectHeadingNodes').map(function (heading) {
        heading.accessorMethod = (0, _string.camelCase)((0, _string.snakeCase)(heading.textContent()));
        heading.headingPath = heading.getHeadingPath();
        heading.accessors = heading.headingPath.split('/').map(function (i) {
          return (0, _string.camelCase)((0, _string.snakeCase)(i));
        });
        heading.accessor = (0, _string.camelCase)((0, _string.snakeCase)(heading.headingPath.replace(/\//g, '_')));
        return heading;
      }).keyBy(keyBy);

      return stayChained ? obj : obj.value();
    },
    stringifyNode: function stringifyNode(node) {
      return __webpack_require__(15)(node);
    },
    getSourceForNode: function getSourceForNode(node) {
      return __webpack_require__(19)(node);
    },
    headingRange: function headingRange(test) {
      var ast = doc.ast;

      return new _promise2.default(function (resolve, reject) {
        try {
          __webpack_require__(17)(ast, test, function (startNode, nodes, endNode) {
            resolve({ startNode: startNode, nodes: nodes, endNode: endNode });
          });
        } catch (error) {
          reject(error);
        }
      });
    },
    documentTitle: function documentTitle() {
      var titleNode = doc.titleNode();

      if (!titleNode) {
        return doc.get('frontmatter.title', doc.variations.humanized);
      } else {
        return titleNode.textContent();
      }
    },
    introParagraphs: function introParagraphs() {
      var until = doc.selectHeadingNodes()[1] || doc.finalNode();

      if (!until) {
        return doc.selectNodes('paragraph');
      } else {
        var _children = until.getNodesBefore(function (node) {
          return ['paragraph'].indexOf(node.type) >= 0;
        }).reverse();

        return __webpack_require__(15)({ type: 'root', children: _children });
      }
    },
    withoutNodeIndexes: function withoutNodeIndexes() {
      var indexList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];

      var ast = this.ast;

      return {
        type: 'root',
        children: children.filter(function (node) {
          return indexList.indexOf(node.index) === -1;
        }),
        data: ast.data
      };
    },
    createAST: function createAST() {
      var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

      var newAST = {
        type: options.type || 'root',
        children: options.children || [],
        data: options.data || {}
      };

      return newAST;
    },
    extractSectionNodes: function extractSectionNodes(node) {
      return node.headingRange().then(function (_ref) {
        var nodes = _ref.nodes;
        return nodes;
      });
    },
    inspectOutline: function inspectOutline() {
      var headings = this.selectHeadingNodes();

      return headings.map(function (headingNode) {
        var content = '- ' + headingNode.textContent();
        return lodash.padStart(content, content.length + (headingNode.depth - 1) * 2);
      }).join("\n");
    },
    headingIndexes: function headingIndexes(depth) {
      return this.chain.invoke('selectHeadingNodes', depth && '[depth=' + depth + ']').sortBy(function (node) {
        return node.position ? node.position.start.line : node.index;
      }).map(function (node) {
        return node.index;
      }).value();
    },
    references: function references() {
      return (0, _assign2.default)({}, this.referenceImages(), this.referenceLinks());
    },
    referenceImages: function referenceImages() {
      return this.chain.invoke('selectNodes', 'imageReference').keyBy('identifier').mapValues(function (refLink, identifier) {
        var definitionNodes = doc.definitionNodes();

        return (0, _assign2.default)(refLink, {
          definitionNode: function definitionNode() {
            return definitionNodes[identifier];
          },

          get definition() {
            return lodash.pick(definitionNodes[identifier], 'title', 'url', 'identifier');
          }
        });
      }).value();
    },
    imageNodes: function imageNodes() {
      return this.selectNodes('image');
    },
    referenceLinks: function referenceLinks() {
      return this.chain.invoke('selectNodes', 'linkReference').keyBy('identifier').mapValues(function (refLink, identifier) {
        var definitionNodes = doc.definitionNodes();

        return (0, _assign2.default)(refLink, {
          definitionNode: function definitionNode() {
            return definitionNodes[identifier];
          },

          get definition() {
            return lodash.pick(definitionNodes[identifier], 'title', 'url', 'identifier');
          }
        });
      }).value();
    },
    definitionNodes: function definitionNodes() {
      return this.chain.invoke('selectNodes', 'definition').keyBy('identifier').value();
    },
    selectHeadingsByDepth: function selectHeadingsByDepth() {
      var depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;

      return this.selectHeadingNodes('[depth=' + depth + ']');
    },
    selectOneNode: function selectOneNode(selector) {
      return __webpack_require__(5)(this.ast)(selector)[0];
    },
    selectNodes: function selectNodes() {
      var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '*';
      var testFn = arguments[1];

      var results = __webpack_require__(5)(this.ast)(selector);

      return typeof testFn === 'function' ? results.filter(function (r) {
        return testFn.call(doc, r);
      }) : results;
    },
    selectHeadingNodes: function selectHeadingNodes() {
      var enhance = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';

      return doc.selectNodes(('heading' + enhance).trim());
    },
    selectCodeBlocks: function selectCodeBlocks() {
      var lang = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'javascript';
      var enhance = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

      return doc.selectNodes(('code[lang=' + lang + ']' + enhance).trim());
    },
    findNodeAfter: function findNodeAfter(node) {
      for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
        args[_key - 1] = arguments[_key];
      }

      return __webpack_require__(24).apply(undefined, [this.ast, node].concat((0, _toConsumableArray3.default)(args)));
    },
    findAllNodesAfter: function findAllNodesAfter(node) {
      for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
        args[_key2 - 1] = arguments[_key2];
      }

      return __webpack_require__(25).apply(undefined, [this.ast, node].concat((0, _toConsumableArray3.default)(args)));
    },
    findAllNodesBefore: function findAllNodesBefore(node) {
      for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
        args[_key3 - 1] = arguments[_key3];
      }

      return __webpack_require__(26).apply(undefined, [this.ast, node].concat((0, _toConsumableArray3.default)(args)));
    },
    nodesIndexedByPosition: function nodesIndexedByPosition() {
      return doc.chain.get('ast.children').keyBy(function (node) {
        return parseInt(node.position.start.line);
      }).value();
    },
    introNodes: function introNodes() {
      var f = this.selectNodes('heading');
      var m = f.find(function (n) {
        return n.depth > 1;
      });

      var nodes = m ? m.getNodesBefore().reverse() : this.ast.children;

      return nodes.filter(function (n) {
        return n.type !== 'yaml';
      });
    },
    finalHeading: function finalHeading() {
      return this.selectNodes('heading:last-of-type');
    },
    titleNode: function titleNode() {
      return this.selectOneNode('heading[depth=1]') || this.selectOneNode('heading:first-of-type');
    },
    firstSectionHeadingNode: function firstSectionHeadingNode() {
      return this.selectOneNode('heading[depth=2]');
    },
    sectionHeadingNodes: function sectionHeadingNodes() {
      return this.selectNodes('heading[depth=2]');
    },
    articleHeadingNodes: function articleHeadingNodes() {
      return this.selectNodes('heading[depth=3]');
    },
    subarticleHeadingNodes: function subarticleHeadingNodes() {
      return this.selectNodes('heading').filter(function (n) {
        return n.depth >= 4;
      });
    },
    getNodesBetweenPositions: function getNodesBetweenPositions(alpha, bravo) {
      var start = isNode(alpha) ? alpha.position.start.line : parseInt(alpha);
      var end = isNode(bravo) ? bravo.position.start.line : parseInt(bravo);

      return doc.chain.get('ast.children').filter(function (node) {
        var line = node.position.start.line;


        return line > start && line < end;
      });
    },
    firstNode: function firstNode() {
      return this.chain.get('ast.children', []).first().value();
    },
    finalNode: function finalNode() {
      return this.chain.get('ast.children', []).last().value();
    }
  });
};

function _decorateNode(doc, node) {
  var _original = (0, _cloneDeep2.default)(node);

  return (0, _assign2.default)(node, {
    original: function original() {
      return _original;
    },
    slug: function slug() {
      return (0, _string.kebabCase)(this.textContent());
    },
    textContent: function textContent() {
      return __webpack_require__(15)(node) || '';
    },
    getHeadingPath: function getHeadingPath() {
      if (node.type !== 'heading') {
        var prev = node.previousHeading();
        return prev && prev.getHeadingPath();
      }

      var textContent = (0, _string.kebabCase)(node.textContent().toLowerCase());
      var prevSuperior = node.getPreviousSuperior();
      var previousPath = typeof prevSuperior === 'undefined' ? '' : prevSuperior.depth >= 2 && prevSuperior.getHeadingPath() || '';

      return [previousPath, textContent].filter(function (i) {
        return i && i.length > 0;
      }).join('/');
    },
    headingRangeSync: function headingRangeSync() {
      var alpha = node;
      var bravo = node.getFinalHeading() || doc.finalNode();

      return doc.getNodesBetweenPositions(alpha, bravo || 50000).value();
    },
    headingRange: function headingRange() {
      var test = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : node.textContent();

      var ast = doc.ast;

      return new _promise2.default(function (resolve, reject) {
        try {
          __webpack_require__(17)(ast, test, function (startNode, nodes, endNode) {
            resolve({ startNode: startNode, nodes: nodes, endNode: endNode });
          });
        } catch (error) {
          reject(error);
        }
      });
    },
    getFinalHeading: function getFinalHeading() {
      return doc.findAllNodesAfter(node, function (n) {
        return n.type === 'heading' && n.depth <= node.depth;
      })[0];
    },
    getPreviousSuperior: function getPreviousSuperior() {
      return node && node.getNodesBefore && node.getNodesBefore(function (n) {
        return n.type === 'heading' && n.depth < node.depth;
      })[0];
    },
    previousHeading: function previousHeading() {
      return node.getNodesBefore(function (n) {
        return n.type === 'heading';
      }).shift();
    },
    nextHeading: function nextHeading() {
      return node.type === 'heading' ? node.getNextNode(function (n) {
        return n.type === 'heading' && n.depth >= node.depth;
      }) : node.getNextNode(function (n) {
        return n.type === 'heading';
      });
    },
    getNextNode: function getNextNode() {
      for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
        args[_key4] = arguments[_key4];
      }

      return doc.findNodeAfter.apply(doc, [node].concat((0, _toConsumableArray3.default)(args)));
    },
    getNodesAfter: function getNodesAfter() {
      for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
        args[_key5] = arguments[_key5];
      }

      return doc.findAllNodesAfter.apply(doc, [node].concat((0, _toConsumableArray3.default)(args)));
    },
    getNodesBefore: function getNodesBefore() {
      for (var _len6 = arguments.length, args = Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
        args[_key6] = arguments[_key6];
      }

      return doc.findAllNodesBefore.apply(doc, [node].concat((0, _toConsumableArray3.default)(args)));
    },
    selectChildren: function selectChildren(selector, testFn) {
      if (node.type === 'heading') {
        return node.selectHeadingChildren(selector, testFn);
      }

      var results = __webpack_require__(5)(node)(selector);

      return typeof testFn === 'function' ? results.filter(function (r) {
        return testFn.call(doc, r);
      }) : results;
    },
    virtualAST: function virtualAST() {
      return {
        type: 'root',
        children: node.headingRangeSync().map(function (n) {
          return n.original();
        }).map(function (n, i) {
          n.index = i;
          return n;
        })
      };
    },
    selectHeadingChildrenSync: function selectHeadingChildrenSync() {
      var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '*';
      var testFn = arguments[1];

      var results = __webpack_require__(5)(node.virtualAST())(selector);

      results = typeof testFn === 'function' ? results.filter(function (r) {
        return testFn.call(doc, r);
      }) : results;

      return results;
    },
    selectHeadingChildren: function selectHeadingChildren() {
      var selector = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '*';
      var testFn = arguments[1];

      return node.headingRange().then(function (_ref2) {
        var nodes = _ref2.nodes;

        var base = {
          type: 'root',
          children: nodes
        };

        return __webpack_require__(5)(base)(selector);
      }).then(function (results) {
        return typeof testFn === 'function' ? results.filter(function (r) {
          return testFn.call(doc, r);
        }) : results;
      });
    }
  });
}

exports.decorateNode = _decorateNode;
function isNode(obj) {
  return (typeof obj === 'undefined' ? 'undefined' : (0, _typeof3.default)(obj)) === 'object' && typeof obj.type === 'string' && obj.position;
}

function createBlock(contents) {
  var lang = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';

  return ["```" + lang, contents, "```"].join("\n");
}

/***/ },

/***/ 1:
/***/ function(module, exports) {

module.exports = require("babel-runtime/core-js/object/assign");

/***/ },

/***/ 122:
/***/ function(module, exports) {

module.exports = require("lodash/cloneDeep");

/***/ },

/***/ 144:
/***/ function(module, exports, __webpack_require__) {

module.exports = __webpack_require__("./src/markdown-ast-interface.js");


/***/ },

/***/ 15:
/***/ function(module, exports) {

module.exports = require("mdast-util-to-string");

/***/ },

/***/ 17:
/***/ function(module, exports) {

module.exports = require("mdast-util-heading-range");

/***/ },

/***/ 18:
/***/ function(module, exports) {

module.exports = require("skypager-util/lib/string");

/***/ },

/***/ 19:
/***/ function(module, exports) {

module.exports = require("unist-util-source");

/***/ },

/***/ 22:
/***/ function(module, exports) {

module.exports = require("babel-runtime/helpers/typeof");

/***/ },

/***/ 24:
/***/ function(module, exports) {

module.exports = require("unist-util-find-after");

/***/ },

/***/ 25:
/***/ function(module, exports) {

module.exports = require("unist-util-find-all-after");

/***/ },

/***/ 26:
/***/ function(module, exports) {

module.exports = require("unist-util-find-all-before");

/***/ },

/***/ 4:
/***/ function(module, exports) {

module.exports = require("babel-runtime/core-js/promise");

/***/ },

/***/ 5:
/***/ function(module, exports) {

module.exports = require("unist-util-select");

/***/ },

/***/ 6:
/***/ function(module, exports) {

module.exports = require("babel-runtime/helpers/toConsumableArray");

/***/ },

/***/ 7:
/***/ function(module, exports) {

module.exports = require("babel-runtime/core-js/object/keys");

/***/ }

/******/ });
//# sourceMappingURL=markdown-ast-interface.js.map