-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
anchors_plugin callback #7
Comments
Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗 |
I don't know if this is the ideal way to do this, but my current solution is: class MyRenderer(RendererHTML):
def __init__(self, *args, **kwargs):
self.fm = None
self.pairs = []
super().__init__(*args, **kwargs)
def front_matter(self, tokens, idx, options, env):
token = tokens[idx]
front_matter = token.content.splitlines()
self.fm = front_matter
return self.renderToken(tokens, idx, options, env)
def heading_open(self, tokens, idx, options, env):
token = tokens[idx]
if token.attrs:
_id = token.attrs[0][1]
token = tokens[idx + 1]
title = token.content
self.pairs.append((title, _id))
return self.renderToken(tokens, idx, options, env)
md = (
MarkdownIt("default", renderer_cls=MyRenderer)...
md.renderer.pairs |
hey yeh thanks I'll try to have a look soon |
I want a list of the title, unique slug-id pairs for my generated anchors so I can create a navbar linking to the content. In MarkdownIt for JS a callback exists with this data:
"The callback option is a function that will be called at the end of rendering with the token and an info object. The info object has title and slug properties with the token content and the slug used for the identifier."
How can this be done with the current plugin?
I thought about a custom parsing function for heading_open token, but how to get inline after?
I considering passing a custom slug_func to anchors_plugin, but it doesn't have access to the slugs param so it can not retrieve the unique_slug id for the heading.
I tried parsing first, then rendering, but the plugin maintains state and so the unique_slug ids in the token stream don't match what is rendered.
The text was updated successfully, but these errors were encountered: