@webref/xref 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@
14
14
  "id": "pagesubtitle",
15
15
  "href": "https://w3c.github.io/svgwg/svg2-draft/#pagesubtitle",
16
16
  "level": 2,
17
- "title": "W3C Editor’s Draft 13 May 2026"
17
+ "title": "W3C Editor’s Draft 20 May 2026"
18
18
  },
19
19
  {
20
20
  "id": "abstract",
package/index.js CHANGED
@@ -63,7 +63,7 @@ function setupExtracts(type, rootFolder) {
63
63
  if (entry.alternateIds) {
64
64
  for (const id of entry.alternateIds) {
65
65
  const url = new URL(entry.href);
66
- url.hash = id;
66
+ url.hash = encodeURIComponent(id);
67
67
  const href = url.toString();
68
68
  indexUrl(href, { source: 'headings', entry });
69
69
  }
@@ -100,8 +100,33 @@ export function setup(rootFolder = scriptPath) {
100
100
  */
101
101
  export function lookup(url) {
102
102
  if (!initialized) {
103
- throw new Error('Cannot run lookup before the `setup()` function gets called');
103
+ throw new Error('The `lookup()` function was called before `setup()`.');
104
104
  }
105
- const res = urlIndex[url];
105
+ if (!url) {
106
+ throw new Error('The `lookup()` function was called without argument.');
107
+ }
108
+
109
+ // URL hashes in Webref extracts are percent-encoded. Goal is to support
110
+ // lookup of both percent-encoded and non percent-encoded URLs. To make sure
111
+ // that we end up with what we need, let's force a decode (this will be a
112
+ // no-op if the fragment is not percent-encoded) before we re-encode.
113
+ let parsedUrl;
114
+ try {
115
+ parsedUrl = new URL(url);
116
+ }
117
+ catch (err) {
118
+ throw new Error('The `lookup()` function was called with an invalid URL.', err);
119
+ }
120
+ let decodedHash;
121
+ try {
122
+ decodedHash = decodeURIComponent(parsedUrl.hash);
123
+ }
124
+ catch {
125
+ decodedHash = parsedUrl.hash;
126
+ }
127
+ parsedUrl.hash = encodeURIComponent(decodedHash.replace(/^#/, ''));
128
+ const lookupUrl = parsedUrl.toString();
129
+
130
+ const res = urlIndex[lookupUrl.toString()];
106
131
  return structuredClone(res) ?? [];
107
132
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webref/xref",
3
3
  "description": "Definitions of the web platform for cross-references purpose",
4
- "version": "1.0.1",
4
+ "version": "1.1.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/w3c/webref.git",