1 min read
pyssg.contrib.external_links
Contrib plugin: open external links in a new tab, safely.
Rewrites anchors pointing at an absolute http(s):// URL so they carry
target="_blank" and a rel that prevents the new tab from reaching back
into the opener (noopener noreferrer by default). Internal links (resolved
to site-relative URLs by the link_resolver plugin) are left untouched.
It taps finalize_content at stage 300 -- after wikilink (100) and internal
link resolution (200) -- so it only sees the final hrefs. The rewrite is a pure
function of the HTML, so builds stay byte-identical and incremental rebuilds
match full rebuilds.
rewrite_external_links(html: str, *, target: str, rel: str) -> str
Add target/rel to external http(s) anchors that lack them.
class ExternalLinksPlugin
Marks external links to open in a new, isolated tab.
ExternalLinksPlugin.__init__(self, *, target: str = '_blank', rel: str = 'noopener noreferrer') -> None
ExternalLinksPlugin.apply(self, builder: Builder) -> None
external_links(*, target: str = '_blank', rel: str = 'noopener noreferrer') -> ExternalLinksPlugin
Factory used in pyssg.config.py.