formatting - .liquid-file(Shopify 主题文件)的自动格式化

标签 formatting phpstorm shopify atom-editor liquid

我正在编辑一些 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/

相关文章:

class - phpstorm中的自动完成构造函数

Shopify - 获取液体产品标题?

c# - 如何格式化带有千位分隔符和小数点分隔符的 Windows 窗体文本框以进行数字输入

java - 防止 JAXB 将字符串转换为数字 (JSON)

node.js - YUI 压缩器和 PHPStorm

javascript - 在 JavaScript 中为函数参数定义默认值的正确方法

C编程制作乘法表(1-12)

c# - 如何使用 C# 以科学格式解析 double

html - 使用 css/html 在 shopify 页面的行中居中 Logo 图像?

android - 使用 Mobile-Buy-SDK Android 在 Shopify 中查询产品