front-matter-markdown
Version:
get the config and toc object from the markdown string.
56 lines (42 loc) • 1.57 kB
JavaScript
(function() {
var AstParser, extractType, getHeadingSection, getListSection, getToc, headings2FileObject, isArray, isFunction, isString, markdown, skipSpace;
isString = require('util-ex/lib/is/type/string');
isArray = require('util-ex/lib/is/type/array');
isFunction = require('util-ex/lib/is/type/function');
markdown = require('./');
getHeadingSection = require('./get-heading-section');
getListSection = require('./get-list-section');
skipSpace = require('./skip-space');
extractType = require('./extract-type');
AstParser = require('./ast-parser');
headings2FileObject = require('./ast-headings-to-file-object');
module.exports = getToc = function(aContent, aOptions) {
var firstLevel, links, maxDepth, result;
if (aOptions == null) {
aOptions = {};
}
firstLevel = aOptions.firstLevel || 1;
maxDepth = aOptions.maxDepth || 3;
if (isString(aContent)) {
aContent = markdown.lexer(aContent);
}
links = aContent.links;
result = extractType(aContent, 'heading', function(node) {
var reserved;
reserved = node.depth >= firstLevel && (node.depth - firstLevel) < maxDepth;
if (reserved && isFunction(aOptions.filter)) {
reserved = aOptions.filter(node.text);
}
return reserved;
});
if (result && result.length) {
if (links) {
result.links = links;
}
result = AstParser.parse(result);
result = headings2FileObject(result);
}
return result;
};
}).call(this);
//# sourceMappingURL=get-toc-from-heading.js.map