configureNesting mounted missing #15

Closed
opened 2024-08-12 10:59:00 +02:00 by Tarrowren · 1 comment
Tarrowren commented 2024-08-12 10:59:00 +02:00 (Migrated from github.com)
// test.html
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <div style="display: block"></div>
  </body>
</html>
import { NodeProp } from "@lezer/common";
import { parser as cssParser } from "@lezer/css";
import { configureNesting, parser as htmlParser } from "@lezer/html";
import { readFile } from "node:fs/promises";

const parser = htmlParser.configure({
  wrap: configureNesting(
    [],
    [
      {
        name: "style",
        parser: cssParser.configure({ top: "Styles" }),
      },
    ],
  ),
});

const input = await readFile("test.html", "utf8");
const htmlTree = parser.parse(input);

const mounted = htmlTree.prop(NodeProp.mounted);
console.log(mounted);
// output undefined

The document says: When an array of ranges is given, only those ranges are parsed, and the tree is mounted as an overlay, but I cannot get it

```html // test.html <!doctype html> <html> <head> <meta charset="utf-8" /> </head> <body> <div style="display: block"></div> </body> </html> ``` ```js import { NodeProp } from "@lezer/common"; import { parser as cssParser } from "@lezer/css"; import { configureNesting, parser as htmlParser } from "@lezer/html"; import { readFile } from "node:fs/promises"; const parser = htmlParser.configure({ wrap: configureNesting( [], [ { name: "style", parser: cssParser.configure({ top: "Styles" }), }, ], ), }); const input = await readFile("test.html", "utf8"); const htmlTree = parser.parse(input); const mounted = htmlTree.prop(NodeProp.mounted); console.log(mounted); // output undefined ``` The document says: `When an array of ranges is given, only those ranges are parsed, and the tree is mounted as an overlay`, but I cannot get it
marijnh commented 2024-08-12 13:29:44 +02:00 (Migrated from github.com)

The subtree will be mounted on the syntax node that the nested parser attached to—in this case, the Attribute node—not the top of the tree (though some nested languages do target the top node, the HTML parser doesn't).

The subtree will be mounted on the syntax node that the nested parser attached to—in this case, the `Attribute` node—not the top of the tree (though some nested languages do target the top node, the HTML parser doesn't).
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/html#15
No description provided.