alto/commonmark-link-rewriter

CommonMark extension that rewrites link and image URLs via base URI, mapping, regex patterns, or callbacks.

Maintainers

Package info

github.com/altophp/commonmark-link-rewriter

Homepage

Issues

Documentation

pkg:composer/alto/commonmark-link-rewriter

Transparency log

Fund package maintenance!

smnandre

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

v1.0.0 2026-07-30 02:00 UTC

This package is auto-updated.

Last update: 2026-07-30 02:56:40 UTC


README

Summary

Indispensable plumbing for any hosted documentation setup. Rewrites link and image URLs after parsing so your markdown stays decoupled from your deployment URL. Rules are composable and applied in sequence: prepend a base URI, swap URLs by exact match, replace with a regex pattern, or run a custom callback. Chain as many as you need.

Installation

composer require

composer require alto/commonmark

Registration

use Alto\CommonMark\Extension\LinkRewriter\LinkRewriterExtension;
use League\CommonMark\Environment\Environment;

$environment = new Environment();
$environment->addExtension(new LinkRewriterExtension([
    'base_uri' => 'https://docs.example.com',
]));

Usage

No custom markdown directive is required; standard links/images are rewritten during document processing.

Configuration

  • base_uri: prepends a base URL to relative links.
  • map: exact URL mapping array.
  • pattern: regex replacement pair (pattern + replacement).
  • callback: custom callable for advanced rewriting.

Minimal Example

[Guide](/getting-started)
![Logo](/assets/logo.svg)

Development

This extension is actively developed in the alto/commonmark monorepo.

License

MIT License -- Simon André & Alto