|
|
@ -111,10 +111,10 @@ const parseTree = (content) => {
|
|
|
|
let content = ''
|
|
|
|
let content = ''
|
|
|
|
let anchor = ''
|
|
|
|
let anchor = ''
|
|
|
|
if (heading.children && heading.children.length > 0 && heading.children[0].type === 'link_open') {
|
|
|
|
if (heading.children && heading.children.length > 0 && heading.children[0].type === 'link_open') {
|
|
|
|
content = heading.children[1].content
|
|
|
|
content = removeMarkdown(heading.children[1].content)
|
|
|
|
anchor = _.kebabCase(content)
|
|
|
|
anchor = _.kebabCase(content)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
content = heading.content
|
|
|
|
content = removeMarkdown(heading.content)
|
|
|
|
anchor = _.kebabCase(heading.children.reduce((acc, t) => acc + t.content, ''))
|
|
|
|
anchor = _.kebabCase(heading.children.reduce((acc, t) => acc + t.content, ''))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -282,33 +282,13 @@ const parseMeta = (content) => {
|
|
|
|
return results
|
|
|
|
return results
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
/**
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Parse content and return all data
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param {String} content Markdown-formatted content
|
|
|
|
|
|
|
|
* @return {Object} Object containing meta, html and tree data
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
parse (content) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
meta: parseMeta(content),
|
|
|
|
|
|
|
|
html: parseContent(content),
|
|
|
|
|
|
|
|
tree: parseTree(content)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parseContent,
|
|
|
|
|
|
|
|
parseMeta,
|
|
|
|
|
|
|
|
parseTree,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Strips non-text elements from Markdown content
|
|
|
|
* Strips non-text elements from Markdown content
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param {String} content Markdown-formatted content
|
|
|
|
* @param {String} content Markdown-formatted content
|
|
|
|
* @return {String} Text-only version
|
|
|
|
* @return {String} Text-only version
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
removeMarkdown (content) {
|
|
|
|
const removeMarkdown = (content) => {
|
|
|
|
return mdRemove(_.chain(content)
|
|
|
|
return mdRemove(_.chain(content)
|
|
|
|
.replace(/<!-- ?([a-zA-Z]+):(.*)-->/g, '')
|
|
|
|
.replace(/<!-- ?([a-zA-Z]+):(.*)-->/g, '')
|
|
|
|
.replace(/```[^`]+```/g, '')
|
|
|
|
.replace(/```[^`]+```/g, '')
|
|
|
@ -323,6 +303,28 @@ module.exports = {
|
|
|
|
.replace(/\s\s+/g, ' ')
|
|
|
|
.replace(/\s\s+/g, ' ')
|
|
|
|
.value()
|
|
|
|
.value()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Parse content and return all data
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param {String} content Markdown-formatted content
|
|
|
|
|
|
|
|
* @return {Object} Object containing meta, html and tree data
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
parse (content) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
meta: parseMeta(content),
|
|
|
|
|
|
|
|
html: parseContent(content),
|
|
|
|
|
|
|
|
tree: parseTree(content)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parseContent,
|
|
|
|
|
|
|
|
parseMeta,
|
|
|
|
|
|
|
|
parseTree,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
removeMarkdown
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|