MarkdownLinkResolver Pennington.Markdown
Resolves author-written relative links inside markdown bodies to absolute canonical URLs. Handles three cases:
../how-to/foo.md— rewrites to the canonical URL of the target markdown file and strips the.mdsuffix.sample-post(no extension) — treated as a sibling markdown reference, resolved against the source file's directory and looked up by trying common extensions../image.pngor other non-markdown relative assets — resolved against the source file's directory and emitted as an absolute URL relative to the owning content source's base URL.
The index is built lazily from all registered IContentService instances. When managed by FileWatchDependencyFactory, the instance is recreated on file changes so the index stays fresh.
Constructors
.ctor
#public MarkdownLinkResolver(IEnumerable<IContentService> contentServices);Creates the resolver; the link index is built lazily on first resolution.
Parameters
contentServicesIEnumerable<IContentService>
Methods
ResolveAsync
#public async ValueTask<string?> ResolveAsync(FilePath sourceFile, string href);Resolve a markdown-author-written href against the source file that contains it. Returns the rewritten href, or null if the href is external / absolute / unresolvable and should be left untouched.
Parameters
sourceFileFilePathhrefstring
Returns
ValueTask<string?>Pennington.Markdown.MarkdownLinkResolver
namespace Pennington.Markdown;
/// Resolves author-written relative links inside markdown bodies to absolute canonical URLs. Handles three cases: ../how-to/foo.md — rewrites to the canonical URL of the target markdown file and strips the .md suffix.sample-post (no extension) — treated as a sibling markdown reference, resolved against the source file's directory and looked up by trying common extensions../image.png or other non-markdown relative assets — resolved against the source file's directory and emitted as an absolute URL relative to the owning content source's base URL.
The index is built lazily from all registered IContentService instances. When managed by FileWatchDependencyFactory, the instance is recreated on file changes so the index stays fresh.
public class MarkdownLinkResolver
{
/// Creates the resolver; the link index is built lazily on first resolution.
public MarkdownLinkResolver(IEnumerable<IContentService> contentServices);
/// Resolve a markdown-author-written href against the source file that contains it. Returns the rewritten href, or null if the href is external / absolute / unresolvable and should be left untouched.
public async ValueTask<string?> ResolveAsync(FilePath sourceFile, string href);
}