URI rewriting

URI rewriting

Use UriExportStrategy with CustomUriExportStrategy and IUriSavingHandler to rewrite resource URIs in the Markdown output. This is useful when images are served from a CDN or a different path than where they’re saved.

Note
URI rewriting works with file-based image strategies (ExportImagesToFileSystemStrategy or CustomImagesStrategy). It has no effect when images are embedded as Base64.

Prepend a CDN base URL

using GroupDocs.Markdown;

public class CdnUriHandler : IUriSavingHandler
{
    public void Handle(UriSavingArgs args)
    {
        args.SetResourceFileUri("https://cdn.example.com/assets/" + args.ResourceFileName);
    }
}

var options = new ConvertOptions
{
    ImageExportStrategy = new ExportImagesToFileSystemStrategy("output/images")
    {
        ImagesRelativePath = "images"
    },
    UriExportStrategy = new CustomUriExportStrategy(new CdnUriHandler())
};

MarkdownConverter.ToFile("report.docx", "output/report.md", options);
// Images saved locally to output/images/
// Markdown references: ![](https://cdn.example.com/assets/img-001.png)

UriSavingArgs properties

PropertyDescription
ResourceFileNameDefault file name generated by the library
ResourceFileUriDefault URI that would appear in the Markdown
SetResourceFileUri(string)Override the URI written to the Markdown output