markdown-config
(config
)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 right after MarkdownConfig is instantiated, in which configuration can be set. This is done before the renderer is made.
lektor-markdown-header-anchors uses this to register a renderer mixin:
def on_markdown_config(self, config, **extra):
class HeaderAnchorMixin(object):
def header(renderer, text, level, raw):
if self.get_config().get('anchor-type') == "random":
anchor = uuid.uuid4().hex[:6]
else:
anchor = slugify(raw)
renderer.meta['toc'].append((level, anchor, Markup(text)))
return '<h%d id="%s">%s</h%d>' % (level, anchor, text, level)
config.renderer_mixins.append(HeaderAnchorMixin)
Comments