Links to headings with extra magic
SuperLinks for Foliant
This preprocessor extends the functionality of Markdown links, allowing you to reference by the heading title, file name or meta id. It works correctly with most backends, resolving to proper links, depending on which backend is being used.
It adds the
The problem with Markdown links is that you have to specify the correct anchor and file path right away.
Let's imagine that you want to create a link to a heading which is defined in another chapter.
If you are building a single-page PDF with Pandoc, you will only need to specify the anchor, which Pandoc generates from that title. But if you are building an MkDocs website, you will need to specify the relative filename to the referenced chapter, and the anchor, which MkDocs generates from the titles. By the way, Pandoc and MkDocs generate anchors differently. So there's no way to make it work for all backends by using just Markdown link syntax.
Superlinks aim to solve this problem.
Install the preprocessor:
$ pip install foliantcontrib.superlinks
To enable the preprocessor, add
preprocessors section in the project config.
preprocessors: - superlinks
Important: SuperLinks preprocessor is very sensitive to its position in the preprocessors list. If you are using it in along with Includes, Anchors or CustomIDs preprocessor, the order in which they are mentioned must be following:
preprocessors: - includes # indludes must be defined BEFORE superlinks in the list - ... - superlinks - ... # following preprocessors must be defined AFTER superlinks in the list - anchors - customids
The preprocessor has no config options just now. But it has some important tag options.
To add a link, use a
link tag with a combination of following parameters:
: Heading title, which you want to create a link to.
: Relative path to a chapter which is being referenced.
: ID of the meta section which is being referenced. (if
title is used, then this title MUST be inside this meta section)
: Just a hardcoded id. No magic here.
The body of the
link tag is your link caption. If the body is empty, SuperLinks will try to guess the right caption:
- referenced title for links by title,
- meta section title for links by meta section,
- heading title for links by CustomIDs,
- title from config or first heading title in the file for links to file,
- anchor name for links by anchors.
Reference a title in the same document
<link title="My title">Link caption</link>
Reference a title in another chapter
<link src="subfolder/another_chapter.md" title="Another title">Link caption</link>
Reference the beginning of another chapter
<link src="subfolder/another_chapter.md">Link caption</link>
Reference a title inside meta section
<link meta_id="SECTION1" title="Title in section1">Link caption</link>
Reference the beginning of meta section
<link meta_id="SECTION1">Link caption</link>
Reference an anchor and search for it globally
<link anchor="my_anchor">Link caption</link>
Reference an anchor and search for it in specific chapter
<link src="subfolder/another_chapter.md" anchor="my_anchor">Link caption</link>
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size foliantcontrib.superlinks-1.0.11-py3-none-any.whl (12.4 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size foliantcontrib.superlinks-1.0.11.tar.gz (12.1 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for foliantcontrib.superlinks-1.0.11-py3-none-any.whl
Hashes for foliantcontrib.superlinks-1.0.11.tar.gz