Skip to main content

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 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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs_webcontext_plugin-0.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_webcontext_plugin-0.1.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_webcontext_plugin-0.1.1.tar.gz.

File metadata

File hashes

Hashes for mkdocs_webcontext_plugin-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5adc7aa916b212db878a8302c7bac64ae8fa131668c5aa715ade581f7dda37f7
MD5 68963458aa7ef1c39726dda50f751e69
BLAKE2b-256 b7a23dfce0089645386e6fe66252a1545fe81530af34e405982109c2449d97cd

See more details on using hashes here.

File details

Details for the file mkdocs_webcontext_plugin-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_webcontext_plugin-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee04a093c64a369ee867217d6528751b83be03646064bd6cdb6c88e0803f0da8
MD5 956bb625584e5e4bff98630f7e815b2a
BLAKE2b-256 eebe0d7358f10c093952ce7cbdb0e5bc0289fef09e6137b6a69e36a0fca7323e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page