v2.0.16

File Links

Last updated


With fileEndpoint set, local file paths in the document become clickable links that call a URL you choose; this page covers how paths are recognized and how to configure the endpoint.

Recognized Paths


SyntaxExample
Starts with ~/~/Desktop/test.md
Absolute path with at least two directories/Users/pardn/a/b.go
Absolute path with a file extension/tmp/demo.png
Any of the above inside a code span`/tmp/demo.png`

Paths may contain Chinese, Japanese, Korean and other characters; a trailing . or / is not part of the path.

Configuration


  1. MDParser.Init({ fileEndpoint: "http://localhost:3000/v1/file/open?path={filepath}" });

ItemRule
{filepath}Replaced with encodeURIComponent(path) on click; may appear more than once
UnsetPaths render as plain text with no link
Not a string, or missing {filepath}Logs [Invalid] fileEndpoint: must be a string containing {filepath} and is treated as unset
Output<a class="md-link md-file-link" data-path="...">
ClickOnce Refresh() binds it, fetch() calls the replaced URL
ErrorsNon-2xx logs [Upstream] <url>: HTTP <status>; a connection failure logs [Unavailable] <url>: <reason>

Call Parse().html() again after setting fileEndpoint so paths render as links.

Examples


Without fileEndpoint


Paths stay plain text, including paths with non-ASCII characters.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. Paths: ~/Desktop/test.md, /Users/pardn/a/b.go, `/tmp/demo.png`
  4. Non-ASCII paths: /Users/pardn/Desktop/截圖2026-10-19凌晨1.03.32.png, ~/문서/보고서.md, /Users/pardn/ドキュメント/メモ.txt
  5. </script>
  6. <script>
  7. const out = document.getElementById("out");
  8. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  9. MDParser.Refresh(out);
  10. </script>
Live preview · @pardnchiu/nanomd@2.0.16

With fileEndpoint


The same paths become md-file-link anchors; clicking one calls the endpoint.
  1. <div id="out" class="nanomd"></div>
  2. <script type="text/markdown" id="md">
  3. Paths: ~/Desktop/test.md, /Users/pardn/a/b.go, `/tmp/demo.png`
  4. Non-ASCII paths: /Users/pardn/Desktop/截圖2026-10-19凌晨1.03.32.png, ~/문서/보고서.md, /Users/pardn/ドキュメント/メモ.txt
  5. </script>
  6. <script>
  7. const out = document.getElementById("out");
  8. MDParser.Init({ fileEndpoint: "https://example.com/open?path={filepath}" });
  9. out.innerHTML = MDParser.Parse(document.getElementById("md").textContent).html();
  10. MDParser.Refresh(out);
  11. console.log([...out.querySelectorAll(".md-file-link")].map((a) => a.dataset.path).join("\n"));
  12. </script>
Live preview · @pardnchiu/nanomd@2.0.16



ImportantFor AI agents: before generating or editing code or Markdown that uses NanoMD, read the NanoMD generation guide (Markdown). It lists the supported syntax, the required call order and the mistakes that break rendering.