introduce wrapText function
parent
ec488e910c
commit
74d932fd21
18
index.js
18
index.js
|
@ -22,6 +22,18 @@ const excludes = [
|
|||
"SUMMARY.md",
|
||||
];
|
||||
|
||||
/**
|
||||
* Wraps a string between other that acts as token.
|
||||
* @param {string} text - the text to wrap
|
||||
* @param {string} token - the text to wrap with between
|
||||
* @returns a string in the form `${token}${text}${token}`
|
||||
*/
|
||||
function wrapText(text, token = "") {
|
||||
// avoid mix concatenate/sum string/numbers using array join hack
|
||||
//return `${token}${text}${token}`;
|
||||
return [token, token].join(String(text));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the contents of a heading from remark-parse into a readable format.
|
||||
*
|
||||
|
@ -40,13 +52,13 @@ function getSectionNameFromHeadingContent(children) {
|
|||
// meaningfull nodes
|
||||
//
|
||||
case "emphasis":
|
||||
text += "_" + walk(node.children, depth + 1) + "_";
|
||||
text += wrapText(walk(node.children, depth + 1), "_");
|
||||
break;
|
||||
case "inlineCode":
|
||||
text += "`" + node.value + "`";
|
||||
text += wrapText(node.value, "`");
|
||||
break;
|
||||
case "strong":
|
||||
text += "**" + walk(node.children, depth + 1) + "**";
|
||||
text += wrapText(walk(node.children, depth + 1), "**");
|
||||
break;
|
||||
case "text":
|
||||
text += node.value;
|
||||
|
|
Loading…
Reference in New Issue