mkdocs-alias-plugin


Namemkdocs-alias-plugin JSON
Version 0.8.0 PyPI version JSON
download
home_pagehttps://github.com/eddyluten/mkdocs-alias-plugin
SummaryAn MkDocs plugin allowing links to your pages using a custom alias
upload_time2024-04-06 22:50:43
maintainerNone
docs_urlNone
authorEddy Luten
requires_python>=3.0
licenseMIT
keywords mkdocs python markdown alias link wiki
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # mkdocs-alias-plugin

[![PyPI version](https://badge.fury.io/py/mkdocs-alias-plugin.svg)](https://pypi.org/project/mkdocs-alias-plugin/)  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![example workflow](https://github.com/eddyluten/mkdocs-alias-plugin/actions/workflows/pylint.yml/badge.svg) [![Downloads](https://pepy.tech/badge/mkdocs-alias-plugin)](https://pepy.tech/project/mkdocs-alias-plugin) ![](https://github.com/eddyluten/mkdocs-alias-plugin/workflows/mkdocs-alias-plugin%20Tests/badge.svg)

The `mkdocs-alias-plugin` MkDocs plugin allows links to your pages using a custom alias such as `[[my-alias]]` or `[[my-alias|My Title]]`.

The aliases are configured through the meta-sections of each page (see Usage below).

If you like this plugin, you'll probably also like [mkdocs-categories-plugin](https://github.com/EddyLuten/mkdocs-categories-plugin) and [mkdocs-live-edit-plugin](https://github.com/EddyLuten/mkdocs-live-edit-plugin).

## Rationale

I maintain a fairly large wiki and occasionally will restructure parts of it, resulting in many broken links. This plugin allows me to separate the wiki contents from the file system structure and resolves the paths during build time. Maybe this plugin will help you out as well.

## Installation

Install the package using pip:

```zsh
pip install mkdocs-alias-plugin
```

Then add the following entry to the plugins section of your `mkdocs.yml` file:

```yml
plugins:
  - alias
```

For further configuration, see the Options section below.

## Usage

Add an `alias` section to your page's meta block:

```yaml
---
alias: wuthering-heights
---
```

Then, using the alias in the markdown content of your pages:

```md
The song references [[wuthering-heights]].
```

Which, after the page builds, renders as a regular link to your page.

A more advanced example would be to use the dictionary-style configuration instead of providing a different link title:

```yaml
---
alias:
    name: wuthering-heights
    text: Wuthering Heights, a novel by Emily Brontë
---
```

If you'd like to supply a custom link text instead on a link-by-link basis, you can do so using a pipe to separate the title from the alias:

```md
The song references [[wuthering-heights|Wuthering Heights]].
```

As of version 0.6.0, you can also use link anchors in your aliases:

```md
The song references [[wuthering-heights#references]].
```

Or, using a custom title:

```md
The song references [[wuthering-heights#references|Wuthering Heights]].
```

As of version 0.8.0, you can enable the plugin option `use_anchor_titles` to replace anchor links with the text of the page heading that defined it. This behavior is opt-in to preserve backward compatibility.

Please refer to the [MkDocs documentation](https://www.mkdocs.org/user-guide/writing-your-docs/#yaml-style-meta-data) for more information on how the meta-data block is used.

### Multiple Aliases

As of version 0.3.0, assigning multiple aliases to a single page is possible. This feature does come with the limitation that these aliases cannot define a per-alias title and instead will use the page title. The syntax for this is:

```yaml
---
alias:
    - wuthering-heights
    - wuthering
    - wh
---
```

### Escaping Aliases (Escape Syntax)

As of version 0.4.0, it is possible to escape aliases to prevent them being parsed by the plugin. This is useful if you use a similar double-bracket markup for a different purpose (e.g. shell scripts in code blocks). The syntax for this feature is a leading backslash:

```md
\[[this text will remain untouched]]

[[this text will be parsed as an alias]]
```

## Options

You may customize the plugin by passing options into the plugin's configuration sections in `mkdocs.yml`:

```yaml
plugins:
    - alias:
        verbose: true
        use_anchor_titles: true
```

### `verbose`

You may use the optional `verbose` option to print more information about which aliases were used and defined during the build process. The default value is `false`.

### `use_anchor_titles`

Setting this flag to true causes the plugin to replace an alias containing an anchor (`[[my-page#sub-heading]]`) with the text of the header that defined it. You can still override the title of the link as usual.

## Troubleshooting

### The link text looks like a path or URL

Your alias doesn't have link text defined *and* your page doesn't have a title H1 tag or a `title` attribute in its meta data section. Once you add this, your link will render with the appropriate text.

### My alias is not replaced

`WARNING  -  Alias 'my-alias' not found`

The alias could not be found in the defined aliases, usually due to a typo. Enable verbose output in the plugin's configuration to display all of the found aliases.

However, it is also possible that the plugin is trying to interpret another double-bracketed syntax as an alias. In this case, use the escape syntax to prevent the plugin from parsing it.

### "Alias already defined"

You're getting a message resembling this in your output:

`WARNING  -  page-url: alias alias-name already defined in other-url, skipping.`

Aliases *must* be unique. Ensure that you're not redefining the same alias for a different page. Rename one of them and the warning should go away.

## Local Development

Installing a local copy of the plugin:

```zsh
pip install -e /path/to/mkdocs-alias-plugin/
```

Running unit tests after installing pytest from the root directory:

```zsh
pytest -vv
```

Both unit test and linting:

```zsh
pylint $(git ls-files '*.py') && pytest -vv
```

## Changelog

## 0.8.0

This release adds functionality to replace the titles of aliases containing anchors with the text of the heading that defines them. Enable this feature by setting the plugin option `use_anchor_titles` to true. Feature request: [#8](https://github.com/EddyLuten/mkdocs-alias-plugin/issues/8).

### 0.7.1

**Bug Fix:** fixes a bug where any alias with the word "text" would break the plugin due to faulty logic. Bug report: [#7](https://github.com/EddyLuten/mkdocs-alias-plugin/issues/7).

### 0.7.0

2024-02-01

This release removes support for the `use_relative_link` option introduced in issue [#3](https://github.com/EddyLuten/mkdocs-alias-plugin/issues/3). As of version 1.5.0, MkDocs prefers relative links to absolute links, which was this package's default before. As of this version, all alias links generated are relative to the file from where they were linked.

### 0.6.0

2023-04-17

Adds support for page anchor links from within an alias. E.g.:

```md
[[my alias#my anchor]]
````

### 0.5.0

2023-02-08

Adds the ability to use the `use_relative_link` config flag, which causes the plugin to generate relative links to the aliased document rather than absolute ones. This flag is useful for those who host their wikis in subdirectories.

@SimonDelmas contributed this feature in PR #3. Thanks!

### 0.4.0

2022-07-10

Adds the ability to escape aliases so they won't be parsed by the plugin. Also adds more unit tests.

### 0.3.0

2022-04-27

Adds the ability to create multiple aliases for a single page (see the documentation for "Multiple Aliases" above). Improves the "alias not found" warning by listing the file attempting to use the alias.

### 0.2.0

2022-02-23

Allow strings as aliases instead of dictionaries, which allows for the use of page titles in the link text of the alias.

This version also makes the `text` key optional in the alias dictionary configuration, using the same page title link text instead if it's not provided.

### 0.1.1

2022-02-12

Fixes a bunch of linter issues, but no new logic.

### 0.1.0

2022-02-12

Initial release with all of the base logic in place.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/eddyluten/mkdocs-alias-plugin",
    "name": "mkdocs-alias-plugin",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.0",
    "maintainer_email": null,
    "keywords": "mkdocs python markdown alias link wiki",
    "author": "Eddy Luten",
    "author_email": "eddyluten@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/62/a5/2f281f1b6ea2864350a9432c1a823231c65608b3c60b991ebe535684641d/mkdocs-alias-plugin-0.8.0.tar.gz",
    "platform": null,
    "description": "# mkdocs-alias-plugin\n\n[![PyPI version](https://badge.fury.io/py/mkdocs-alias-plugin.svg)](https://pypi.org/project/mkdocs-alias-plugin/)  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![example workflow](https://github.com/eddyluten/mkdocs-alias-plugin/actions/workflows/pylint.yml/badge.svg) [![Downloads](https://pepy.tech/badge/mkdocs-alias-plugin)](https://pepy.tech/project/mkdocs-alias-plugin) ![](https://github.com/eddyluten/mkdocs-alias-plugin/workflows/mkdocs-alias-plugin%20Tests/badge.svg)\n\nThe `mkdocs-alias-plugin` MkDocs plugin allows links to your pages using a custom alias such as `[[my-alias]]` or `[[my-alias|My Title]]`.\n\nThe aliases are configured through the meta-sections of each page (see Usage below).\n\nIf you like this plugin, you'll probably also like [mkdocs-categories-plugin](https://github.com/EddyLuten/mkdocs-categories-plugin) and [mkdocs-live-edit-plugin](https://github.com/EddyLuten/mkdocs-live-edit-plugin).\n\n## Rationale\n\nI maintain a fairly large wiki and occasionally will restructure parts of it, resulting in many broken links. This plugin allows me to separate the wiki contents from the file system structure and resolves the paths during build time. Maybe this plugin will help you out as well.\n\n## Installation\n\nInstall the package using pip:\n\n```zsh\npip install mkdocs-alias-plugin\n```\n\nThen add the following entry to the plugins section of your `mkdocs.yml` file:\n\n```yml\nplugins:\n  - alias\n```\n\nFor further configuration, see the Options section below.\n\n## Usage\n\nAdd an `alias` section to your page's meta block:\n\n```yaml\n---\nalias: wuthering-heights\n---\n```\n\nThen, using the alias in the markdown content of your pages:\n\n```md\nThe song references [[wuthering-heights]].\n```\n\nWhich, after the page builds, renders as a regular link to your page.\n\nA more advanced example would be to use the dictionary-style configuration instead of providing a different link title:\n\n```yaml\n---\nalias:\n    name: wuthering-heights\n    text: Wuthering Heights, a novel by Emily Bront\u00eb\n---\n```\n\nIf you'd like to supply a custom link text instead on a link-by-link basis, you can do so using a pipe to separate the title from the alias:\n\n```md\nThe song references [[wuthering-heights|Wuthering Heights]].\n```\n\nAs of version 0.6.0, you can also use link anchors in your aliases:\n\n```md\nThe song references [[wuthering-heights#references]].\n```\n\nOr, using a custom title:\n\n```md\nThe song references [[wuthering-heights#references|Wuthering Heights]].\n```\n\nAs of version 0.8.0, you can enable the plugin option `use_anchor_titles` to replace anchor links with the text of the page heading that defined it. This behavior is opt-in to preserve backward compatibility.\n\nPlease refer to the [MkDocs documentation](https://www.mkdocs.org/user-guide/writing-your-docs/#yaml-style-meta-data) for more information on how the meta-data block is used.\n\n### Multiple Aliases\n\nAs of version 0.3.0, assigning multiple aliases to a single page is possible. This feature does come with the limitation that these aliases cannot define a per-alias title and instead will use the page title. The syntax for this is:\n\n```yaml\n---\nalias:\n    - wuthering-heights\n    - wuthering\n    - wh\n---\n```\n\n### Escaping Aliases (Escape Syntax)\n\nAs of version 0.4.0, it is possible to escape aliases to prevent them being parsed by the plugin. This is useful if you use a similar double-bracket markup for a different purpose (e.g. shell scripts in code blocks). The syntax for this feature is a leading backslash:\n\n```md\n\\[[this text will remain untouched]]\n\n[[this text will be parsed as an alias]]\n```\n\n## Options\n\nYou may customize the plugin by passing options into the plugin's configuration sections in `mkdocs.yml`:\n\n```yaml\nplugins:\n    - alias:\n        verbose: true\n        use_anchor_titles: true\n```\n\n### `verbose`\n\nYou may use the optional `verbose` option to print more information about which aliases were used and defined during the build process. The default value is `false`.\n\n### `use_anchor_titles`\n\nSetting this flag to true causes the plugin to replace an alias containing an anchor (`[[my-page#sub-heading]]`) with the text of the header that defined it. You can still override the title of the link as usual.\n\n## Troubleshooting\n\n### The link text looks like a path or URL\n\nYour alias doesn't have link text defined *and* your page doesn't have a title H1 tag or a `title` attribute in its meta data section. Once you add this, your link will render with the appropriate text.\n\n### My alias is not replaced\n\n`WARNING  -  Alias 'my-alias' not found`\n\nThe alias could not be found in the defined aliases, usually due to a typo. Enable verbose output in the plugin's configuration to display all of the found aliases.\n\nHowever, it is also possible that the plugin is trying to interpret another double-bracketed syntax as an alias. In this case, use the escape syntax to prevent the plugin from parsing it.\n\n### \"Alias already defined\"\n\nYou're getting a message resembling this in your output:\n\n`WARNING  -  page-url: alias alias-name already defined in other-url, skipping.`\n\nAliases *must* be unique. Ensure that you're not redefining the same alias for a different page. Rename one of them and the warning should go away.\n\n## Local Development\n\nInstalling a local copy of the plugin:\n\n```zsh\npip install -e /path/to/mkdocs-alias-plugin/\n```\n\nRunning unit tests after installing pytest from the root directory:\n\n```zsh\npytest -vv\n```\n\nBoth unit test and linting:\n\n```zsh\npylint $(git ls-files '*.py') && pytest -vv\n```\n\n## Changelog\n\n## 0.8.0\n\nThis release adds functionality to replace the titles of aliases containing anchors with the text of the heading that defines them. Enable this feature by setting the plugin option `use_anchor_titles` to true. Feature request: [#8](https://github.com/EddyLuten/mkdocs-alias-plugin/issues/8).\n\n### 0.7.1\n\n**Bug Fix:** fixes a bug where any alias with the word \"text\" would break the plugin due to faulty logic. Bug report: [#7](https://github.com/EddyLuten/mkdocs-alias-plugin/issues/7).\n\n### 0.7.0\n\n2024-02-01\n\nThis release removes support for the `use_relative_link` option introduced in issue [#3](https://github.com/EddyLuten/mkdocs-alias-plugin/issues/3). As of version 1.5.0, MkDocs prefers relative links to absolute links, which was this package's default before. As of this version, all alias links generated are relative to the file from where they were linked.\n\n### 0.6.0\n\n2023-04-17\n\nAdds support for page anchor links from within an alias. E.g.:\n\n```md\n[[my alias#my anchor]]\n````\n\n### 0.5.0\n\n2023-02-08\n\nAdds the ability to use the `use_relative_link` config flag, which causes the plugin to generate relative links to the aliased document rather than absolute ones. This flag is useful for those who host their wikis in subdirectories.\n\n@SimonDelmas contributed this feature in PR #3. Thanks!\n\n### 0.4.0\n\n2022-07-10\n\nAdds the ability to escape aliases so they won't be parsed by the plugin. Also adds more unit tests.\n\n### 0.3.0\n\n2022-04-27\n\nAdds the ability to create multiple aliases for a single page (see the documentation for \"Multiple Aliases\" above). Improves the \"alias not found\" warning by listing the file attempting to use the alias.\n\n### 0.2.0\n\n2022-02-23\n\nAllow strings as aliases instead of dictionaries, which allows for the use of page titles in the link text of the alias.\n\nThis version also makes the `text` key optional in the alias dictionary configuration, using the same page title link text instead if it's not provided.\n\n### 0.1.1\n\n2022-02-12\n\nFixes a bunch of linter issues, but no new logic.\n\n### 0.1.0\n\n2022-02-12\n\nInitial release with all of the base logic in place.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An MkDocs plugin allowing links to your pages using a custom alias",
    "version": "0.8.0",
    "project_urls": {
        "Homepage": "https://github.com/eddyluten/mkdocs-alias-plugin"
    },
    "split_keywords": [
        "mkdocs",
        "python",
        "markdown",
        "alias",
        "link",
        "wiki"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eb8e123f3b32b2ede41b2af9af34ed38f840a9d5818b938d35486a3e19d3a3aa",
                "md5": "aa1045f9dde7740c8353ba062675f7f1",
                "sha256": "c66b3181c5bb751da7891519d1c37b15cd0700abb7e56e7bc679ba9a6f3de77f"
            },
            "downloads": -1,
            "filename": "mkdocs_alias_plugin-0.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "aa1045f9dde7740c8353ba062675f7f1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.0",
            "size": 8418,
            "upload_time": "2024-04-06T22:50:41",
            "upload_time_iso_8601": "2024-04-06T22:50:41.663152Z",
            "url": "https://files.pythonhosted.org/packages/eb/8e/123f3b32b2ede41b2af9af34ed38f840a9d5818b938d35486a3e19d3a3aa/mkdocs_alias_plugin-0.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "62a52f281f1b6ea2864350a9432c1a823231c65608b3c60b991ebe535684641d",
                "md5": "aa78397103dd54a6ebffa859f3ec2af1",
                "sha256": "26c7128fe94cf8f1e2ee49842ed142094a5fbc94c03278034513d67c2a53485a"
            },
            "downloads": -1,
            "filename": "mkdocs-alias-plugin-0.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "aa78397103dd54a6ebffa859f3ec2af1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.0",
            "size": 8228,
            "upload_time": "2024-04-06T22:50:43",
            "upload_time_iso_8601": "2024-04-06T22:50:43.324138Z",
            "url": "https://files.pythonhosted.org/packages/62/a5/2f281f1b6ea2864350a9432c1a823231c65608b3c60b991ebe535684641d/mkdocs-alias-plugin-0.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-06 22:50:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "eddyluten",
    "github_project": "mkdocs-alias-plugin",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mkdocs-alias-plugin"
}
        
Elapsed time: 0.29574s