markdown-meta-postprocess
(meta,
record
)Future versions of Lektor may change its Markdown parser away from 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.
lektor-markdown-header-anchors uses this to populate a meta var:
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
A list of some plugins that make use of this event is available here.
Comments