syntax-tree/hast-util-raw

Unable format element's with properties `type` and `value` that aren't tagName: input

matthewp opened this issue · 6 comments

Initial checklist

Affected packages and versions

hast-util-raw@9

Link to runnable example

https://codepen.io/matthewp/pen/rNRmLLq?editors=1010

Steps to reproduce

This is enough to cause it

import {raw} from 'hast-util-raw'
import {h} from 'hastscript'

const tree = h('div', {'type':'number','value':'1'}, []);

const reformatted = raw(tree);

console.log(reformatted);

Note that if you replace div with input it works fine. I traced this back from an Astro bug which is reproducible at a higher level here: https://stackblitz.com/edit/github-qdnomy?file=src%2Fpages%2Findex.md . In that example the div comes into hast-util-raw as a "raw" node (I think), but I assume that it's the same underlying issue as in the reduced example.

Expected behavior

Should be reformatted with the properties as properties.

Actual behavior

Throws with: Cannot compile number node

Affected runtime and version

node@18 and Chrome

Affected package manager and version

No response

Affected OS and version

No response

Build and bundle tools

Astro

Hey @matthewp! 👋
Sorry you ran into a spot of trouble.
It sounds a lot like you are running into syntax-tree/hastscript#21 please see the discussion there

It does seem that way, @ChristianMurphy, is it better to close this one in that case?

That's a higher-level issue, I think this is the right place for this one.

Ah no, it's with hastscript, that's what's pushing it down into children.

It is better to close this.

Throws with: Cannot compile number node

number is not an MDAST node type https://github.com/syntax-tree/mdast#readme
Handling invalid HTML is not an expectation/requirement of the formatter.

Generate valid HTML for the formatter to work.


Where you are generating the AST make sure it is valid.
If you are using hastscript this is exactly syntax-tree/hastscript#21
If something else is generating the AST, that could be discussed further there.

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.