lego/packages/markdown-header-anchors
2019-09-02 18:31:26 +02:00
..
.gitignore Fix packages, add xml plugin, fix gitignore 2019-09-02 18:31:26 +02:00
CHANGES.md Fix packages, add xml plugin, fix gitignore 2019-09-02 18:31:26 +02:00
lektor_markdown_header_anchors.py Fix packages, add xml plugin, fix gitignore 2019-09-02 18:31:26 +02:00
LICENSE Fix packages, add xml plugin, fix gitignore 2019-09-02 18:31:26 +02:00
MANIFEST.in Fix packages, add xml plugin, fix gitignore 2019-09-02 18:31:26 +02:00
README.md Fix packages, add xml plugin, fix gitignore 2019-09-02 18:31:26 +02:00
setup.cfg Fix packages, add xml plugin, fix gitignore 2019-09-02 18:31:26 +02:00
setup.py Fix packages, add xml plugin, fix gitignore 2019-09-02 18:31:26 +02:00

lektor-markdown-header-anchors

This plugin extends the markdown support in Lektor in a way that headlines are given anchors and a table of contents is collected.

Enabling the Plugin

To enable the plugin run this command:

$ lektor plugins add markdown-header-anchors

In Templates

Within templates it becomes possible to access the .toc property of markdown data. It's a list where each item has the following attributes:

  • anchor: the name of the anchor
  • title: the title of the headline as HTML
  • children: a list of headers below that header

Example rendering:

<h4>Table Of Contents</h4>
<ul class="toc">
{% for item in this.body.toc recursive %}
  <li><a href="#{{ item.anchor }}">{{ item.title }}</a>{%
   if item.children %}<ul>{{ loop(item.children) }}</ul>{% endif %}</li>
{% endfor %}
</ul>