akalongman / sublimetext-codeformatter

Code Formatter plugin for ST2/ST3
MIT License
772 stars 130 forks source link

Many bugs with HTML formatter, can you drop BeautifulSoup? #253

Open CaledoniaProject opened 8 years ago

CaledoniaProject commented 8 years ago

BeautifulSoup does not recognise meta or link tags, and does not work with scripts,

<meta charset="utf-8">
<link charset="utf-8" href="bower_components/bootstrap/dist/css/bootstrap.min.css" media="screen" rel="stylesheet" title="no title">

<script>
  var app = angular.module('metro', []);
  app.controller('tags', function($scope, $http) {
    $scope.tools = tools.filter(function(value) {
      return !value.hide;
    });
  });
</script>

If you try to format anything like that, it would be a total mess.

However, another plugin called HTML/JS/CSS Beautify uses js-beautifier for HTML files and it works great. (Available with package control)

So, can you please replace the BeautifulSoup solution with js-beautifier?

CaledoniaProject commented 8 years ago

Node is required to run to js-beautify, e.g

var js_beautify = require("js-beautify").js_beautify;
var css_beautify = require("js-beautify").css;
var html_beautify = require("js-beautify").html;
RevanProdigalKnight commented 8 years ago

Just out of curiosity, have you tried the RegExp formatter, or just the BeautifulSoup formatter?

CaledoniaProject commented 8 years ago

Hmm, I just use the format command in a html file, how can I try the RegExp formatter?

RevanProdigalKnight commented 8 years ago

Sorry for the delay in response - add "formatter_version": "regexp" to the "codeformatter_html_options" block in your user settings (available under Preferences -> Package Settings -> CodeFormatter -> Settings - User).

I also encourage you to look at the other options available for the HTML formatter once you're on the RegExp formatter.

CaledoniaProject commented 8 years ago

Wow, it works, just some minor problems

1. I must copy the whole codeformatter_html_options and edit on it, if I only use this,

{
    "codeformatter_html_options":
    {
        "formatter_version": "regex"
    }
}

Codeformatter would complain about it

2. It formats <title>xxx</title>

to

<title>
    xxx
</title>

I don't want the new line in <title> tag, is it possible to change that behaviour?

RevanProdigalKnight commented 8 years ago

It's supposed to be "formatter_version": "regexp", not "formatter_version": "regex". That may have been the issue.

I'm still working on a generic fix for problems like your second issue, hopefully I'll get some time to work on it and create a pull request soon.

CaledoniaProject commented 8 years ago

Aha, it was a typo, with regexp CodeFormatter would still complain about it. It wasn't a big problem though