Zet*_*eth 6 formatting liquid shopify phpstorm atom-editor
我正在编辑一些 3rd 方代码(Shopify 主题),但代码绝对不可读。
理想情况下,我希望能够自动格式化.liquid
-files,但似乎无法做到。
我在 PhpStorm 中的尝试
我试过在 PhpStorm 中插入代码并按下CMD + Option + l
(在执行此操作后),这会执行某些操作,但会在随机位置生成换行符,如下所示:
{% unless current_tags %}<h1
class="text-center text-uppercase title-under">{{ 'blogs.general.title_main' | t }}</h1>{% else %}<h1
Run Code Online (Sandbox Code Playgroud)
我在 Atom 中的尝试
在 Atom 中,我尝试安装atom-beautify,但无法识别文件类型。我可以看到其他人也有我的问题。由于.liquid
有相当多的份额.blade.php
的话,我想看看是否有该格式,这导致了一个解决方案开放的线程也。
我尝试研究添加对新语言的支持(使用 atom-beautify),但它非常耗时。
这有点接近了。但是如果我有一个完整的 Shopify 主题,在将代码移动到我的编辑器之前将代码复制到该网站仍然很麻烦。如果PrettyDiff可以绝对钉自动格式化,那么,我就会住它, -但它仍然是这样的:
{% if settings.show_blog_sidebar %}
<div class="col-xl-8 col-lg-8 col-md-12" id="centerColumn">
{% endif %}
Run Code Online (Sandbox Code Playgroud)
我想达到的目标
为了制造这个废话:
{% 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 }}">
...
...
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
{% 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 }}">
...
...
Run Code Online (Sandbox Code Playgroud)
我真的是这个星球上第一个想要自动格式化.liquid
-file 的人吗?
尚无法在 PhpStorm 中以这种方式进行格式化: https: //youtrack.jetbrains.com/issue/WI-12782和https://youtrack.jetbrains.com/issue/WI-39065 - 添加正确格式的相应功能请求你可以投票支持。