【发布时间】:2019-12-20 21:18:41
【问题描述】:
我通常喜欢将 Prettier 与 Visual Code 结合使用。然而,Prettier 在为 Hugo 编辑 HTML 模板时让我抓狂,因为它不会保留对读者友好的格式:
{{ with .Site.Params.author }}<meta name="author" content="{{ . }}">{{ end }}
{{ hugo.Generator }}
{{ "<!-- plugins -->" | safeHTML }}
{{ range .Site.Params.plugins.css }}
<link rel="stylesheet" href="{{ .URL | absURL }} ">
{{ end }}
{{ "<!-- Main Stylesheet -->" | safeHTML }}
{{ $styles := resources.Get "scss/style.scss" | toCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.Permalink }}" integrity="{{ $styles.Data.Integrity }}" media="screen">
相反,它被转换为:
{{ with .Site.Params.author }}
<meta name="author" content="{{ . }}" />
{{ end }} {{ hugo.Generator }} {{ "
<!-- plugins -->
" | safeHTML }} {{ range .Site.Params.plugins.css }}
<link rel="stylesheet" href="{{ .URL | absURL }} " />
{{ end }} {{ "
<!-- Main Stylesheet -->
" | safeHTML }} {{ $styles := resources.Get "scss/style.scss" | toCSS | minify
| fingerprint }}
<link
rel="stylesheet"
href="{{ $styles.Permalink }}"
integrity="{{ $styles.Data.Integrity }}"
media="screen"
/>
如何定制 Prettier 以更好地处理模板逻辑? (从那以后我开始禁用它。)
【问题讨论】:
-
我在这里发现了一个类似的问题:stackoverflow.com/questions/57980680/…
标签: html visual-studio-code vscode-settings hugo prettier