mgdm / htmlq

Like jq, but for HTML.
MIT License
7k stars 107 forks source link

Pretty print removes blank text node between inline elements #58

Open muzimuzhi opened 1 year ago

muzimuzhi commented 1 year ago
$ echo '<code>x</code> <code>y</code>' | htmlq -p body

<body><code>x</code><code>y</code>
</body>%

Here "blank" text node means a text node contains only whitespaces.

Since <code>x</code> <code>y</code> and <code>x</code><code>y</code> give different rendering output, htmlq changes the semantic of this HTML snippet.

It seems the condition on line 70 (see code snippet below) is too loose. Not sure if self.previous_was_block && text.trim().is_empty() is enough. https://github.com/mgdm/htmlq/blob/739cd363543cd5c36a2d7bcbbb3ab7e811205611/src/pretty_print.rs#L69-L81