External Links
Opt-in rewriter that adds target and rel attributes to outbound links.
What it does
zfb ships an opt-in external-link rewriter, configured through the top-level markdown.externalLinks option. When enabled, every <a> whose href is classified as external receives the target and rel attributes you configure. It is a build-time port of rehype-external-links and runs inside zfb's markdown pipeline.
The rewriter is off by default. Neither zfb nor the zudo-doc preset enables it, so omitting the option leaves the rendered HTML byte-for-byte unchanged.
No automatic icon
Content-body external links receive no visual affordance today. zudo-doc's content-link component (content-link.tsx) applies only accent color and underline — it adds no external-link icon, and it does not set target or rel. The markdown.externalLinks rewriter described here adds attributes only; it does not inject an icon or any other marker.
What counts as external
An href is treated as external when:
It is an absolute
http:orhttps:URL.Its origin differs from the top-level
siteURL (whensiteis configured). Whensiteis absent, any absolutehttp:/https:URL is treated as external.
Non-HTTP(S) schemes (mailto:, tel:, …) are always left unchanged, and relative URLs (/, ., #anchor) are always internal.
Enabling it
The zudo-doc preset owns the markdown config, and zudoDoc() returns a complete zfb config. To opt in, spread that config and extend its markdown block with an externalLinks entry — spread base.markdown so the preset's existing markdown.features are preserved:
import { defineConfig } from "zfb/config";
import { zudoDoc } from "@takazudo/zudo-doc/config";
const base = zudoDoc({
// ...your project settings
});
export default defineConfig({
...base,
markdown: {
...base.markdown,
externalLinks: {
target: "_blank",
rel: ["noopener", "noreferrer"],
},
},
});Both fields are optional. target defaults to "_blank" and rel defaults to ["noopener", "noreferrer"], so externalLinks: {} opts in with those defaults. Supplied rel tokens are merged (case-insensitively deduplicated) with any rel already present on the link.
Example
With the rewriter enabled, a standard markdown link to an external site:
See the [zfb repository](https://github.com/takazudo/zfb) for source.renders as <a href=. The link text and its accent styling are unchanged — only the target and rel attributes are added.
Notes
The rewriter sets attributes only; it renders no icon. To show a visual external-link indicator once the rewriter is enabled, add your own CSS — for example a rule keyed on the
a[target="_blank"]attribute it adds.See Resolve Links for the companion feature that normalizes internal
.mdx/.mdlink targets.