syntax-tree / hast-util-raw

utility to reparse a hast tree
https://unifiedjs.com
MIT License
11 stars 4 forks source link

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

Closed matthewp closed 9 months ago

matthewp commented 9 months ago

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

ChristianMurphy commented 9 months ago

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

matthewp commented 9 months ago

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

matthewp commented 9 months ago

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

matthewp commented 9 months ago

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

ChristianMurphy commented 9 months ago

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 https://github.com/syntax-tree/hastscript/issues/21 If something else is generating the AST, that could be discussed further there.

github-actions[bot] commented 9 months ago

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