inikulin / parse5

HTML parsing/serialization toolset for Node.js. WHATWG HTML Living Standard (aka HTML5)-compliant.
MIT License
3.68k stars 236 forks source link

Retain Attribute Spacing #1303

Open ackava opened 1 month ago

ackava commented 1 month ago

https://astexplorer.net/#/gist/033016ca9df38fea6ac05b61a474df63/74f7e3fff5a4f3771383394151c4a36454399f92

Is there anyway to retain attribute spacing? Check a attribute in h1.

Text Nodes contain whitespaces and whitespace can retain correctly.

I know attribute doesn't have prefix/suffix whitespaces in the HTML spec, but it would be of great help to retain space for WYSWYG editors.

When there are multiple attributes specified, we usually indent them one after another.

wooorm commented 1 month ago

That’s not the job of an AST. No AST persists whitespace. You are trying to do things with parse5 which it can never do. Now, the root question of this question you ask, perhaps there is a solution to that. But I do not know what you want. Please ask what you really really want.