Closed octref closed 7 years ago
Will use https://github.com/mrmlnc/vscode-pugbeautify for jade/pug.
wonderful~! waiting for the new version~~
Formatters are temporarily disabled until this feature is addressed.
Looking forward to the new version.. I really need the formatter..
I really need the formatter too !~~~~
+1
@octref Couldn't you just disable the formatter per default and make it accessible per workspace settings? I don't think that the added new lines are such a big problem. Maybe just add it as "experimental" feature.
It was working fine for basic setups, wasn't it? Would like to see it enabled back.
This is top on my list. Give me a day or two to work on it.
So here is how it goes. Notice html/css/js/scss/less are all formatted, whereas sass/stylus/pug are left alone.
Will add initial indentation to the template part and remove the initial indentation on js and make a release.
Stole these config from https://github.com/victorporof/Sublime-HTMLPrettify
const htmlOptions = {
brace_style: 'collapse', // [collapse|expand|end-expand|none] Put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are
end_with_newline: false, // End output with newline
indent_char: ' ', // Indentation character
indent_handlebars: false, // e.g. {{#foo}}, {{/foo}}
indent_inner_html: false, // Indent <head> and <body> sections
indent_scripts: 'keep', // [keep|separate|normal]
indent_size: 2, // Indentation size
max_preserve_newlines: 0, // Maximum number of line breaks to be preserved in one chunk (0 disables)
preserve_newlines: true, // Whether existing line breaks before elements should be preserved (only works before elements, not inside tags or for text)
unformatted: ['a', 'span', 'img', 'code', 'pre', 'sub', 'sup', 'em', 'strong', 'b', 'i', 'u', 'strike', 'big', 'small', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], // List of tags that should not be reformatted
wrap_line_length: 0 // Lines should wrap at next opportunity after this number of characters (0 disables)
};
const cssOptions = {
end_with_newline: false, // End output with newline
indent_char: ' ', // Indentation character
indent_size: 2, // Indentation size
newline_between_rules: true, // Add a new line after every css rule
selector_separator: ' ',
selector_separator_newline: true // Separate selectors with newline or not (e.g. 'a,\nbr' or 'a, br')
};
These will be used as initial default, let me know what you agree & don't agree with. (Indentation size & char is read from VSCode config). I'll add capability to specify your own js-beautify config later.
Check out 0.5.3 and let me know how it works.
Still yet to be done:
pressing shift-alt-f for multiple times will increase the indentation of html <!-- -->
comments:
became
and became
0.5.4 preserves new lines for html, and uses force-aligned
to align attributes as @beeplin suggested in #77
Before:
After:
Seems css/scss/less preserve new lines option is being added this weekend, https://github.com/beautify-web/js-beautify/pull/1146
I'll add it once it lands in js-beautify
.
v0.5.4 is wonderful :)
0.5.6 brings CSS preserve_newlines
from js-beautify, and is set as default:
Thanks to @beeplin for submitting the bug, but please, please, please @octref find a way to be able to specify: "html.format.wrapAttributes": "auto" as you mentioned previously in this thread (allow to specify own options). Thank you for your work!
@danikane Will do soon.
@danikane This is already in master so closing. Also auto
is set as default but people can set wrap_attributes
to force-aligned
if they want. Will be available in 0.6.
Many thanks!
@octref Any news on status of pugbeautify integration?
@x8x I forgot that. You can track https://github.com/vuejs/vetur/issues/527.
@octref Amazing! Thx! :-)
vscode-html-languageservice
depends onjs-beautify
directly. However, it's not aware of scss, less regions. It's also causing problems like #77.js-beautify
actually supports scss and less, so vetur will just depend on it directly.Overall:
"vetur.vue-html.format.config": ".htmlbeautifyrc"
"vetur.css.format.config": ".cssbeautifyrc"
"vetur.js.format.config": ".jsbeautifyrc"