0

I'm a very new Sublime Text 2 user and I'm trying to setup a usable HTML Tidy package. I've installed SublimeHtmlTidy and I've left the settings unchanged.

I've added shortcut { "keys": ["ctrl+alt+t"], "command": "html_tidy"}

When I run it on this code:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
 <title>Title</title>
</head>
<body>
<h1>Heading 1</h1>
<p>
Some text
</p>
</body>
</html>

The output I get is this:

<h1>
    Heading 1
</h1>
<p>
    Some text
</p>

..it having stripped the head, body and html tags.

I've tried setting the "show-body-only": true in the hope that it will ignore everything outside the body, and also the "doctype": "omit" and "doctype": "auto" hoping that it will leave the doctype untouched.

What am I doing wrong people? Thanks!

Mere Development
  • 2,439
  • 5
  • 32
  • 63
  • It seems to be a bug. I suppose you selected the whole document when using this command. Please don't select anything when using it. – longhua Nov 20 '13 at 11:55
  • @lhuang It happens when I select everything, or when I select nothing :/ – Mere Development Nov 20 '13 at 12:49
  • Is `show-body-only` set to `true`? – longhua Nov 20 '13 at 12:51
  • I just set up a default install on XP (sorry, I'm not at my OS X box at the moment) with the latest version of PHP and created a new document with the content in your question. I selected `Tidy HTML` from the command palette and it worked perfectly... – MattDMo Nov 20 '13 at 16:31
  • @MattDMo Hi, thanks for trying that. I just tried it that way too (using ctrl+alt+p, Tidy HTML) and the results are the same as the ones I posted. Anything I can do to debug this? – Mere Development Nov 20 '13 at 20:37
  • @MereDevelopment What's your `show-body-only` setting? By the way, from developer's comment, it doesn't support to select the whole document and run Tidy. https://github.com/welovewordpress/SublimeHtmlTidy/issues/34 – longhua Nov 21 '13 at 01:32
  • @lhuang it was set to 'true' after I'd been testing. Setting it back to false allows the Tidy to work as I wanted if nothing is selected. If I select all and then run it, the html/head/body tags are stripped. So as you said at first it must be a bug. Thanks a lot! – Mere Development Nov 21 '13 at 09:13

1 Answers1

1

If show-body-only is set to true, it only prints the contents inside body tags. So if you meet the same issue, please check this setting first.

By design, HTML tidy support two tidy ways:

  1. Tidy the whole document: if you need to tidy the whole document, please select nothing and run tidy command.
  2. Tidy partial HTML in body tags: select the corresponding contents and run tidy command. It is very important to know: this only support contents inside body tags and it may produce strange result if you select contents outside body tags.

By the way, from developer's comment, it doesn't support to select the whole document and run tidy command. please check the following link.

Only return body if I select the whole HTML when running tidy command

longhua
  • 4,142
  • 21
  • 28