|
|
@ -52,13 +52,9 @@ var mkdown = md({
|
|
|
|
// Rendering rules
|
|
|
|
// Rendering rules
|
|
|
|
|
|
|
|
|
|
|
|
mkdown.renderer.rules.emoji = function(token, idx) {
|
|
|
|
mkdown.renderer.rules.emoji = function(token, idx) {
|
|
|
|
return '<i class="twa twa-' + token[idx].markup + '"></i>';
|
|
|
|
return '<i class="twa twa-' + token[idx].markup + '"></i>';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mkdown.inline.ruler.push('internal_link', (state) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Parse markdown content and build TOC tree
|
|
|
|
* Parse markdown content and build TOC tree
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -74,28 +70,28 @@ const parseTree = (content) => {
|
|
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < tokens.length; i++) {
|
|
|
|
for (let i = 0; i < tokens.length; i++) {
|
|
|
|
if (tokens[i].type !== "heading_close") {
|
|
|
|
if (tokens[i].type !== "heading_close") {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const heading = tokens[i - 1];
|
|
|
|
const heading = tokens[i - 1];
|
|
|
|
const heading_close = tokens[i];
|
|
|
|
const heading_close = tokens[i];
|
|
|
|
|
|
|
|
|
|
|
|
if (heading.type === "inline") {
|
|
|
|
if (heading.type === "inline") {
|
|
|
|
let content = "";
|
|
|
|
let content = "";
|
|
|
|
let anchor = "";
|
|
|
|
let anchor = "";
|
|
|
|
if (heading.children && heading.children[0].type === "link_open") {
|
|
|
|
if (heading.children && heading.children[0].type === "link_open") {
|
|
|
|
content = heading.children[1].content;
|
|
|
|
content = heading.children[1].content;
|
|
|
|
anchor = slug(content, {lower: true});
|
|
|
|
anchor = slug(content, {lower: true});
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
content = heading.content
|
|
|
|
content = heading.content
|
|
|
|
anchor = slug(heading.children.reduce((acc, t) => acc + t.content, ""), {lower: true});
|
|
|
|
anchor = slug(heading.children.reduce((acc, t) => acc + t.content, ""), {lower: true});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tocArray.push({
|
|
|
|
tocArray.push({
|
|
|
|
content,
|
|
|
|
content,
|
|
|
|
anchor,
|
|
|
|
anchor,
|
|
|
|
level: +heading_close.tag.substr(1, 1)
|
|
|
|
level: +heading_close.tag.substr(1, 1)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -159,10 +155,23 @@ const parseContent = (content) => {
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const parseMeta = (content) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let commentMeta = new RegExp('<!-- ?([a-zA-Z]+):(.*)-->','g');
|
|
|
|
|
|
|
|
let results = {}, match;
|
|
|
|
|
|
|
|
while(match = commentMeta.exec(content)) {
|
|
|
|
|
|
|
|
results[_.toLower(match[1])] = _.trim(match[2]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
|
|
|
|
parse(content) {
|
|
|
|
parse(content) {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
|
|
|
|
meta: parseMeta(content),
|
|
|
|
html: parseContent(content),
|
|
|
|
html: parseContent(content),
|
|
|
|
tree: parseTree(content)
|
|
|
|
tree: parseTree(content)
|
|
|
|
};
|
|
|
|
};
|
|
|
|