gogocome

请教 vscode 的 prettier 格式化代码的一个问题

  •  
  •   gogocome · Apr 12, 2022 · 3842 views
    This topic created in 1671 days ago, the information mentioned may be changed or developed.

    部分 html 标签结尾被格式化成这个样子了,右边的尖括号换行了,有办法吗?

    </i
    >15555223321</a
              >
              
    
    8 replies  •  2022-04-15 16:44:05 +08:00
    gogocome
    gogocome
    OP
    Apr 12, 2022
    1
    {
    "singleQuote": true,
    "printWidth": 1500
    }

    没用好像..
    creanme
    creanme
    Apr 12, 2022❤️1
    2
    我印象中好像没法配置,只能手动把里面的内容以及整个右标签换行,然后再格式化,prettier 就不会单独把右尖括号换行了。
    gogocome
    gogocome
    OP
    Apr 12, 2022
    3
    @creanme 这样是可以的.谢谢.
    jawilx
    jawilx
    Apr 12, 2022
    4
    可以配置,不过需要考虑清楚,"htmlWhitespaceSensitivity": "ignore",https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting
    kkocdko
    kkocdko
    Apr 12, 2022 via Android
    5
    4 楼正解。
    这么做的原因是,如果格式化成这样:
    <i>
    123123
    </i>
    会发现内容前后多出了一个空格的位置。大多数 inline 元素都是这样的。因此这两种形式并非完全等价。
    wangtian2020
    wangtian2020
    Apr 13, 2022
    6
    可以先用文件内搜索,搜索框内敲个换行符,然后全部移除掉。这样子你的代码压缩到只有一行了
    这个时候重新格式化
    nzbin
    nzbin
    Apr 13, 2022
    7
    模板格式化建议不要用 prettier ,vscode 自带的格式化更好用,可以参考这篇文章里介绍的模板格式化方法
    https://www.cnblogs.com/nzbin/p/11495417.html
    wdssmq
    wdssmq
    Apr 15, 2022
    8
    "html.format.wrapAttributes": "preserve-aligned"

    已设置。。之后看效果。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4556 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 08:40 · PVG 16:40 · LAX 00:40 · JFK 03:40
    ♥ Do have faith in what you're doing.