lezer-parser / html

An HTML parser for Lezer
MIT License
13 stars 10 forks source link

HTML non-standard nested language #12

Closed Nness closed 9 months ago

Nness commented 9 months ago

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. 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.

marijnh commented 9 months ago

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

Nness commented 9 months ago

Thanks for fast patch 😄