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

tidy change html view when deal with white-space:pre tag #685

Closed
cztchoice opened this issue Mar 5, 2018 · 2 comments
Closed

tidy change html view when deal with white-space:pre tag #685

cztchoice opened this issue Mar 5, 2018 · 2 comments

Comments

@cztchoice
Copy link

html before tidy

<html>
<head>
<title>Test document</title>
</head>
<body>
<div dir="ltr"><br><ol style=""><li dir="ltr" style="white-space:pre"><p dir="ltr" style=""><span style="white-space:pre-wrap">Since 2003 </span></p></li></div>
</body>
</html>

html look like:
image

after tidy

<!DOCTYPE html>
<html>
<head>
<meta name="generator" content="HTML Tidy for HTML5 (experimental) for Windows https://github.com/w3c/tidy-html5/tree/c63cc39">
<title>Test document</title>
</head>
<body>
<div dir="ltr"><br>

<ol style="">
<li dir="ltr" style="white-space:pre">
<p dir="ltr" style=""><span style="white-space:pre-wrap">Since 2003</span>
</p>
</li>
</ol>
</div>
</body>
</html>

rendered like:
image

tidy cfg:

indent: false
indent-attributes: false 
output-html: yes
input-xml: false
wrap: 0
vertical-space: yes

it looks like tidy doesn't handle white-space style well.

Do you have any work around for this to make html look like correctly?
Thanks.

@geoffmcl
Copy link
Contributor

geoffmcl commented Mar 8, 2018

@cztchoice thanks for the issue...

You seem to be using a quite old version of tidy - The commit c63cc39 shown is around Jul 21, 2012 - but that is not so important since current tidy 5.7.3 will do the same thing...

I am not fully sure what that white-space:pre style is actually supposed to do... but in reading around, testing and experimenting, it certainly has an effect in a browser...

The problem is that tidy will add a newline after the <li...> tag, before the <p> tag... remove that newline and the browser display is correct...

You can try this by adding the special option --vertical-space auto which effectively removes all/most newline characters...

Normally this newline in the <li> element is ignored but you seem to be telling the browser to not ignore the newline with <li style="white-space:pre">, so you get the newline you requested...

Try this sample in a browser -

<ol>
<li style="white-space:pre">
<p>Since 2003</p>
</li>
</ol>
<ol>
<li>
<p>Since 2003</p>
</li>
</ol>

In the first you should see the 1. with the text on a new line, and not in the second... a question of style...

Now tidy does not read, interpret, understand css style elements in a document - it is not a browser! - and its output will not be influenced, changed whatever css is given...

There is a small case for say a new option to force output of an <li>, and probably some others, as sort of always inline only... that is under no circumstances put the <p>, in this case, on a new line... but can not think of even a suitable name at this time to cover all possible cases...

Of course, take away the <p> and maybe the <span...>, and tidy will output the <li> fully inline in most cases...

So to mount this as a Feature Request someone has to suggest a suitable option name, and clearly specify in which cases, to which tags, it should apply, etc... that is provide a full specification, use case and justification...

Look forward to further feedback on this issue... thanks...

@geoffmcl geoffmcl added this to the 5.7 milestone Mar 8, 2018
@geoffmcl
Copy link
Contributor

geoffmcl commented Apr 9, 2021

20210409: Review, years later...

It seems the Feature Request has not been fully fleshed out... so closing this for now...

Look forward to further feedback on the issue, if there is one... thanks...

@geoffmcl geoffmcl closed this as completed Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants