The default Obsidian link renderer will add the is-unresolved class to any broken links, but dc.Markdown will not handle this at all.
My workaround is to post-process it:
const Markdown = ({
content,
sourcePath,
}: {
content: string;
sourcePath?: string;
}) => {
const wrapperRef = dc.useRef<HTMLDivElement>(null);
const currentPath = dc.useCurrentPath();
const path = sourcePath || currentPath;
dc.useEffect(() => {
const root = wrapperRef.current;
if (!root) return;
// Wait until dc.Markdown has rendered and check if links are broken
queueMicrotask(() => {
root.querySelectorAll("a.internal-link").forEach((link) => {
const linkpath =
link.getAttribute("data-href") ?? link.getAttribute("href");
if (!linkpath) return;
const resolved = dc.app.metadataCache.getFirstLinkpathDest(
linkpath,
path,
);
link.classList.toggle("is-unresolved", !resolved);
});
});
}, [dc.app, content, path]);
return (
<div ref={wrapperRef}>
<dc.Markdown content={content} sourcePath={path} />
</div>
);
};
It would be nice if this was incorporated into the original component's effect
The default Obsidian link renderer will add the
is-unresolvedclass to any broken links, butdc.Markdownwill not handle this at all.My workaround is to post-process it:
It would be nice if this was incorporated into the original component's effect