lektor-website/content/docs/api/plugins/events/markdown-meta-postprocess/contents.lr

40 lines
1.2 KiB
Plaintext
Raw Normal View History

title: markdown-meta-postprocess
---
body:
! Future versions of Lektor may change its Markdown parser away from [Mistune](https://github.com/lepture/mistune), and the various markdown related event hooks may be completely removed or work differently if that happens.
This event is emitted after the markdown has been rendered. This can be used to change the markdown object meta information after the fact.
## Example
[lektor-markdown-header-anchors :ext](https://github.com/lektor/lektor-markdown-header-anchors) uses this to populate a meta var:
```python
def on_markdown_meta_postprocess(self, meta, **extra):
prev_level = None
toc = []
stack = [toc]
for level, anchor, title in meta['toc']:
if prev_level is None:
prev_level = level
elif prev_level == level - 1:
stack.append(stack[-1][-1][2])
prev_level = level
elif prev_level > level:
while prev_level > level:
if len(stack) > 1:
stack.pop()
prev_level -= 1
stack[-1].append(TocEntry(anchor, title, []))
meta['toc'] = toc
```
---
signature: meta, record
---
summary: This event is emitted after the markdown meta information is set.
---
type: event