Giter Club home page Giter Club logo

Comments (1)

mbostock avatar mbostock commented on June 15, 2024 1

Investigating…

The code actually does find the H2 elements. The problem is that when an H2 is specified in HTML, unlike Markdown it isn’t automatically wrapped in a header anchor; we use markdown-it-anchor to do that for Markdown. So the code finds the H2 elements, but then ignores them because they don’t have an <a href class="observablehq-header-anchor"> inside.

So, you can declare a heading that is visible in the TOC like so:

<h2 id="this-is-a-test" tabindex="-1">
  <a class="observablehq-header-anchor" href="#this-is-a-test">This is a test</a>
</h2>

(The tabindex attribute is optional but recommended.)

To do this automatically, we’d need to duplicate the behavior of markdown-it-anchor for HTML H2 elements: automatically wrap them in an anchor and compute a unique slug based on the text content of the heading. Another possibility is that we require you to specify the id attribute when specifying an H2 element in HTML (so that there is no ambiguity as to what the link should be); in general we treat HTML as a lower-level API to Markdown.

Probably this means we should not use markdown-it-anchor so we don’t have two code paths for generating heading links; instead, we let markdown-it render the ## as a vanilla H2, and then we use the same code path for turning H2 into heading links regardless of whether it was specified as HTML or as Markdown.

from framework.

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.