Giter VIP home page Giter VIP logo

Comments (6)

valeriangalliat avatar valeriangalliat commented on September 24, 2024 1

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'
)

from markdown-it-anchor.

valeriangalliat avatar valeriangalliat commented on September 24, 2024 1

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.

from markdown-it-anchor.

valeriangalliat avatar valeriangalliat commented on September 24, 2024

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.

from markdown-it-anchor.

felixsanz avatar felixsanz commented on September 24, 2024

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.

from markdown-it-anchor.

valeriangalliat avatar valeriangalliat commented on September 24, 2024

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.

from markdown-it-anchor.

felixsanz avatar felixsanz commented on September 24, 2024

Works great, thanks!

from markdown-it-anchor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.