Skip to content
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

Custom rules documentation #617

Closed
rl-saen opened this issue Dec 5, 2019 · 7 comments
Closed

Custom rules documentation #617

rl-saen opened this issue Dec 5, 2019 · 7 comments

Comments

@rl-saen
Copy link

rl-saen commented Dec 5, 2019

Hello everyone,
my CSS dude wants me to add a wrapper element within every li when translating markdown to HTML.

Looking at #598 I see it is possible to inject custom rules and functionality into markdown-it by
modifying mdi.renderer.rules. However, I can't find documentation in the readme as to which keys rules has/expects for certain elements.

When displaying the content of rules at build time it looks like only default rules are present, meaning I have to add new rules myself. But again, I am not sure how to properly extend rules: Looking at #598 I see the function itself doesn't differentiate between elements it applies its changes to all values it receives. So I guess it depends on the key name in rules which element the function is applied on? If so where can I find a list of which key names are available?

Best regards

@puzrin
Copy link
Member

puzrin commented Dec 5, 2019

Advanced modifications require some sources inspect. See https://github.com/markdown-it/markdown-it/blob/master/lib/renderer.js

It uses default renderer function if "named" one not exists. Seems simple.

@rl-saen
Copy link
Author

rl-saen commented Dec 5, 2019

It uses default renderer function if "named" one not exists. Seems simple.

Indeed, but to know which rule I'd have to create I have to know what to name my key in the rule object.

Again looking at #598 I see that to add a rule to access the opening tag of a link I have to set the function at the key link_open. My question in detail is "What is the correct key to add to the rules object to access the opening tag of a li Element?" and in general "Is there a full list somewhere of the possible key names for the rules object?"

Advanced modifications require some sources inspect.

Yes, I did read through parts of the source code but didn't find a solution (maybe looked in the wrong place, etc etc.).

I find it especially strange that the readme explicitly mentions (in the 6th line none the least)

Configurable syntax! You can add new rules and even replace existing ones.

But then there is no follow up on how to do that.

@puzrin
Copy link
Member

puzrin commented Dec 5, 2019

Parser is non trivial thing. We have no resources to write a big book. If you describe exactly what you need, i could try to help with direction.

@rl-saen
Copy link
Author

rl-saen commented Dec 5, 2019

What is the correct way to add rules to access the opening and closing tag of a 'li' Element?

@puzrin
Copy link
Member

puzrin commented Dec 5, 2019

See tags in demo

You probably may wish to override default renderer rules for list_item_open and list_item_close. Something like md.renderer.rules.list_item_open = function (...) { ... }.

Is this what you need?

@rl-saen
Copy link
Author

rl-saen commented Dec 5, 2019

Yes, it is! Thank you very much.

@dhrubajyoti2006
Copy link

Hi Team,

If I want to modify and want to have "$" and "$" as the begin and end to denote "bold" instead of "**", is there a straight forward way yo do it.

Comparing it with other markdown editors, they are called as textPatters. So, my question is - is there a way to pass custom textPatters to this markdownIt

-Regards
Dhrubajyoti

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants