Code Monkey home page Code Monkey logo

Comments (11)

hoyois avatar hoyois commented on July 29, 2024

It's been some time since I thought about this, but I'm pretty sure I'm following the algorithm strictly. The definition of depth seemed pretty unintuitive to me as well when I first parsed it. It's a measure of how deeply the heading is within its closest sectioning element parent. So if all sections are explicit, then all headings will have depth 1.

depth = the number of sections that are ancestors of s in the outline that s finds itself in when the outlines are created + 1, where s is the section associated to the heading.

In a situation like body > section > h1 h2 h1, the outline the headings find themselves in is the outline of the enclosing section element (the "current outlinee"), which looks like

section1
— section1.1
section2

so depth of each h1 is 0+1, and depth of the h2 is 1+1. Would you still interpret the definition differently?

from html5outliner.

HughxDev avatar HughxDev commented on July 29, 2024

I don’t know; the definition is very confusing. I would think that depth would correspond to the level of nesting… is there a way to determine that at all?

from html5outliner.

hoyois avatar hoyois commented on July 29, 2024

You should submit a bug report and ask them to clarify the definition. I did that last year for the algorithm itself and they modified it as a result (it used to have 8 points, and two of them were vacuous).

from html5outliner.

hoyois avatar hoyois commented on July 29, 2024

Anyway I'm closing this for the time being. Please reopen it if you get more info.

from html5outliner.

hoyois avatar hoyois commented on July 29, 2024

By the way, an argument in favor this weird definition is that the more obvious notion of depth is so easily computed by other means (just look at the tree of sections!) that it would be redundant to add a property for it.

from html5outliner.

HughxDev avatar HughxDev commented on July 29, 2024

What I am trying to do is add specific attributes (with jQuery) to headings depending on where they appear in the outline tree, without reimplementing the algorithm myself. If it’s easy to do, would you mind giving me an example?

from html5outliner.

hoyois avatar hoyois commented on July 29, 2024

How about this:

var section = heading.associatedSection;
var depth = 0;
while(section = section.parentSection) ++depth;

from html5outliner.

HughxDev avatar HughxDev commented on July 29, 2024

That works, thanks! Maybe it is redundant in HTML; I may still raise the issue, but either way you should consider adding that as a property in your code, perhaps as "nesting" or "level" or similar, in case others are similarly confused.

from html5outliner.

HughxDev avatar HughxDev commented on July 29, 2024

Just posted to the WHATWG about this and was informed that the more intuitive interpretation is in fact correct; the spec is referring to the number of ancestor sections within the entire document outline, not just the current outlinee.

from html5outliner.

hoyois avatar hoyois commented on July 29, 2024

I'll change it then, thanks!

from html5outliner.

hoyois avatar hoyois commented on July 29, 2024

Done. I simply made the depth property into a getter that does exactly what I posted before.

from html5outliner.

Related Issues (6)

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.