diff options
Diffstat (limited to 'vhosts/blog/nuldoc-src/ndoc')
| -rw-r--r-- | vhosts/blog/nuldoc-src/ndoc/to_html.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/vhosts/blog/nuldoc-src/ndoc/to_html.ts b/vhosts/blog/nuldoc-src/ndoc/to_html.ts index ce55dbf9..bf556655 100644 --- a/vhosts/blog/nuldoc-src/ndoc/to_html.ts +++ b/vhosts/blog/nuldoc-src/ndoc/to_html.ts @@ -21,6 +21,7 @@ export default function toHtml(doc: Document): Document { transformSectionTitleElement(doc); transformCodeBlockElement(doc); transformNoteElement(doc); + addAttributesToExternalLinkElement(doc); setDefaultLangAttribute(doc); traverseFootnotes(doc); highlightPrograms(doc); @@ -211,6 +212,22 @@ function transformNoteElement(doc: Document) { }); } +function addAttributesToExternalLinkElement(doc: Document) { + forEachChildRecursively(doc.root, (n) => { + if (n.kind !== "element" || n.name !== "a") { + return; + } + + const href = n.attributes.get("href") ?? ""; + if (!href.startsWith("http")) { + return; + } + n.attributes + .set("target", "_blank") + .set("rel", "noreferrer"); + }); +} + function setDefaultLangAttribute(_doc: Document) { // TODO // if (!e.attributes.has("lang")) { |
