Skip to content

改进:当break_attr_limit大于-1时,折成 属性数/break_attr_limit 行 #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vue-format",
"displayName": "vue-format",
"description": "A beautify extension for .vue file",
"version": "0.1.8",
"version": "0.1.10",
"publisher": "febean",
"keyword": "vue vscode format js-beautify extension",
"engines": {
Expand Down Expand Up @@ -41,7 +41,7 @@
},
"vue-format.break_attr_limit": {
"type": "number",
"default": -1,
"default": 5,
"description": "Break attributes when tag's attributes.length > this number, no break when -1. (tag 的 attrs 大于该数值时,强制 attrs 换行,-1时不换行)"
},
"vue-format.attr_end_with_gt": {
Expand Down
2 changes: 1 addition & 1 deletion src/js-beautify.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
"html_indent_root": false,
"break_attr_limit": -1,
"break_attr_limit": 5,
"attr_end_with_gt": true,
"format_need": ["html", "js", "css"],
"js-beautify": {
Expand Down
8 changes: 7 additions & 1 deletion src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ function breakTagAttr(str = '', breakLimitNum = 1, opt = {
// console.log(matchRes);
if (matchRes.length > breakLimitNum) { // 一个属性强制断行,或者多属性
// 每个 attr 先 trim,然后加换行,空格
let index = -1;
let newStr = tagContent.replace(ATTR_REG, (match, $1) => {
return '\n' + indent + padIndent + $1.trim();
index++;
if(index > 0 && index % breakLimitNum == 0) {
return '\n' + indent + padIndent + $1.trim();
} else {
return ' ' + $1.trim();
}
});
// tag 结束括号换行
newStr = attrEndWithGt ? newStr : newStr.replace(TAG_CLOSE_REG, '\n' + indent + '$1');
Expand Down