我正在编辑一些 3rd 方代码(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),但它变得非常耗时。
我的尝试 PrettyDiff.com
这有点接近了。但是如果我有一个完整的 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
的人吗? -文件?
最佳答案
还不能在 PhpStorm 中以这种方式格式化:https://youtrack.jetbrains.com/issue/WI-12782 & https://youtrack.jetbrains.com/issue/WI-39065 - 相应的功能请求,以添加您可以投票支持的正确格式。
关于formatting - .liquid-file(Shopify 主题文件)的自动格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48808257/