-
Notifications
You must be signed in to change notification settings - Fork 74
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
Dynamic class name #23
Comments
I think I solved it myself. I wrote a custom render function, like this: md.use(markdownItContainer, 'dynamic', {
validate: function() { return true; },
render: function(tokens, idx) {
var token = tokens[idx];
if (token.nesting === 1) {
return '<div class="' + token.info.trim() + '">';
} else {
return '</div>';
}
},
}); Do you see any problems with an implementation like that? Usage: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus metus tortor, dignissim a libero sed, rhoncus feugiat neque.
::: foo
In fermentum felis non dapibus hendrerit. Proin et urna viverra, tempor purus a, accumsan nulla.
:::
::: bar baz
Vestibulum ornare eros nisl, in facilisis ante tempor non. Vestibulum sit amet arcu ultricies, sollicitudin urna ut, facilisis enim.
:::
Mauris non efficitur justo, quis consectetur risus. Duis eget pellentesque enim. Integer sagittis, turpis vel semper tincidunt, nunc ante dapibus nibh, sit amet ullamcorper ex metus vitae quam. Aliquam id libero in nulla commodo porttitor sed varius diam. Output: <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus metus tortor, dignissim a libero sed, rhoncus feugiat neque.</p>
<div class="foo">
<p>In fermentum felis non dapibus hendrerit. Proin et urna viverra, tempor purus a, accumsan nulla.</p>
</div>
<div class="bar baz">
<p>Vestibulum ornare eros nisl, in facilisis ante tempor non. Vestibulum sit amet arcu ultricies, sollicitudin urna ut, facilisis enim.</p>
</div>
<p>Mauris non efficitur justo, quis consectetur risus. Duis eget pellentesque enim. Integer sagittis, turpis vel semper tincidunt, nunc ante dapibus nibh, sit amet ullamcorper ex metus vitae quam. Aliquam id libero in nulla commodo porttitor sed varius diam. </p> |
Yes, your renderer modifications is ok. You can also skip |
Actually, you need the validate function. Otherwise it will work only with I think the behaviour described in this issue would be a great default. It's also how pandoc behaves by default now. So this:
would work with just:
instead of the current:
|
I don't agree. You mix params (infostring) and container (generated tag) type. Those are ortogonal (independent). Type is mandatory. |
Not sure I understood that. I'm suggesting that if no
is converted to:
for any string Are you saying, that you don't agree that this is a sensible default? But you agree that it is pandoc's default behaviour? |
My comment was about
instead of
You can set last param any name you like, but it should not be missed. |
But what if I want my users to be able to use any class name? Which is in fact what pandoc users can do. |
If you're saying that's a bad default, maybe this could be done by explicitly setting an option, like:
|
I think, you misunderstand the intent of this module. Intent is to be universal (modifyable), for any use case. But example shows only a small subset. If you wish to have default class - just modify renderer to add it, when infostring is empty. |
I'm not sure whether we're talking past each other here. I don't want to have a default class. I want what's pandoc's behaviour, which is the same what the OP of this issue achieved. If the only way to do this is with a custom |
For example, in nodeca we use 2 different container types:
Anyway, you are free to create a new issue, with focus on pandoc similarity, and we can discuss your arguments more detailed. But note, i'm very conservative about extending API, and will ask valuable reasons. |
I see that you consider the default use-case a different one, makes sense as well. Don't think it's worth arguing about defaults. Everyone has a different opinion ;-) Coming from pandoc, I just was expecting something else. That's why I suggested changing it if |
No problem. Just consider this module not as final ready-to-use solution. It helps you to solve very complicated task - how to properly parse block with embedded content. Everything else should be tuned, because very opinion-based. |
Tobbe : thanks, I'm using your code at metabake.org for nested css blocks |
Thanks @Tobbe for the code! It should have been the default behaviour. |
Is it possible to have a generic container that applies a dynamic class name?
Kind of like the info-string for fenced code blocks. I.e. if you write
```java
you get a<code>
with the class namelanguage-java
, but if you write```ruby
the class name will belanguage-ruby
.In a similar manner I would like to be able to do
::: foo
and get<div class="foo">
and::: bar
and get<div class="bar">
. Is this possible? It's important that all use the same opening/closing sequence (:::
) and that I don't have to write anything more than just those three colons and the classname.The text was updated successfully, but these errors were encountered: