Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LinkRewriter Extension

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

About

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

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Releases

Contributors

Languages