Mkdocs plugin to convert absolute paths to Webcontext aware paths.
Project description
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
srcattributes 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
-
Install the plugin:
pip install mkdocs-webcontext-plugin
Or using Poetry:
poetry add mkdocs-webcontext-plugin
-
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:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mkdocs_webcontext_plugin-0.1.1.tar.gz.
File metadata
- Download URL: mkdocs_webcontext_plugin-0.1.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5adc7aa916b212db878a8302c7bac64ae8fa131668c5aa715ade581f7dda37f7
|
|
| MD5 |
68963458aa7ef1c39726dda50f751e69
|
|
| BLAKE2b-256 |
b7a23dfce0089645386e6fe66252a1545fe81530af34e405982109c2449d97cd
|
File details
Details for the file mkdocs_webcontext_plugin-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mkdocs_webcontext_plugin-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee04a093c64a369ee867217d6528751b83be03646064bd6cdb6c88e0803f0da8
|
|
| MD5 |
956bb625584e5e4bff98630f7e815b2a
|
|
| BLAKE2b-256 |
eebe0d7358f10c093952ce7cbdb0e5bc0289fef09e6137b6a69e36a0fca7323e
|