因為自己遇到這個問題,然后百度了很久都得不到解決辦法,所以解決問題以后在博客園寫下此文,希望能幫助到更多人!
//在jsbeautifyrc.js里面的html中加入這個,就OK了
"wrap_attributes":"force"//【own新添加】html屬性是否換新行【auto自動,force強制換行,preserve保護現有格式 】
如果是第一次不會,可以看如下流程圖
1:在插件安裝中找到如下圖所示,點擊配置
此插件是Hbuilder默認自帶的格式化插件
2:點擊 jsbeautify.js這個
3:點擊之后,會打開配置文件,如圖所示
4:在下面html中加入配置:"wrap_attributes":"force"
綠色選中的這一樣就是
"html": {
"indent_handlebars": true,
"indent_inner_html": true,
"indent-scripts": "normal", //[keep|separate|normal]
"extra_liners": [] ,//配置標簽列表,需要在這些標簽前面額外加一空白行
"wrap_attributes":"force"//【own新添加】html屬性是否換新行【auto自動,force強制換行,preserve保護現有格式 】
}
完成的配置參考如下:
點擊查看代碼
module.exports = {
parsers: {
".js": "js",
".json": "js",
".njs": "js",
".sjs": "js",
".wxs": "js",
".css": "css",
".nss": "css",
".wxss": "css",
".acss": "css",
".ttss": "css",
".qss": "css",
".html": "html",
".ux": "html",
".wxml": "html",
".nml": "html",
".vue": "html",
".nvue": "html",
".axml": "html",
".swan": "html",
".ttml": "html",
".qml": "html"
},
options: {
"indent_size": "1",
"indent_char": "\t",
"indent_with_tabs": false, //使用tab縮進
"eol": "\r\n", //行結束符
"end_with_newline": false, //使用換行結束輸出
"indent_level": 0, //起始代碼縮進數
"preserve_newlines": true, //保留空行
"max_preserve_newlines": null, //最大連續保留換行符個數。比如設為2,則會將2行以上的空行刪除為只保留1行
"space_in_paren": false, //括弧添加空格 示例 f( a, b )
"space_in_empty_paren": false, //函數的括弧內沒有參數時插入空格 示例 f( )
"jslint_happy": false, //啟用jslint-strict模式
"space_after_anon_function": false, //匿名函數的括號前加空格
"brace_style": "collapse", //代碼樣式,可選值 [collapse|expand|end-expand|none][,preserve-inline] [collapse,preserve-inline
"unindent_chained_methods": false, //不縮進鏈式方法調用
"break_chained_methods": false, //在隨后的行中斷開鏈式方法調用
"keep_array_indentation": false, //保持數組縮進
"unescape_strings": false, //使用xNN符號編碼解碼可顯示的字符
"wrap_line_length": 120,
"e4x": false, //支持jsx
"comma_first": false, //把逗號放在新行開頭,而不是結尾
"operator_position": "before-newline",
"unformatted": ["wbr"],
"html": {
"indent_handlebars": true,
"indent_inner_html": true,
"indent-scripts": "normal", //[keep|separate|normal]
"extra_liners": [] ,//配置標簽列表,需要在這些標簽前面額外加一空白行
"wrap_attributes":"force"//【own新添加】html屬性是否換新行【auto自動,force強制換行,preserve保護現有格式 】
}
}
}