diff --git a/examples/basic.commented.html b/examples/basic.commented.html new file mode 100644 index 0000000000..3d86940e06 --- /dev/null +++ b/examples/basic.commented.html @@ -0,0 +1,117 @@ + + + + + + Replace me with a real title + + + + + +
+

+ This is required. +

+
+
+

+ This is required. +

+
+
+

+ Overview +

+

+ This section has a CSS class "introductory", which means + it will not appear in the TOC. + Example Link to Section. +

+
+
+

+ Introduction +

+

+ This section has a CSS class "informative", so it is + listed in the TOC. ReSpec will list this reference as non-normative + since this is an informative section [[DOM]]. +

+
+
+

+ Foo interface +

+

+      [Exposed Window]
+      interface Foo {
+        constructor();
+        attribute DOMString bar;
+        undefined doTheFoo();
+      };
+      
+

+ The Foo interface is nice. Lets you do stuff. +

+

+ The Foo.constructor() creates a Foo instance +

+

+ The bar attribute, returns 🍺. +

+

+ The doTheFoo() method, returns nothing +

+

+ ReSpec will list this reference as normative [[ECMASCRIPT]]. +

+

+ This is an example of a non-normative reference in a normative section + [[?HTML]] +

+

+        const foo = new Foo();
+        if (foo.bar === "my bar") {
+          foo.doTheBar();
+        }
+      
+
+ +
+

+ IDL Index +

+

+ All the Web IDL in this specification is collected in this section. +

+
+
+ + diff --git a/examples/basic.html b/examples/basic.html index 1c85155111..daa5fdcb70 100644 --- a/examples/basic.html +++ b/examples/basic.html @@ -5,7 +5,7 @@ Replace me with a real title - + @@ -39,7 +39,7 @@

This section has a CSS class "introductory", which means it will not appear in the TOC. - Example Link to Section . + Example Link to Section.

@@ -57,7 +57,7 @@

Foo interface

-      [Exposed=Window]
+      [Exposed Window]
       interface Foo {
         constructor();
         attribute DOMString bar;
@@ -68,13 +68,13 @@ 

The Foo interface is nice. Lets you do stuff.

- The Foo.constructor() creates a Foo instance. + The Foo.constructor() creates a Foo instance

The bar attribute, returns 🍺.

- The doTheFoo() method, returns nothing. + The doTheFoo() method, returns nothing

ReSpec will list this reference as normative [[ECMASCRIPT]]. @@ -101,7 +101,7 @@

- Link to + Link to .

diff --git a/tools/respec2html.js b/tools/respec2html.js index b74787c48c..5c6769d029 100755 --- a/tools/respec2html.js +++ b/tools/respec2html.js @@ -86,7 +86,7 @@ class Logger { const paddedTitle = `${title}:`.padStart(padWidth); console.error(" ", colors.bold(paddedTitle), this._formatMarkdown(value)); }; - print("Count", rsError.elements && String(rsError.elements.length)); + print("Line", rsError.location && rsError.location.join(", ")); print("Plugin", rsError.plugin); print("Hint", rsError.hint); } diff --git a/tools/respecDocWriter.js b/tools/respecDocWriter.js index 00aff742c3..becd066639 100644 --- a/tools/respecDocWriter.js +++ b/tools/respecDocWriter.js @@ -290,6 +290,29 @@ function handleConsoleMessages(page, onError, onWarning) { return JSON.stringify({ message: String(obj) }); } else { // Ideally: `obj instanceof RsError` and `RsError instanceof Error`. + if (obj.elements) { + /** @type {HTMLElement[]} */ + const elems = obj.elements; + const regex = /respec-sourcemap#(.+)/; + /** @param {Node} [node] */ + const hasComment = node => { + if (!node || node.nodeType !== Node.COMMENT_NODE) return false; + return regex.test(node.textContent); + }; + /** @param {Node} node */ + const match = node => node.textContent.match(regex)[1].trim(); + const location = elems.map(el => { + if (hasComment(el.firstChild)) { + return match(el.firstChild); + } + if (hasComment(el.nextSibling)) { + return match(el.nextSibling); + } + return 0; + }); + const result = { ...JSON.parse(JSON.stringify(obj)), location }; + return JSON.stringify(result); + } return JSON.stringify(obj); } }, handle);