syntax-tree/hast

Need `raw` node type

xiaoxinghu opened this issue · 4 comments

Type for Raw HTML

There's no type for raw node.

Problem

In TypeScript, when try to push raw type nodes (e.g. u('raw', 'some raw html')) on to a hast tree, you will get a complier error, because raw is not included in acceptable children types.

Expected behaviour

Should there be a Raw type declared publicly?

raw is not really part of hast, it’s more a convention for certain utilities/plugins do pass through HTML as a string untouched. Can you somehow extend your types to allow raw inside your trees?

The issue is actually because of type "Element" in hast. If I want to reference Element directly, there's gonna be errors. But I think I can wrap it with my own type and deal with it there. But it kind of break the strong type protection there.

So you can create a RawSupportingElement and use that?

Yeah, that's what I am currently doing. good to know that it's a convention rather than an official type. Thanks for the quick reply.