Skip to main content

Automatically link across pages in MkDocs.

Project description

mkdocs-autorefs

ci pypi version gitter

Automatically link across pages in MkDocs.

Installation

With pip:

python3 -m pip install mkdocs-autorefs

Usage

# mkdocs.yml
plugins:
  - search
  - autorefs

In one of your Markdown files (e.g. doc1.md) create some headings:

## Hello, world!

## Another heading

Link to [Hello, World!](#hello-world) on the same page.

This is a normal link to an anchor. MkDocs generates anchors for each heading, and they can always be used to link to something, either within the same page (as shown here) or by specifying the path of the other page.

But with this plugin, you can link to a heading from any other page on the site without needing to know the path of either of the pages, just the heading title itself.
Let's create another Markdown page to try this, subdir/doc2.md:

We can [link to that heading][hello-world] from another page too.

This works the same as [a normal link to that heading](../doc1.md#hello-world).

Linking to a heading without needing to know the destination page can be useful if specifying that path is cumbersome, e.g. when the pages have deeply nested paths, are far apart, or are moved around frequently. And the issue is somewhat exacerbated by the fact that MkDocs supports only relative links between pages.

Note that this plugin's behavior is undefined when trying to link to a heading title that appears several times throughout the site. Currently it arbitrarily chooses one of the pages.

Requirements

mkdocs-autorefs requires Python 3.6 or above.

To install Python 3.6, I recommend using pyenv.
# install pyenv
git clone https://github.com/pyenv/pyenv ~/.pyenv

# setup pyenv (you should also put these three lines in .bashrc or similar)
export PATH="${HOME}/.pyenv/bin:${PATH}"
export PYENV_ROOT="${HOME}/.pyenv"
eval "$(pyenv init -)"

# install Python 3.6
pyenv install 3.6.12

# make it available globally
pyenv global system 3.6.12

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-autorefs-0.1.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

mkdocs_autorefs-0.1.1-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-autorefs-0.1.1.tar.gz.

File metadata

  • Download URL: mkdocs-autorefs-0.1.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.6.9 Linux/5.11.1-arch1-1

File hashes

Hashes for mkdocs-autorefs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ff9386ceb1ceeb88786696c7534ec31a6248a4828a5a2f8fea9d2699f650e3ab
MD5 ea5be1248257a64e4fdb0d7775a130c6
BLAKE2b-256 adec6dc0b2240049fb4131ea8f665162c416fff0c14c5b0eb7f890be241ba64a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mkdocs_autorefs-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.6.9 Linux/5.11.1-arch1-1

File hashes

Hashes for mkdocs_autorefs-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8bed8e81db45bb8d25e30e09d9d2943a7ceb92d3ad6b51e84618027c55c398eb
MD5 f3fa4dafefa2e3c2691710e0f5aaf336
BLAKE2b-256 8f7ef932afc2e2af212a37b8d63018417b5cda1998337554ce7e6b694096aa8f

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