-
I'd like to be able to add css classes to images, or tables or other properties. I have seen |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
I have developed a solution to this for my own project at homebrewery.naturalcrit.com that uses a curly brace syntax similar to what you describe. I have several thousand users who thave been using this for years, with quite a bit if user feedback and tweaking along the way. Skim over the home page there to get an idea of how it works. If that format seems useful to you, I can see about separating it into an extension as an NPM package. Or I can point you directly to my extension code for you to paste in. |
Beta Was this translation helpful? Give feedback.
-
The main logic is here https://github.com/arve0/markdown-it-attrs/blob/master/utils.js though not sure how it could be implemented in marked in a way that would work as described(run on each token, "cut" the attributes, parse them and set them on the token object). |
Beta Was this translation helpful? Give feedback.
-
Seems this is the one for markedjs. It is even listed in the "known" extensions list |
Beta Was this translation helpful? Give feedback.
-
Ok, I have figured it out. This is simple extension that just looks for attributes pattern following certain tokens. In this case it hooks into image so it won't trigger if preceding token is text or table or code.
There is no renderer because there is nothing to render but it must return token to avoid the attributes being rendered as text. This obviously works only if the configuration follows the token. Which is great case for image, or link. But table would work better if it preceded it. But tokenizer only has access to preceding tokens. Code block on the other hand must encompass it. So in such cases walkTokens would be needed to massage some values or look ahead for the following token to match. |
Beta Was this translation helpful? Give feedback.
Ok, I have figured it out. This is simple extension that just looks for attributes pattern following certain tokens. In this case it hooks into image so it won't trigger if preceding token is text or table or code.