Skip to content

Commit a0d2121

Browse files
committed
Adapt crawl test
also, only insert alternateIds when not empty
1 parent 5f90dd1 commit a0d2121

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/browserlib/map-ids-to-headings.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default function () {
8686
let href = nodeid;
8787

8888
if (parentSection) {
89-
const alternateIds = [];
89+
let alternateIds = [];
9090
let id;
9191

9292
const heading = parentSection.heading;
@@ -117,9 +117,12 @@ export default function () {
117117
if (id) {
118118
mapping.id = id;
119119
}
120+
alternateIds = alternateIds.filter(id => id !== mapping.id);
120121
mapping.href = href;
121122
mapping.title = trimmedText.replace(reNumber, '');
122-
mapping.alternateIds = alternateIds.filter(id => id !== mapping.id);
123+
if (alternateIds.length) {
124+
mapping.alternateIds = alternateIds;
125+
}
123126
mappingTable[nodeid] = mapping;
124127

125128
if (number) {

test/crawl-test.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,24 @@
161161
"id": "toc",
162162
"href": "https://w3c.github.io/mediacapture-output/#toc",
163163
"level": 2,
164-
"title": "Table of Contents"
164+
"title": "Table of Contents",
165+
"alternateIds": ["table-of-contents"]
165166
},
166167
{
167168
"id": "references",
168169
"href": "https://w3c.github.io/mediacapture-output/#references",
169170
"level": 2,
170171
"title": "References",
171-
"number": "A"
172+
"number": "A",
173+
"alternateIds": ["a-references"]
172174
},
173175
{
174176
"id": "informative-references",
175177
"href": "https://w3c.github.io/mediacapture-output/#informative-references",
176178
"level": 3,
177179
"title": "Informative references",
178-
"number": "A.1"
180+
"number": "A.1",
181+
"alternateIds": ["a-1-informative-references"]
179182
}
180183
],
181184
"ids": [

0 commit comments

Comments
 (0)