Custom abbreviation snippet not expanding past first element in Emmet Sublime Text 3

时间:2021-01-16 07:34:13

I am new to Emmet. Trying to create a custom abbreviation that expands to:

我是Emmet的新手。尝试创建扩展为的自定义缩写:

<link rel="stylesheet" href="http://www.domain.com/path/CSstyles.css">
<link rel="stylesheet" href="http://www.domain.com/path/CDstyle2.css">
<link rel="stylesheet" href="http://www.domain.com/path/DEstyle.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 

so I can easily insert a set of styles and script for a site I work on a lot.

所以我可以轻松地为我经常工作的网站插入一组样式和脚本。

I am working in Sublime Text 3 and went to Sublime > Preferences > Package Settings > Emmet > Settings - User and added the following as a starting point:

我正在使用Sublime Text 3并转到Sublime>首选项>包设置> Emmet>设置 - 用户并添加以下内容作为起点:

{
    "snippets": {
         "html": {
            "abbreviations": {
                "lclinks": "<link rel=\"stylesheet\" href=\"http://www.domain.com/path/CSstyles.css\" />+<link rel=\"stylesheet\" href=\"http://www.domain.com/path/CDstyles.css\" />"

            }
         }
    }
}

Which worked, but did not expand past the first style reference. I tried replacing the + with an n\t\ with the same results. I found an example online and plugged that in instead to see if that worked, but it still does not expand past the first element. What am I doing wrong? The documentation here doesn't really address multiple line snippets.

哪个有效,但没有扩展到第一个样式参考。我尝试使用相同的结果将n替换为n \ t \。我在网上找到了一个示例并插入了该示例,以查看是否有效,但它仍然没有超出第一个元素。我究竟做错了什么?这里的文档并没有真正解决多行代码片段。

        {
            "snippets": {
                 "html": {
                    "abbreviations": {
                        "lclinks": "<div class=\"block\">\n\t<div class=\"text\">\n\t\t<h3>|</h3>\n\t\t<p></p>\n\t</div>\n</div>"

                    }
                 }
            }
        }

1 个解决方案

#1


1  

In your example, you are using abbreviations section which is actually parses provided single element HTML tag to use it as a reference for building output. And what you are trying to do is to create a regular text snippet. E.g. a chunk of arbitrary code.

在您的示例中,您使用的是缩写部分,它实际上是解析提供的单个元素HTML标记,以将其用作构建输出的参考。你要做的是创建一个常规的文本片段。例如。一大堆任意代码。

If you read closer snippets.json section, you’ll see that given file contains abbreviations and snippets sections that has different meanings, described here.

如果您阅读更接近的snippets.json部分,您将看到给定文件包含具有不同含义的缩写和片段部分,如此处所述。

In your example, you have to use either snippets section or use aliases in your abbreviations section:

在您的示例中,您必须使用片段部分或在缩写部分中使用别名:

{
    "snippets": {
         "html": {
            "abbreviations": {
                "lclinks": "link[href=http://www.domain.com/path/CSstyles.css]+link[href=http://www.domain.com/path/CDstyle2.css]"
            }
         }
    }
}

#1


1  

In your example, you are using abbreviations section which is actually parses provided single element HTML tag to use it as a reference for building output. And what you are trying to do is to create a regular text snippet. E.g. a chunk of arbitrary code.

在您的示例中,您使用的是缩写部分,它实际上是解析提供的单个元素HTML标记,以将其用作构建输出的参考。你要做的是创建一个常规的文本片段。例如。一大堆任意代码。

If you read closer snippets.json section, you’ll see that given file contains abbreviations and snippets sections that has different meanings, described here.

如果您阅读更接近的snippets.json部分,您将看到给定文件包含具有不同含义的缩写和片段部分,如此处所述。

In your example, you have to use either snippets section or use aliases in your abbreviations section:

在您的示例中,您必须使用片段部分或在缩写部分中使用别名:

{
    "snippets": {
         "html": {
            "abbreviations": {
                "lclinks": "link[href=http://www.domain.com/path/CSstyles.css]+link[href=http://www.domain.com/path/CDstyle2.css]"
            }
         }
    }
}