HTML non-standard nested language #12

Closed
opened 2023-11-22 22:53:58 +01:00 by Nness · 2 comments
Nness commented 2023-11-22 22:53:58 +01:00 (Migrated from github.com)

I tried to use nested language on a custom HTML tag, which the parser throw error when tag is incomplete.

Related code:
github.com/lezer-parser/html@c95b9713f3/src/content.js (L56-L64)

mj-style custom tag. I have registered mj-style as one of extra tags, then in nested language we ask lezer/html to use CSS parser if it is mj-style tag.

The error is: Invalid inner parse ranges given: [{"from":36,"to":36}]

It happen on following line.

          return {parser: tag.parser, overlay: [{from: open.to, to: close.type.id == CloseTag ? close.from : n.to}]}

The way to fix I believe there are two ways.

  1. parser recognize empty content.
  2. if from === to, then the code should return null.

After more testing, here are the secnarios.

  • <mj-style> no error
  • <mj-style error
  • <mj-style> code </> no error
  • <mj-style>code </mj-st> no error
I tried to use nested language on a custom HTML tag, which the parser throw error when tag is incomplete. Related code: https://github.com/lezer-parser/html/blob/c95b9713f36ede3e44d380ebade2e3bd25751c4c/src/content.js#L56-L64 [mj-style custom tag](https://documentation.mjml.io/#mj-style). I have registered `mj-style` as one of extra tags, then in nested language we ask lezer/html to use CSS parser if it is `mj-style` tag. The error is: `Invalid inner parse ranges given: [{"from":36,"to":36}]` It happen on following line. ```javascript return {parser: tag.parser, overlay: [{from: open.to, to: close.type.id == CloseTag ? close.from : n.to}]} ``` The way to fix I believe there are two ways. 1. parser recognize empty content. 2. if `from === to`, then the code should return null. After more testing, here are the secnarios. * `<mj-style>` no error * ` <mj-style` error * `<mj-style> code </>` no error * ` <mj-style>code </mj-st>` no error
marijnh commented 2023-11-23 11:11:11 +01:00 (Migrated from github.com)

Attached patch should help—it makes sure the logic doesn't create an inner parse when there is no content to parse.

Attached patch should help—it makes sure the logic doesn't create an inner parse when there is no content to parse.
Nness commented 2023-11-23 21:03:29 +01:00 (Migrated from github.com)

Thanks for fast patch 😄

Thanks for fast patch 😄
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#12
No description provided.