diff --git a/package.json b/package.json index ea0125b..60e86d0 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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": { diff --git a/src/js-beautify.conf.js b/src/js-beautify.conf.js index c369ebb..139773a 100644 --- a/src/js-beautify.conf.js +++ b/src/js-beautify.conf.js @@ -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": { diff --git a/src/plugins.js b/src/plugins.js index c6757e6..f0b674c 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -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');