Access heading level in anchor-link.html (#1008)

* Add lvl variable in anchor-link context

* Add docs about lvl in anchor-link.html

* Rename lvl => level
This commit is contained in:
southerntofu 2020-04-29 17:40:25 +00:00 committed by GitHub
parent e9b47dae59
commit e3dc8bbab5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -329,6 +329,7 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render
};
let mut c = tera::Context::new();
c.insert("id", &id);
c.insert("level", &heading_ref.level);
let anchor_link = utils::templates::render_template(
&ANCHOR_LINK_TEMPLATE,

View file

@ -39,7 +39,12 @@ This option is set at the section level: the `insert_anchor_links` variable on t
The default template is very basic and will need CSS tweaks in your project to look decent.
If you want to change the anchor template, it can be easily overwritten by
creating an `anchor-link.html` file in the `templates` directory, which gets an `id` variable.
creating an `anchor-link.html` file in the `templates` directory.
The anchor link template has the following variables:
- `id`: the heading's id after applying the rules defined by `slugify.anchors`
- `level`: the heading level (between 1 and 6)
## Internal links
Linking to other pages and their headings is so common that Zola adds a