Sublime Forum

Prettify HTML for ST4

#1

Hello all

I am trying to find a plugin that can prettify HTML. I used HTML-CSS-JS Prettify before, but it doesn’t seem to work with ST4. I have more or less given up getting package control to work which is super annoying, but it’s possible to install a plugin manually by copying it, right?

So, is there any replacemnet out there for ST4?

I hope you can help.
Br, Donleavy

0 Likes

#2

For auto-formatting, I suggest using the Fmt plugin (available on Package Control or from https://github.com/mitranim/sublime-fmt) which lets you configure formatters for any amount of languages. It works by shelling out to a CLI formatter you have installed on your system. For HTML, I use deno fmt (since I also use Deno for other stuff). This requires the following in your Fmt.sublime-settings:

{
  "rules": [
    {
      "selector": "(text.html - text.html.markdown)",
      "cmd": ["deno", "fmt", "-", "--ext", "html"],
      "env": {"NO_COLOR": "true"},
      "format_on_save": true,
    },
  ],
}

If format_on_save is undesirable, drop that line and add the following to your keymap (change the keys if you want):

{"keys": ["primary+k", "primary+j"], "command": "fmt_format_buffer"}
0 Likes

#3

I’ve used HTML-CSS-JS Prettify as my daily driver for years now and it works flawlessly, including on ST4 (I’m on ST4199/Mac).

The only thing you may need to do is install node (if you haven’t already) and then set your path to node in the plugin. The link above has all the instructions to instal via Package control or Manually.

More recently, I’ve been exploring Formatter which is very powerful but a lot more work to set up. It is in essence a way to trigger other formatting libraries, but you need to install these separately and then configure formatter to trigger them. So far I have it driving Prettier, Prettierd and JSBeutifier.


0 Likes