有没有办法在扩展之前制作自定义Emmet缩写输入变量?

loading...


0

所以,我在Sublime Text 3上使用Emmet,我已经想出了如何进行自定义片段(在进行扩展缩写命令时直接替换而不进行预处理),

"jq": "<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js' integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=' crossorigin='anonymous' ></script>${child}"

以及如何进行自定义缩写

"sym": "svg[width=${1} height=${1}]>symbol[ id='${2}' viewBox='0 0 ${1} ${1}']"

扩展到

<svg width="|" height="|">
    <symbol id="" viewBox="0 0 | |"></symbol>
</svg>

我想知道的是,是否有一种方法可以制作一个自定义缩写,以便它将一些变量输入到缩写中,就像这样

sym:w200h100x0y0#myCustomSymbol

扩展到

<svg width="200" height="100">
    <symbol id="myCustomSymbol" viewBox="0 0 200 100">|</symbol>
</svg>

我认为它可能是可能的,因为我们可以做的事情链接w100在CSS扩展到宽度:100px .

...对于那些偶然发现这篇文章试图理解如何进行自定义的人来说,你可以转到首选项>包设置> Emmet>设置 - 用户打开文件,在其中写下你自定义东西的json . 首选项>包设置> Emmet>设置 - 默认显示应如何格式化 .

{
    "variables": {
        "lang": "en",
        "greet":"Greetings and Salutations from the People of Earth"
    },
    "snippets": {
        "css": {
            "abbreviations": {
                "tsh": "text-shadow:${1:hoff} ${2:voff} ${3:blur} ${4:#000};"
            },
        },
        "html": {
            "snippets": {
                "jq": "<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js' integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=' crossorigin='anonymous' />${child}",
                "hi":"<div>\n\t${greet}\n</div>"
            },
            "abbreviations": {
                "sym": "svg[width=${1} height=${1}]>symbol[ id='${2}' viewBox='0 0 ${1} ${1}']",
                "hello":"h1>{${greet}}>span"
                // variables can't be placed at the end of an abbreviation, for some reason.
                // however h1>{${greet}} expands correctly if explicit typed in the html document.
            }
        }
    },
    "preferences": {
        "css.valueSeparator": ": ",
        "css.propertyEnd": ";"
    },
}
1回答

  • 0

    不,Emmet没有这样的选择 . 它假定您应首先扩展缩写,然后通过选项卡填充字段

loading...

评论

暂时没有评论!