Minor refactor

This commit is contained in:
Foster Hangdaan 2023-12-05 10:36:20 -05:00
parent 81500eabad
commit 993a41a386
Signed by: foster
GPG key ID: E48D7F49A852F112

View file

@ -63,19 +63,13 @@ site.process([".html"], (page) => {
// NOTE: This is a hack to append a class to JS doctrings so that we
// can style them. If only the Hightlight.js plugin could be configured
// to do this instead.
const codeCommentElements = page.document?.getElementsByClassName("hljs-comment");
if (codeCommentElements && codeCommentElements.length > 0) {
page.document?.getElementsByClassName("hljs-comment").forEach((codeCommentElement) => {
const docStringRegex = /^\/\*\*.*\*\/$/gsm;
const codeDocStringElements = codeCommentElements.filter((el) => {
const matchResult = el.innerText.match(docStringRegex);
return !!matchResult;
});
if (codeDocStringElements.length > 0) {
codeDocStringElements.forEach((el) => {
el.classList.add("docstring");
})
const matchResult = codeCommentElement.innerText.match(docStringRegex);
if (matchResult) {
codeCommentElement.classList.add("docstring");
}
}
});
});
export default site;