我正在尝试格式化 Twig 文件中的 html,但我遇到了缩进问题。我探索了各种解决方案:
Prettier(通过 ALE 插件):不幸的是,它不支持 Twig。
跑步
php bin/console lint:twig templates/
:这个方法好像不行。
twig-lint:不幸的是,它已经过时了。
在 .vimrc 中添加
let g:twig_indent_html = 1
和 autocmd FileType twig setlocal ft=twig syntax=twig autoindent
: 这没有产生预期的结果。
Twig-CS-Fixer
prettier-plugin-twig-melody(及其分支:https://classic.yarnpkg.com/en/package/@supersoniks/prettier-plugin-twig-melody)
我也尝试过https://github.com/nelsyeung/twig.vim,https://github.com/lumiliet/vim-twig和https://github.com/qbbr/vim -树枝
此外,我还尝试通过 CocInstall coc-htmlhint 使用 htmlhint 以及配置:
let g:coc_filetype_map = {
\ 'twig': 'html',
\ }
一个简短的示例:
{% extends 'base.html.twig' %}
{% block title %}Welcome - Home{% endblock %}
{% block body %}
<h1>Welcome</h1>
<div>
<p>Hello!</p>
</div>
{% endblock %}
我想要一个简短的样本:
{% extends 'base.html.twig' %}
{% block title %}Welcome - Home{% endblock %}
{% block body %}
<h1>Welcome</h1>
<div>
<p>Hello!</p>
</div>
{% endblock %}
但是,我仍然遇到 Twig 文件缩进问题。任何进一步的建议将不胜感激。谢谢。
有了 tidy,一个外部命令,就有可能:
:<line-to-start>,<line-to-end>!tidy --show-errors 0 --show-body-only auto -qi -w 0
您可以按如下方式指定行:
:5,46!tidy --show-errors 0 --show-body-only auto -qi -w 0
适用于第 5 行至第 46 行的应用程序。
答案在这里找到:
使用 HTML Tidy 来缩进 HTML 代码?