-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
What is the "right" way to add links around an inline token? #834
Comments
Injecting PS. It would be more easy to understand, if you could provide minimal "real world example" of input text and ouput text. Probably i missed something. |
Ah, sorry, forgot that! The input markdown text would look like:
And I'm trying to capture the
Right now my function is called as follows: But when you say "I would place it on the end of core chain", I'm not sure what the best way to do that is? Would this make sense as the new way to call the rule function?
|
Just use https://github.com/markdown-it/markdown-it/blob/master/lib/ruler.js#L233 |
Ah, I hadn't seen that function. Thanks @puzrin ! This was very useful! I'm made the change and it looks like it is working: AramZS/devblog@af17fab |
So I've checked the docs and a number of plugins and seen a variety of way different folks add links to content. I'm not sure which is the best way or why. I have a plugin that processes inline commit messages I write into my blog posts, searches the GitHub API and gets back links to the actual commits. Most of that is pretty irrelevant to my question, but you can see the whole plugin here.
The relevant part is that I am looking for
inline
type tokens, finding ones with content matching my pattern, assuming that (because this is my writing pattern) it always hascode_inline
type children and adding a link around thecode_inline
token as follows:All this works fine, but I'm also trying to be as correct in my use of Markdown-It as possible so I have a question that doesn't seem to have a clear answer:
When creating the link should I be using
html_inline
orlink_open
andlink_close
?For now, I'm using
html_inline
as follows:But I could also use
link_open
and then I would have access to theattrPush
on the token and could use thesetAttr
functions commented out above, which looks like this:But I'm not sure that's the right way to go? I don't seem to have any ability to tell which token types are already available at the point I initiate my plugin
md.core.ruler.after("inline"
or if a type likelink_open
is reserved for special behavior that might make it harder for my plugin to work properly?This isn't some super urgent question, so please feel free to take your time to respond, but I would really like to know what the best practice is here. Thanks!
The text was updated successfully, but these errors were encountered: