Pretty Print/Fix deleting lines of code

For technical support for all editions of CSS HTML Validator. Includes bug reports.
Post Reply
MikeK
Rank I - Novice
Rank I - Novice
Posts: 14
Joined: Sat Oct 14, 2006 6:05 am

Pretty Print/Fix deleting lines of code

Post by MikeK » Fri May 01, 2015 4:48 am

I am converting a site to be responsive using Bootstrap. The following lines of code provide the collapsing Navbar and the bar icon for mobile use:

<div class="navbar navbar-default navbar-static-top">
<div class="container">
<img class="featureImg" src="images/panorama1170x96.jpg" alt="Wokingham panorama" height="100%" width="100%">
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse"></button>
<span class = "icon-bar"></span>
<span class = "icon-bar"></span>
<span class = "icon-bar"></span>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-left">
<li class="active">
<a href="index.html">Home</a>
</li>

Using Pretty Print/Fix on the code deletes four lines leaving:

<div class="navbar navbar-default navbar-static-top">
<div class="container">
<img class="featureImg" src="images/panorama1170x96.jpg" alt="Wokingham panorama" height="100%" width="100%">

<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-left">
<li class="active">
<a href="index.html">Home</a>
</li>

<li>
<a href="aboutws.html">About</a>
</li>

I like to use Pretty Print/Fix but cannot do so if it deletes lines of code rather than just tidying things up.

I would appreciate any thoughts on why it is deleting lines of code and any suggestions of what if anything I can do to stop it doing so.

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Pretty Print/Fix deleting lines of code

Post by Albert Wiersch » Fri May 01, 2015 10:24 am

Hello,

It looks like it's trying to tidy up too much by dropping empty "span" elements.

In the next v15 update I've added two new options under the "More Options" menu: "Drop Empty Elements" and "Drop Empty Paragraphs"

Both new options are checked by default because that is the HTML Tidy default.

What you want is to set drop-empty-elements to false, which is what the "Drop Empty Elements" option will do if the option is unchecked.

To add the option to a HTML Tidy profile, you'll need to edit a file.

Please see:
https://www.htmlvalidator.com/v150/docs ... ofiles.htm

Adding "--drop-empty-elements 0" to the args attribute value of the profile(s) you want to change should do it.

Example:
args="--drop-empty-elements 0"
or
args="--indent 1 --indent-spaces 1 --drop-empty-elements 0"

Then save the file and reload the HTML Tidy profiles or just exit and restart CSE HTML Validator and it will re-read the HTML Tidy profiles to updated with the changes.

If you'd like a new build to try with the new options I've just added to make this easier then let me know what edition you are using.

I hope this helps!
Image
Albert Wiersch

MikeK
Rank I - Novice
Rank I - Novice
Posts: 14
Joined: Sat Oct 14, 2006 6:05 am

Re: Pretty Print/Fix deleting lines of code

Post by MikeK » Fri May 01, 2015 11:41 am

Hello Albert,
I have tried adding to the tidy xml file

<profile name="nodrop" args="--drop-empty-elements 0"/> and alternatively

<profile name="nodrop" args="--indent 1 --indent-spaces 1 --drop-empty-elements 0"/>

but it still drops the four lines.

I am using Validator Standard vesion 15.02.
Perhaps you could send me a new build with the new options.
Thanks,
Mike

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Pretty Print/Fix deleting lines of code

Post by Albert Wiersch » Fri May 01, 2015 12:15 pm

Hi Mike,

You will also need to make sure you're using the correct profile by selecting it... in this case it is "nodrop" as specified by your config file.

I've put online a new version of CSE HTML Validator Standard which you can download here:
https://www.htmlvalidator.com/download/registered.php

You should get v15.0210 even though the page says v15.0200. Please upgrade to that version and let me know how the new option works. Thanks!
Image
Albert Wiersch

MikeK
Rank I - Novice
Rank I - Novice
Posts: 14
Joined: Sat Oct 14, 2006 6:05 am

Re: Pretty Print/Fix deleting lines of code

Post by MikeK » Sat May 02, 2015 8:57 am

Hi Albert,
I selected the "nodrop" profile when checking out args="--drop-empty-elements 0" and args="--indent 1 --indent-spaces 1 --drop-empty-elements 0".

I have downloaded and installed v15.0200. I have searched Options for the "More Options" menu but cannot seem to find it.

Could you tell me where to look to find the "More Options" menu so that I can deselect "Drop Empty Elements" and "Drop Empty Paragraphs".

Mike

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Pretty Print/Fix deleting lines of code

Post by Albert Wiersch » Sat May 02, 2015 9:04 am

Hi Mike,

You'll need v15.0210, not v15.0200.

Then, go to the Pretty Print/Fix tool (Ctrl+F11). There is a "More Options" menu in the control panel on the right. The option should be in there.
Image
Albert Wiersch

MikeK
Rank I - Novice
Rank I - Novice
Posts: 14
Joined: Sat Oct 14, 2006 6:05 am

Re: Pretty Print/Fix deleting lines of code

Post by MikeK » Sun May 03, 2015 3:41 am

Hi Albert,
My mistake in typing my last post. The version I have loaded is:

CSE HTML Validator v15.02 – 32-bit
Editor v15.0210 (Std); Engine DLL v15.0210 (Std)

I can't find the Pretty Print/Fix tool in the menus and (Ctrl+F11) doesn't seem to do anything.

Mike

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Pretty Print/Fix deleting lines of code

Post by Albert Wiersch » Sun May 03, 2015 7:37 am

Hello,

When you load CSE HTML Validator, there should be a 'Tools' menu in the main menu and in that menu a 'Pretty Print/Fix Dialog' option. Is that not there?
Image
Albert Wiersch

MikeK
Rank I - Novice
Rank I - Novice
Posts: 14
Joined: Sat Oct 14, 2006 6:05 am

Re: Pretty Print/Fix deleting lines of code

Post by MikeK » Sun May 03, 2015 10:15 am

Hi Albert,
Found it. I had not found the the 'Options' menu after selecting that a 'Pretty Print/Fix Dialog' option in the 'Tools' menu.

I have unchecked "Drop Empty Elements" but unfortunately 'Pretty Print/Fix' still deletes the four lines.

Thanks for your help. I appreciat that you have spent time trying to resolve this.

I am happy to try anything else that you might suggest but I can manage by copying the four lines, using Pretty Print/Fix and then reinserting the lines.

Mike

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Pretty Print/Fix deleting lines of code

Post by Albert Wiersch » Sun May 03, 2015 10:38 am

That's strange. Please try copying and pasting the below HTML document into a new document and running the Pretty Print & Fix tool on it.

Code: Select all

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Drop test</title>
	<meta name="generator" content="CSE HTML Validator (https://www.htmlvalidator.com/)">
</head>

<body>

<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse"></button>
<span class = "icon-bar"></span>
<span class = "icon-bar"></span>
<span class = "icon-bar"></span>

</body>
</html>
When I do this with the 'Drop Empty Elements' option unchecked it does not drop the empty elements.

If it doesn't work then please go to 'Options->View Last Tidy Command Line' and tell me what it says.

It may be possible that the edits you made to the profile could also be interfering so make sure you choose the appropriate profile in the tool's control panel (the panel on the right side of the Pretty Print & Fix dialog box).
Image
Albert Wiersch

MikeK
Rank I - Novice
Rank I - Novice
Posts: 14
Joined: Sat Oct 14, 2006 6:05 am

Re: Pretty Print/Fix deleting lines of code

Post by MikeK » Mon May 04, 2015 4:44 am

It is working. It shows the span items in a continuous line with the button class but that's just fine.

<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse"></button> <span class=
"icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>

Many thanks for your help in sorting this out and for your useful program that I have used over a number of years for various websites.
Regards,
Mike

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3412
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Pretty Print/Fix deleting lines of code

Post by Albert Wiersch » Mon May 04, 2015 7:39 am

Mike, great! I'm glad it's working. I think it is putting them on the same line because "span" is an inline element and inline elements are usually inline. :)
Image
Albert Wiersch

Post Reply