【发布时间】:2018-07-26 06:28:39
【问题描述】:
我正在编辑一些第 3 方代码(Shopify 主题),代码完全不可读。
理想情况下,我希望能够自动格式化.liquid-files,但似乎无法做到。
我在 PhpStorm 中的尝试
我尝试在 PhpStorm 中插入代码并按下 CMD + Option + l (after doing this),它会做一些事情,但会在随机的地方换行,如下所示:
{% unless current_tags %}<h1
class="text-center text-uppercase title-under">{{ 'blogs.general.title_main' | t }}</h1>{% else %}<h1
我在 Atom 中的尝试
在 Atom 中,我尝试安装 atom-beautify,但无法识别文件类型。我可以看到others have had my issue as well。由于.liquid 与.blade.php 共享了很多内容,因此我尝试查看是否有针对该格式的解决方案,结果是open thread as well。
我尝试查看adding support for a new language(使用 atom-beautify),但它很快就变得非常耗时。
我对@987654326@的尝试
这有点接近了。但是,如果我有一个完整的 Shopify 主题,在将代码移动到我的编辑器之前,将代码复制到该网站中仍然很麻烦。如果 PrettyDiff 绝对可以钉自动格式化,那么我可能会接受它,但它仍然会做这样的事情:
{% if settings.show_blog_sidebar %}
<div class="col-xl-8 col-lg-8 col-md-12" id="centerColumn">
{% endif %}
我想要达到的目标
做这个废话:
{% unless current_tags %}<h1
class="text-center text-uppercase title-under">{{ 'blogs.general.title_main' | t }}</h1>{% else %}<h1
class="text-center text-uppercase title-under">{{ 'blogs.general.title_result' | t }} {{ current_tags.first | replace: '-', ' ' }}</h1>{% endunless %}
{% for article in blog.articles %}{% if article.excerpt contains "SOMEVAR" %}<p>
test</p>{% capture _article %}{% include "get-content-with-key" content: article.excerpt key: "[SOMEVAR]" %}{% endcapture %}{% capture _title %}{% include "get-content-with-key" content: _article key: "[title]" %}{% endcapture %}{% capture author %}{% include "get-content-with-key" content: _article key: "[author]" %}{% endcapture %}{% capture image %}{% include "get-content-with-key" content: _article key: "[image]" %}{% endcapture %}{% capture content %}{% include "get-content-with-key" content: _article key: "[content]" %}{% endcapture %}{% if _title == '' %}{% assign _title = article.title %}{% endif %}{% if author == '' %}{% assign author = article.author %}{% endif %}
{% if article.comments.size > 0 %}{% assign comment_url = article.url | append: '#comments' %}{% else %}{% assign comment_url = article.url | append: '#addcomment' %}{% endif %}
<div class="{{ grid }}">
...
...
看起来像这样:
{% unless current_tags %}
<h1 class="text-center text-uppercase title-under">{{ 'blogs.general.title_main' | t }}</h1>
{% else %}
<h1 class="text-center text-uppercase title-under">{{ 'blogs.general.title_result' | t }} {{ current_tags.first | replace: '-', ' ' }}</h1>
{% endunless %}
{% for article in blog.articles %}
{% if article.excerpt contains "SOMEVAR" %}
<p>test</p>
{% capture _article %}
{% include "get-content-with-key" content: article.excerpt key: "[SOMEVAR]" %}
{% endcapture %}
{% capture _title %}
{% include "get-content-with-key" content: _article key: "[title]" %}
{% endcapture %}
{% capture author %}
{% include "get-content-with-key" content: _article key: "[author]" %}
{% endcapture %}
{% capture image %}
{% include "get-content-with-key" content: _article key: "[image]" %}
{% endcapture %}
{% capture content %}
{% include "get-content-with-key" content: _article key: "[content]" %}
{% endcapture %}
{% if _title == '' %}
{% assign _title = article.title %}
{% endif %}
{% if author == '' %}
{% assign author = article.author %}
{% endif %}
{% if article.comments.size > 0 %}
{% assign comment_url = article.url | append: '#comments' %}
{% else %}
{% assign comment_url = article.url | append: '#addcomment' %}
{% endif %}
<div class="{{ grid }}">
...
...
我真的是这个星球上第一个想要自动格式化.liquid 文件的人吗?
【问题讨论】:
标签: formatting phpstorm shopify atom-editor liquid