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 class for lists with custom bullet? #5

Open
katerlouis opened this issue Nov 18, 2021 · 3 comments
Open

Custom class for lists with custom bullet? #5

katerlouis opened this issue Nov 18, 2021 · 3 comments

Comments

@katerlouis
Copy link

I want to give my editors a secondary bullet-list like this:

markdown:

### look at my list:
% cool marker, mate
% thanks, I know
% and it's so convenient to type!

resulting in this:

<h3>look at my list</h3>
<ul class="custom-class-set-in-config-maybe">
  <li>cool marker, mate</li>
  <li>thanks, I know</li>
  <li>and it's so convenein to type</li>
</ul>

Is that possible with this plugin?

@FritsvanCampen
Copy link
Member

To my knowledge that rule does not follow any spec (markdown or pandoc) so it's a tough ask to add it here.
I think your best option is to write your own plugin.
You can copy the list-rule and add your own list marker character: https://github.com/markdown-it/markdown-it/blob/master/lib/rules_block/list.js#L18-L20

@katerlouis
Copy link
Author

To my knowledge that rule does not follow any spec (markdown or pandoc) so it's a tough ask to add it here. I think your best option is to write your own plugin. You can copy the list-rule and add your own list marker character: https://github.com/markdown-it/markdown-it/blob/master/lib/rules_block/list.js#L18-L20

I tried that and failed miserably :D I have no idea where to add the crucial class assignment that makes the list actually different (<ul class="my-custom-list">)

@FritsvanCampen
Copy link
Member

FritsvanCampen commented Nov 25, 2021

This is where the ul token is generated: https://github.com/markdown-it/markdown-it/blob/master/lib/rules_block/list.js#L199

You can either decide to add the className directly with
token.attrs = [ [ 'className', 'my-custom-list' ] ]
You can do this if % is the only allowed marker character.

Or wait until you find a list item with the % marker in the while-loop below.

What you do exactly also depends on what you want to have happen on markdown like:

### look at my list:
% cool marker, mate
- thanks, I know
- and it's so convenient to type!

or

### look at my list:
- cool marker, mate
% thanks, I know
- and it's so convenient to type!

Does it still add the class? Are these even considered valid lists?

Good luck :)

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

2 participants