Add site processor
The new processor appends the `docstring` class to code docstrings so that they can be styled.
This commit is contained in:
parent
4a9de90590
commit
28839e99bf
1 changed files with 19 additions and 0 deletions
19
_config.ts
19
_config.ts
|
@ -59,4 +59,23 @@ site.use(toc({
|
||||||
}));
|
}));
|
||||||
site.use(footnotes());
|
site.use(footnotes());
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default site;
|
export default site;
|
||||||
|
|
Loading…
Reference in a new issue