Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case sensitiveness: htmlq not preserving case? #50

Open
ryenus opened this issue Apr 15, 2022 · 3 comments
Open

Case sensitiveness: htmlq not preserving case? #50

ryenus opened this issue Apr 15, 2022 · 3 comments

Comments

@ryenus
Copy link

ryenus commented Apr 15, 2022

Somehow htmlq turns the element, or tag names into lowercase:

Expected

$ echo -e '<Need>\n  <PreserveCase>True</PreserveCase>\n</Need>' | htmlq Need
<Need>
  <PreserveCase>True</PreserveCase>
</Need>

Actual

$ echo -e '<Need>\n  <PreserveCase>True</PreserveCase>\n</Need>' | htmlq Need
<need>
  <preservecase>True</preservecase>
</need>

Here the tag <Need> becomes <need> and <PreserveCase> becomes <preservecase>, which is not what expected.
Possible to preserve the exact case in the tag names? Even behind an option?

Thanks!

@muzimuzhi
Copy link

HTML tag names are case-insensitive, it's XML that uses a case-sensitive pattern.

A quick search suggests the case conversion may come from html5serve, hence it's impossible to config it on htmlq's end. See https://github.com/servo/html5ever/search?q=lowercase.

@ryenus
Copy link
Author

ryenus commented Dec 1, 2022

@muzimuzhi ahh, thank you, that's good to know. Meanwhile I've moved on with yq, which can preserve case properly:

echo -e '<Should><PreserveCase>True</PreserveCase></Should>' | yq -px -ox .Should

Which produces:

<PreserveCase>True</PreserveCase>

@baodrate
Copy link

Meanwhile I've moved on with yq, which can preserve case properly

Except yq, which assumes the input is standard XML rather than HTML, doesn't properly retain the order of text inside each tag (and it doesn't necessarily output valid html):

htmlq -p a <<<'<a>Order <b>should</b> be <em>preserved</em></a>'

produces

<a>Order <b>should</b> be <em>preserved</em></a>

but

yq -px -ox '.a' <<<'<a>Order <b>should</b> be <em>preserved</em></a>'

produces

<+content>Order</+content>
<+content>be</+content>
<b>should</b>
<em>preserved</em>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants