introduce wrapText function

pull/11/head
David Ordás 2022-09-17 12:08:38 +02:00
parent ec488e910c
commit 74d932fd21
No known key found for this signature in database
GPG Key ID: 6FD751229911593E
1 changed files with 15 additions and 3 deletions

View File

@ -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;