@@ -4769,6 +4769,11 @@
User Agent Processing
4769
4769
< p > If a table of contents element is not found, the publication does not have a table of contents that
4770
4770
can be used for machine rendering purposes.p >
4771
4771
4772
+ < p class ="note "> This algorithm is not defined in purely event driven terms, as inspecting all descendant
4773
+ nodes is not necessary to obtain the needed information from the DOM. In some cases, an element is
4774
+ exited immediately after it is processed. An event approach could be applied, but would require
4775
+ modifying the algorithm to process/ignore the omitted nodes.p >
4776
+
4772
4777
< ol >
4773
4778
< li id ="toc-initialize-toc ">
4774
4779
< p > Let < var > tocvar > be the < a href ="https://infra.spec.whatwg.org/#ordered-map "> mapa >
@@ -4885,8 +4890,7 @@
User Agent Processing
4885
4890
< a href ="https://infra.spec.whatwg.org/#list "> lista > , exit the
4886
4891
element and continue processing with the next element.li >
4887
4892
< li > Otherwise, < a href ="https://infra.spec.whatwg.org/#stack-push "> pusha >
4888
- the < a href ="https://infra.spec.whatwg.org/#ordered-map "> mapa > in
4889
- < var > current_toc_branchvar > onto < var > branchesvar > and set
4893
+ < var > current_toc_branchvar > onto < var > branchesvar > and then set
4890
4894
< var > current_toc_branchvar > to < a
4891
4895
href ="https://infra.spec.whatwg.org/#nulls "> nulla > .li >
4892
4896
ol >
@@ -4923,14 +4927,26 @@
User Agent Processing
4923
4927
< p >
4924
4928
< strong > When exiting a < a > list elementa > :strong >
4925
4929
p >
4926
- < p > If < var > branchesvar > is not empty, < a
4927
- href ="https://infra.spec.whatwg.org/#stack-pop "> popa > the top < a
4928
- href ="https://infra.spec.whatwg.org/#ordered-map "> mapa > from
4929
- < var > branchesvar > and set < var > current_toc_branchvar > to it.p >
4930
+ < ol >
4931
+ < li >
4932
+ < p > If < var > branchesvar > is not empty, < a
4933
+ href ="https://infra.spec.whatwg.org/#stack-pop "> popa > the top < a
4934
+ href ="https://infra.spec.whatwg.org/#ordered-map "> mapa > from
4935
+ < var > branchesvar > and set < var > current_toc_branchvar > to it.p >
4936
+ li >
4937
+ < li >
4938
+ < p > Otherwise, if < var > toc.entriesvar > contains an empty < a
4939
+ href ="https://infra.spec.whatwg.org/#list "> lista > , set it to < a
4940
+ href ="https://infra.spec.whatwg.org/#nulls "> nulla > .p >
4941
+ li >
4942
+ ol >
4930
4943
< details >
4931
4944
< summary > Explanationsummary >
4932
- < p > This resets < var > current_toc_branchvar > back to the parent object after all of
4933
- its child branches have been processed.p >
4945
+ < p > This step resets < var > current_toc_branchvar > back to the parent object after
4946
+ all of its child branches have been processed.p >
4947
+ < p > If there are no branches in the stack, the < var > toc.entriesvar > is set to null
4948
+ if it doesn't contain any items (to avoid processing any further lists at the
4949
+ root level).p >
4934
4950
details >
4935
4951
li >
4936
4952
@@ -4958,7 +4974,7 @@
User Agent Processing
4958
4974
details >
4959
4975
li >
4960
4976
4961
- < li id ="toc-dom-exist-list ">
4977
+ < li id ="toc-dom-exit-li ">
4962
4978
< p >
4963
4979
< strong > When exiting a < a
4964
4980
href ="https://html.spec.whatwg.org/multipage/grouping-content.html#the-li-element "
@@ -4972,31 +4988,25 @@
User Agent Processing
4972
4988
href ="https://infra.spec.whatwg.org/#nulls "> nulla > .p >
4973
4989
li >
4974
4990
< li >
4975
- < p > If < var > branches var > is not empty:p >
4991
+ < p > If < var > current_toc_branch["name"] var > is an empty string :p >
4976
4992
< ol >
4977
- < li > if the < var > current_toc_branch["entries"]var > contains a non-empty < a
4978
- href ="https://infra.spec.whatwg.org/#list "> lista > , and
4979
- < var > current_toc_branch["name"]var > is an empty string, set
4993
+ < li > if < var > current_toc_branch["entries"]var > is not < a
4994
+ href ="https://infra.spec.whatwg.org/#nulls "> nulla > , set
4980
4995
< var > current_toc_branch["name"]var > to a placeholder value or < a
4981
4996
href ="https://infra.spec.whatwg.org/#nulls "> nulla > ;li >
4982
- < li > if the < var > current_toc_branch["entries"]var > contains an empty < a
4983
- href ="https://infra.spec.whatwg.org/#list "> lista > , and
4984
- < code > current_toc_branch["name"]code > is an empty < a
4985
- href ="https://infra.spec.whatwg.org/#string "> stringa > , set
4986
- < var > current_toc_branchvar > to < a
4997
+ < li > otherwise, set < var > current_toc_branchvar > to < a
4987
4998
href ="https://infra.spec.whatwg.org/#nulls "> nulla > and exit this
4988
4999
processing step.li >
4989
5000
ol >
4990
- < p > < a href ="https://infra.spec.whatwg.org/#list-append "> Appenda > the < a
4991
- href ="https://infra.spec.whatwg.org/#ordered-map "> mapa > in
4992
- < var > current_toc_branchvar > to the < var > entriesvar > property of the
4993
- < a href ="https://infra.spec.whatwg.org/#ordered-map "> mapa > at the top
4994
- of < var > branchesvar > .p >
4995
5001
li >
4996
5002
< li >
4997
- < p > Otherwise, < a href ="https://infra.spec.whatwg.org/#list-append "> appenda >
4998
- the < a href ="https://infra.spec.whatwg.org/#ordered-map "> mapa > in
4999
- < var > current_toc_branchvar > to < var > toc["entries"]var > .p >
5003
+ < p > If < var > branchesvar > is not empty, < a
5004
+ href ="https://infra.spec.whatwg.org/#list-append "> appenda >
5005
+ < var > current_toc_branchvar > to the < var > entriesvar > property of the < a
5006
+ href ="https://infra.spec.whatwg.org/#ordered-map "> mapa > at the top of
5007
+ < var > branchesvar > . Otherwise, < a
5008
+ href ="https://infra.spec.whatwg.org/#list-append "> appenda >
5009
+ < var > current_toc_branchvar > to < var > toc["entries"]var > .p >
5000
5010
li >
5001
5011
5002
5012
< li >
@@ -5020,15 +5030,16 @@
User Agent Processing
5020
5030
< p > As a final step, < var > current_toc_branchvar > is reset back to
5021
5031
< code > nullcode > .p >
5022
5032
< aside class ="example " title ="Visualization of a branch merge. ">
5023
- < p > If the following two maps are in < var > current_toc_branch var > p >
5033
+ < p > If the following map is in < var > branches var > : p >
5024
5034
< pre > «[
5025
5035
"name" → "Section 1",
5026
5036
"url" → "http://example.com/contents.html#s1",
5027
5037
"type" → "text/html",
5028
5038
"rel" → null,
5029
5039
"entries" → « »
5030
- ]»,
5031
- «[
5040
+ ]»pre >
5041
+ < p > And the following map is in < var > current_toc_branch:var > p >
5042
+ < pre > «[
5032
5043
"name" → "Section 1.1",
5033
5044
"url" → "http://example.com/contents.html#s1.1",
5034
5045
"type" → "text/html",
@@ -5090,8 +5101,8 @@
User Agent Processing
5090
5101
href ="https://infra.spec.whatwg.org/#nulls "> nulla > .p >
5091
5102
li >
5092
5103
< li > If the element has an < code > hrefcode > attribute and the URL in the
5093
- attribute resolves to a resource in the < a > default reading order a > or
5094
- < a > resource list a > , set < var > current_toc_branch["url"]var > to
5104
+ attribute resolves to a resource in < a href =" #reslist-end "
5105
+ > uniqueResources a > , set < var > current_toc_branch["url"]var > to
5095
5106
the value. Otherwise, set < var > current_toc_branch["url"]var > to < a
5096
5107
href ="https://infra.spec.whatwg.org/#nulls "> nulla > .li >
5097
5108
< li > If the element has a < code > typecode > attribute, and the value of the
@@ -5101,8 +5112,10 @@
User Agent Processing
5101
5112
href ="https://infra.spec.whatwg.org/#nulls "> nulla > .li >
5102
5113
< li > If the element has a < code > relcode > attribute, and the value of the
5103
5114
attribute is not an empty string after trimming leading and trailing
5104
- white space, set < var > current_toc_branch["rel"]var > to the trimmed
5105
- value. Otherwise, set < var > current_toc_branch["rel"]var > to < a
5115
+ white space, split the trimmed value on whitespace and set
5116
+ < var > current_toc_branch["rel"]var > to the resulting < a
5117
+ href ="https://infra.spec.whatwg.org/#list "> lista > of tokens.
5118
+ Otherwise, set < var > current_toc_branch["rel"]var > to < a
5106
5119
href ="https://infra.spec.whatwg.org/#nulls "> nulla > .li >
5107
5120
ol >
5108
5121
< p > Exit the element and continue processing with the next element.p >
@@ -5172,10 +5185,8 @@
User Agent Processing
5172
5185
5173
5186
< li id ="toc-finish ">
5174
5187
< p > After completing the DOM walk, if < var > toc["entries"]var > contains a non-empty < a
5175
- href ="https://infra.spec.whatwg.org/#list "> lista > , < var > tocvar > represents the
5176
- machine-processed table of contents.p >
5177
- < p > Otherwise, the digital publication does not have a table of contents that can be used for
5178
- machine rendering purposes.p >
5188
+ href ="https://infra.spec.whatwg.org/#list "> lista > , return < var > tocvar > . Otherwise,
5189
+ return < code > nullcode > .p >
5179
5190
< details >
5180
5191
< summary > Explanationsummary >
5181
5192
< p > If the < code > entriescode > array in the root < em > tocem > object does not contain any
0 commit comments