From 993a41a386fce63007723ce937b9ccfa9f9da78d Mon Sep 17 00:00:00 2001 From: Foster Hangdaan Date: Tue, 5 Dec 2023 10:36:20 -0500 Subject: [PATCH] Minor refactor --- _config.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/_config.ts b/_config.ts index 58470be..8598eb6 100644 --- a/_config.ts +++ b/_config.ts @@ -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;