Skip to main content

Arbitrary anchors for Foliant.

Project description


Preprocessor which allows to use arbitrary anchors in Foliant documents.


$ pip install foliantcontrib.anchors


To enable the preprocessor, add anchors to preprocessors section in the project config:

    - anchors

The preprocessor has some options, but most probably you won't need any of them:

    - anchors:
        element: '<span id="{anchor}"></span>'
        tex: False

element : Template of an HTML-element which will be placed instead of the <anchor> tag. In this template {anchor} will be replaced with the tag contents. Default: '<span id="{anchor}"></span>'

tex : If this option is True, preprocessor will try to use TeX-language anchors: \hypertarget{anchor}{}. Default: False

Notice, this option will work only with pdf target. For all other targets it is set to False.


Just add an anchor tag to some place and then use an ordinary Markdown-link to this anchor:


Some important notice about system limitation.


Don't forget about [limitation](#limitation)!

You can also place anchors in the middle of paragraph:

Lorem ipsum dolor sit amet, consectetur adipisicing elit.<anchor>middle</anchor> Molestiae illum iusto, sequi magnam consequatur porro iste facere at fugiat est corrupti dolorum quidem sapiente pariatur rem, alias unde! Iste, aliquam.

[Go to the middle of the paragraph](#middle)

You can place anchors inside tables:

Name | Age | Weight
---- | --- | ------
Max  | 17  | 60
Jane | 98  | 12
John | 10  | 40
Katy | 54  | 54
Mike <anchor>Mike</anchor>| 22  | 299
Cinty| 25  | 42


Something's wrong with Mike, [look](#Mike)!

Additional info

1. Anchors are case sensitive

Markdown and MarkDown are two different anchors.

2. Anchors should be unique

You can't use two anchors with the same name in one document.

If preprocessor notices repeating anchors in one md-file it will throw you a warning.

If there are repeating anchors in different md-files and they all go into single pdf or docx, all links will lead to the first one.

3. Anchors may conflict with headers

Headers are usually assigned anchors of their own. Be careful, your anchors may conflict with them.

Preprocessor will try to detect if you are using anchor which is already taken by the header and warn you in console.

Remember, that header anchors are almost always in lower-case and almost never use special symbols except -.

4. Some symbols are restricted

You can't use these symbols in anchors:


Also you can't use space.

5. But a lot of other symbols are available

All these are valid anchors:


Notice for Mkdocs

In many Mkdocs themes the top menu lays over the text with absolute position. In this situation all anchors will be hidden by the menu.

Possible solution is to use element option. Example config:

    - anchors:
        element: '<span style="display:block; margin:-3.1rem; padding:3.1rem;" id="{anchor}"></span>'

Project details

Download files

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

Files for foliantcontrib.anchors, version 1.0.4
Filename, size File type Python version Upload date Hashes
Filename, size foliantcontrib.anchors-1.0.4-py3-none-any.whl (5.5 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size foliantcontrib.anchors-1.0.4.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page