# URI rewriting Customize resource URIs in the Markdown output -- CDN URLs, custom paths Use `uri_export_strategy` with `CustomUriExportStrategy` and a Python callable 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. {{< alert style="info" >}} URI rewriting works with file-based image strategies (`ExportImagesToFileSystemStrategy` or `CustomImagesStrategy`). It has no effect when images are embedded as Base64. {{< /alert >}} ### Prepend a CDN base URL {{< tabs "uri-rewriting-cdn">}} {{< tab "uri_rewriting_cdn.py" >}} ```python from groupdocs.markdown import ( MarkdownConverter, ConvertOptions, ExportImagesToFileSystemStrategy, CustomUriExportStrategy ) def uri_rewriting_cdn(): """Rewrite image URIs to point to a CDN base URL in the Markdown output.""" # Step 1: Define the CDN base URL CDN_BASE = "https://cdn.example.com/assets/" # Step 2: Create a handler that prepends the CDN URL to each resource def cdn_handler(call_info): """Called for each resource URI during conversion. Receives context with ResourceFileName, ResourceFileUri. Returns dict with resource_file_uri to override the URI.""" ctx = call_info["context"] original = ctx["ResourceFileName"] return {"resource_file_uri": CDN_BASE + original} # Step 3: Configure image and URI export strategies options = ConvertOptions() options.image_export_strategy = ExportImagesToFileSystemStrategy("./output/images") options.uri_export_strategy = CustomUriExportStrategy(cdn_handler) # Step 4: Convert and save using keyword argument for options MarkdownConverter.to_file("business-plan.docx", "output/report.md", convert_options=options) # Images saved locally to output/images/ # Markdown references: ![](https://cdn.example.com/assets/img-001.png) if __name__ == "__main__": import os os.makedirs("output/images", exist_ok=True) uri_rewriting_cdn() ``` {{< /tab >}} {{< tab "business-plan.docx" >}} {{< tab-text >}} `business-plan.docx` is sample file used in this example. Click [here](https://docs.groupdocs.com/markdown/python-net/_sample_files/developer-guide/advanced-usage/business-plan.docx) to download it. {{< /tab-text >}} {{< /tab >}} {{< tab "uri-rewriting-cdn.zip" >}} ```text output/images/img-001.png (4 KB) output/images/img-002.jpg (41 KB) output/images/img-003.png (14 KB) output/report.md (5 KB) ``` [Download full output](https://docs.groupdocs.com/markdown/python-net/_output_files/developer-guide/advanced-usage/uri-rewriting/uri_rewriting_cdn/uri-rewriting-cdn.zip) {{< /tab >}} {{< /tabs >}} ### UriSavingArgs properties | Property | Description | |---|---| | `ResourceFileName` | Default file name generated by the library | | `ResourceFileUri` | Default URI that would appear in the Markdown | | `resource_file_uri` | Override the URI written to the Markdown output (return value) |