Skip to main content

Webcontext link converter plugin for MkDocs

MkDocs assumes absolute paths start from the root of the hosted website, like http://localhost/. For example, an absolute path like /assets/image1.jpg becomes http://localhost/assets/image1.jpg, which is correct if MkDocs is hosted at the root.

When the server root is not the same as the MkDocs root, this plugin lets you define a webcontext to prepend to these absolute paths. The webcontext path (e.g., /projectname/documents) replaces the default root (/).

Features

  • Converts absolute image paths in Markdown to be relative to a specified web context.
  • Converts image src attributes in HTML embedded in Markdown.
  • Converts url("/path") references inside CSS files.
  • Supports Markdown reference-style image and link syntax.
  • Debug and info logging of replacements.

Examples

Site URL Context Image Path Before Image Path After
http://example.com/ / /images/img1.jpg /images/img1.jpg
http://example.com/foo /foo /images/img1.jpg /foo/images/img1.jpg
http://example.com/foo/bar /foo/bar /images/img1.jpg /foo/bar/images/img1.jpg
http://127.0.0.1:8000 / /images/img1.jpg /images/img1.jpg
http://127.0.0.1:8000/foo /foo /images/img1.jpg /foo/images/img1.jpg

Quick Start

  1. Install the plugin:

    pip install mkdocs-webcontext-plugin
    

    Or using Poetry:

    poetry add mkdocs-webcontext-plugin
    
  2. Enable the plugin in your mkdocs.yml:

    plugins:
      - webcontext:
          context: foo/bar
    

Supported Link Types

The plugin modifies the following path formats:

  • Markdown links: [title](/path/image.png)

  • Markdown reference links:

    [logo]: /assets/logo.png
    
  • HTML image tags: <img src="/assets/img.png">

  • CSS url() paths: url("/assets/bg.jpg")

These paths will be rewritten to start with your defined context.

CSS Support

After your site is built, the plugin will scan all .css files in the output directory and rewrite any url("/...") references to use the defined context.

Logging

Rewrites are logged at the DEBUG level. Updated CSS files are logged at the INFO level.

Special Thanks

This plugin was inspired by and built with guidance from:

Metadata

Release files for mkdocs-webcontext-plugin 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mkdocs-webcontext-plugin 0.1.1
File Size Uploaded
mkdocs_webcontext_plugin-0.1.1.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkdocs-webcontext-plugin 0.1.1
File Interpreter ABI Platform
mkdocs_webcontext_plugin-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.7 kB

Release files / mkdocs_webcontext_plugin-0.1.1.tar.gz

Download URL mkdocs_webcontext_plugin-0.1.1.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5adc7aa916b212db878a8302c7bac64ae8fa131668c5aa715ade581f7dda37f7
BLAKE2b-256 checksum
How to use checksums
b7a23dfce0089645386e6fe66252a1545fe81530af34e405982109c2449d97cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / mkdocs_webcontext_plugin-0.1.1-py3-none-any.whl

Download URL mkdocs_webcontext_plugin-0.1.1-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ee04a093c64a369ee867217d6528751b83be03646064bd6cdb6c88e0803f0da8
BLAKE2b-256 checksum
How to use checksums
eebe0d7358f10c093952ce7cbdb0e5bc0289fef09e6137b6a69e36a0fca7323e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page