Skip to content

Clarifications to the table of contents algorithm - #180

Merged
mattgarrish merged 10 commits into
masterfrom
editorial/toc-algo-fixes
Jan 27, 2020
Merged

mattgarrish merged 10 commits into
masterfrom
editorial/toc-algo-fixes

Conversation

@mattgarrish

@mattgarrish mattgarrish commented Dec 14, 2019 •

Copy link
Copy Markdown
Member

This PR addresses the issues noted in #179 as well as the rel tokenizing issues in #177.

@iherman I'm not sure if the note about the event model captures what you wanted or not, so feel free to modify if not.


Preview | Diff

@mattgarrish
mattgarrish requested a review from iherman December 14, 2019 17:23
Comment thread index.html Outdated
white space, split the trimmed value on whitespace and set
<var>current_toc_branch["rel"]</var> to the resulting <a
href="https://infra.spec.whatwg.org/#list">list</a> of tokens.
Otherwise, set <var>current_toc_branch["rel"]</var> to <a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github does not let me comment on unchanged lines; but it is a consequence of this change: In step (4), where current_toc_branch is initialized, I would expect the rel value to be set to either an empty array or, most probably, to null.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this has already been fixed, as I see rel -> null in step 4.

I'm fine with that, but then type should probably be set to null as well for consistency. And in both cases, the "otherwise" statement at the end becomes redundant so can be removed (both values will already be null if their respective conditions to add a value aren't met).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've actually switched all the properties to null by default.

The only one that affects processing is name, but it took me a while to figure out what it was doing. Instead of starting it off as empty string and then setting it to null if a name is an empty string, we should start it off as null and just leave an empty string if that's the result.

Setting it to null conflicts with 5.2, which is where a placeholder gets inserted when the name is an empty string.

Comment thread index.html
exited immediately after it is processed. An event approach could be applied, but would require
modifying the algorithm to process/ignore the omitted nodes.</p>

<ol>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) I think this note should come after the first paragraph. Otherwise, I believe the text is o.k.

(2) The usual terminology in the algorithm is

exit the element and continue processing with the next element.

Maybe a slightly better way is to emphasize the situation, something like

exit the element without descending the sub-tree at this element and continue processing with the next element.

A bit more verbose but may help making things clearer...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's good now, too. The only thing I did was s/omitted/skipped/ in the note to match the terminology from the other PR.

@iherman

iherman commented Dec 15, 2019

Copy link
Copy Markdown
Member

Forgot in the formal github review part: maybe adding a reference to this PR in the change log is also appropriate.

@iherman

iherman commented Dec 16, 2019

Copy link
Copy Markdown
Member

A purely stylistic/editorial comment. I found the name current_toc_branch somehow misleading. The main function of current_toc_branch is to be the current toc entry (the url, the rel values, and all that jazz), and yes, it may have some deeper level toc attached to it, but that is not really a 'branch'. Maybe current_toc_entry or current_toc_node is better?

@iherman

iherman commented Dec 18, 2019

Copy link
Copy Markdown
Member

Actually... I found a bug in my code, and I realized that it was due to my misunderstanding of the text: the use of the word 'exit'.

(1) On the one hand, we use the term 'exiting an XXX element' to denote the (pseudo) event of, well, exiting the element.
(2) On the other hand, we use the phrase 'Exit the element and continue processing with the next element.'

So... does (2) mean that:

(i) the element also goes through the 'exit event', ie, executes the relevant 'event handler'
(ii) the element is essentially forgotten and the next element is handled

If you think indeed in terms of events, the answer is (i). But I believe what we really mean in the algorithm (ii).

My interpretation of the spec code was (i). Specifically, in step 4.2.2. there is an 'exit' of the sort described in (2), which (erroneously) led to the execution of 4.3 and, in the test c2.branches.08 that led to an exception in my code. Indeed, 4.3 turned toc.entries to null, which led to an exception down the line. By changing the interpretation to (ii), things are fine.

Maybe we can avoid this misunderstanding if we use the term 'leaving', instead of 'exiting' in section 4 situation like (1). For example, 4.3. would say "When leaving a list element" instead of "When exiting a list element". And/or we can say "forget the element and continue processing with the next element" for the situation in (2).

WDYT?

- took care of #180 (comment) and #180 (comment)
- to handle the issue #180 (comment) I exchanged the word 'exit' in the relevant sentences to 'omit', with a further clarification in the initial note
@iherman iherman mentioned this pull request Dec 19, 2019
@iherman

iherman commented Dec 19, 2019

Copy link
Copy Markdown
Member

@mattgarrish I have a separate PR (#182) against this PR to handle these issues.

@mattgarrish

Copy link
Copy Markdown
Member Author

Maybe current_toc_entry or current_toc_node is better?

Ya, I like current_toc_node as it doesn't say anything about whether it's a leaf or branch. (It also avoids a bit of ugliness of having current_toc_entry['entries'].)

@mattgarrish

Copy link
Copy Markdown
Member Author

I think between the merged PRs and the changes I've just made everything has been captured now, but can you take another look @iherman ?

@iherman

iherman commented Jan 27, 2020

Copy link
Copy Markdown
Member

@mattgarrish yep, it is a go as far as I am concerned!

@mattgarrish
mattgarrish merged commit caac6b9 into master Jan 27, 2020
@mattgarrish
mattgarrish deleted the editorial/toc-algo-fixes branch January 27, 2020 17:50
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

Successfully merging this pull request may close these issues.

2 participants