Skip to content

Commit

Permalink
feat: wxml格式化添加js-beautify支持 (#162)
Browse files Browse the repository at this point in the history
* feat: wxml格式化添加js-beautify支持

* chore: update package-lock.json

* fix: 修复contributes的配置类型

---------

Co-authored-by: charlzyx <charlzyx@qq.com>
  • Loading branch information
iChenLei and charlzyx committed May 9, 2023
1 parent 9b372b2 commit 124682d
Show file tree
Hide file tree
Showing 6 changed files with 406 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.4.10 / 2023-04-26
==================
* 功能: wxml 格式化添加 js-beautify 支持

2.4.9 / 2023-04-05
==================

Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
```jsonc
{
"minapp-vscode.cssExtname": "less", // 默认 wxss,支持 styl sass scss less css
"minapp-vscode.wxmlExtname": "vue", // 默认 wxml,支持 vue wpy
"minapp-vscode.wxmlExtname": "vue", // 默认 wxml,支持 vue wpy
"minapp-vscode.jsExtname": "ts" // 默认 js,支持 ts coffee
}
```
Expand Down Expand Up @@ -200,12 +200,29 @@ vue 中的 template 板支持两个属性:

### wxml 格式

支持`prettyHtml``prettier`(部分内容需要采用兼容html的方式书写)
支持`prettyHtml`, `js-beautify` `prettier`(部分内容需要采用兼容html的方式书写)

* 默认 `wxml`
```jsonc
"minapp-vscode.wxmlFormatter": "wxml", // 指定格式化工具
```

* [js-beautify](https://github.com/beautify-web/js-beautify#css--html)
```jsonc
"minapp-vscode.wxmlFormatter": "jsBeautifyHtml", // 指定格式化工具
// 使用 vscode settings.json 中的 `html.format.[配置字段]` 配置字段, 详见下方 tips.4
"minapp-vscode.jsBeautifyHtml": "useCodeBuiltInHTML",
// 使用自定义配置
"minapp-vscode.jsBeautifyHtml": { // jsBeautify 默认配置
"content_unformatted": "text",
"wrap_attributes": "force",
"indent_size": 2,
"wrap_attributes_indent_size": 2,
"void_elements": "image,input,video",
"indent_scripts": "keep"
}
```

* [prettyHtml](https://github.com/Prettyhtml/prettyhtml#prettyhtmldoc-string-options-vfile)
```jsonc
"minapp-vscode.wxmlFormatter": "prettyHtml", // 指定格式化工具
Expand Down Expand Up @@ -233,6 +250,7 @@ vue 中的 template 板支持两个属性:
1. 针对`prettyHtml``prettier` 方式,会自动读取项目下的配置文件,[Prettier configuration file](https://prettier.io/docs/en/configuration.html) `.editorconfig`
2. 切换格式化工具需重启 VSCode
3. 针对 `prettyHtml` ,和 `prettier` 采用 HTML5 的语法和 wxml 不完全一致,写法要注意兼容
4. 针对 `jsBeautifyHtml` , 当值为 `"useCodeBuiltInHTML"`时, 配置信息将从 vscode 配置中的 `html.format.*` 配置字段[doc](https://code.visualstudio.com/docs/languages/html#_formatting) 读取, 转换为 [js-beautify](https://github.com/beautify-web/js-beautify#css--html) 的配置

### 常见问题

Expand Down

0 comments on commit 124682d

Please sign in to comment.