---
title: "Link Markdown copies to Markdown copies · Agent Wranglers"
url: https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents/markdown-links-to-markdown
id: AGT-50
level: Recommended
updated: 2026-10-27
build: a2a6bdfed830
tokens: 775
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Link Markdown copies to Markdown copies

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Ready for AI agents](https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: AGT-50
- Level: Recommended
- Chapter: [Ready for AI agents](https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents.md)
- Rule: Every internal link in a Markdown copy points to the Markdown copy of its target.
- Check: A script reads every `.md` page. It fails on any link to your own host whose path does not end in `.md`, apart from images and feeds.
- How: An agent that follows a link from a Markdown page to an HTML page pays for the whole layout. Rewrite internal links when you build the Markdown, including breadcrumbs, chapter links and previous and next links. Leave links to other sites alone. The copies themselves follow [Offer every page as Markdown](https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents/markdown-source-endpoints.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### JavaScript example

```js
export const toMarkdownLinks = (markdown, host) =>
  markdown.replace(/\]\((https:\/\/[^)\s]+)\)/g, (link, url) => {
    const { hostname, pathname } = new URL(url);
    return hostname === host && !/\.\w+$/.test(pathname) ? `](${url.replace(/\/?$/, '')}.md)` : link;
  });
```

### Python example

```python
import re
from urllib.parse import urlsplit

def to_markdown_links(markdown: str, host: str) -> str:
    def rewrite(match: re.Match) -> str:
        url = match.group(1)
        parts = urlsplit(url)
        if parts.hostname == host and not re.search(r"\.\w+$", parts.path):
            return f"]({url.rstrip('/')}.md)"
        return match.group(0)
    return re.sub(r"\]\((https://[^)\s]+)\)", rewrite, markdown)
```

## Related rules

- AGT-49 [Offer every page as Markdown](https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents/markdown-source-endpoints.md) in Agents as users

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents/markdown-links-to-markdown">Agent Wranglers agents as users playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Offer every page as Markdown](https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents/markdown-source-endpoints.md)
- Next: [Showing agents a different page than people](https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents/same-content-for-agents.md)
- [Ready for AI agents](https://agentwranglers.se/playbook/agents-as-users/ready-for-ai-agents.md)
