How to get html tag and attribute names from a syntaxtree?

I’m trying to automatically decorate some html:

<svg>
   <polygon points=“5 10, -3 7” />
</svg>

When I try to access this in the syntax tree enter() iterator it gives me the node type but for the life of me I can’t figure out how to get the tag name and attribute name and attribute value.

I guess what I’m hoping for is something like an AST for this html block where I can easily extract:

  1. TagName
  2. AttributeName
  3. PointPairing type (like if I wanted to decorate all coordinates in html)

I looked at elementName in the Lang-html package as one option to extract this from the tree.

Any ideas?

1 Like

Use the from and to positions of the syntax nodes to look up its content in the editor document (state.sliceDoc).

1 Like

Thank you Marijn!

I’m curious: Why aren’t you storing the tagName etc in the syntaxTree? Perf reasons? Smaller memory footprint?

Indeed, memory footprint – the syntax tree is very compact, but it only stores nodes’ type, extent, and child-parent relations.

1 Like