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

Reverse level #27

Closed
felixsanz opened this issue Feb 24, 2017 · 6 comments
Closed

Reverse level #27

felixsanz opened this issue Feb 24, 2017 · 6 comments
Assignees

Comments

@felixsanz
Copy link

Doesn't level works as opposite as its supposed to?

For example, i want to give an id attribute to my main headers, h1, h2 and h3, but i can't use the level attribute to control that. How i'm supposed to exclude the h4 ones? It should work the opposite :/

level: 3 <- minimum header level of 3 to apply the functionality.

But right now that's just adding the attributes to h3-h6 tags, which is... weird.

@valeriangalliat
Copy link
Owner

Makes sense. Initially my thought was mostly to exclude h1 because the page I was working on had only one h1 and I didn't want give it an anchor, that's why it works this way.

But it think it would be a good idea to make level more flexible, supporting something like level: [1, 3] in your case.

I'll give it a shot over the week-end.

@valeriangalliat valeriangalliat self-assigned this Feb 24, 2017
@felixsanz
Copy link
Author

felixsanz commented Feb 24, 2017

Thats great, an array with the levels where you want to have ids/anchors.

My issue is because i have headings like:

<h4><code>options</code></h4>
<ul>
<li>active: true</li>
<li>...</li>
</ul>

And because my heading doesn't contain text, it's generated like <h4 id=""><code>...</code></h4>, which is invalid. So i want to disable this functionality in <h4> headings, where i usually put code tags.

@valeriangalliat
Copy link
Owner

Oh, interesting, I'd also consider this as a bug, the ID should be a slugified version of the code too. I'm looking into this.

@valeriangalliat
Copy link
Owner

valeriangalliat commented Feb 26, 2017

Hmm, I just tested the following:

equal(
  md({ html: true }).use(anchor).render('#### <code>options</code>'),
  '<h4 id="options"><code>options</code></h4>\n'
)

And it actually passes. What versions of markdown-it and markdown-it-anchor are you using?

Edit: ha, the following indeed have empty ID, I need to fix this.

equal(
  md().use(anchor).render('#### `options`'),
  '<h4 id="options"><code>options</code></h4>\n'
)

valeriangalliat added a commit that referenced this issue Feb 26, 2017
valeriangalliat added a commit that referenced this issue Feb 26, 2017
valeriangalliat added a commit that referenced this issue Feb 26, 2017
valeriangalliat added a commit that referenced this issue Feb 26, 2017
valeriangalliat added a commit that referenced this issue Feb 26, 2017
valeriangalliat added a commit that referenced this issue Feb 26, 2017
@valeriangalliat
Copy link
Owner

I fixed both issues; the inline code is now also used to generate the ID, and you can pass an array of header levels to select in the level option.

It's published as of 4.0.0.

Note that I also dropped Babel support in 4.0.0 so this module only works with a Node version with ES6 support.

@felixsanz
Copy link
Author

Works great, thanks!

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