問題描述
如何使用 Emmet 在 Sublime 中添加非 html 語法片段? (How to add not html syntax snippet in Sublime with Emmet?)
舊的 Emmet 工作正常,但現在我的 Sublime 已自動將 Emmet
插件升級到最新版本,並且以下代碼段不再工作......
最新的 Emmet 只能接受自定義片段上的 HTML 語法
這些片段我看起來很奇怪,因為這些是我的自定義標籤,將在 Template Engine
中轉換為 php 代碼,所以代碼不是 HTML 語法。
例如,當我鍵入 p1
並按 tab
時,我希望它給我 :
{
"config": {
// Configure snippets/options for HTML syntax only.
// For a list of supported syntaxes, check out keys of `syntax_scopes`
// dictionary of `Emmet.sublime‑settings`
"html": {
"snippets": {
"p1": "<!‑‑{if }‑‑>",
"l1": "<!‑‑{/if}‑‑>",
"p2": "<!‑‑{loop }‑‑>",
"l2": "<!‑‑{/loop}‑‑>",
"p3": "<!‑‑{eval }‑‑>",
"p4": "<!‑‑{block }‑‑>",
"l4": "<!‑‑{/block}‑‑>",
"else": "<!‑‑{else}‑‑>",
"elif": "<!‑‑{elseif }‑‑>"
}
}
}
}
參考解法
方法 1:
New Emmet accepts snippet values as Emmet abbreviations (yep, a recursion) and plays better with native ST snippets. Thus, you should either add your snippets as native in ST, or if you still want to use Emmet for such snippets, you should write them as valid Emmet abbreviation. To output arbitrary text in Emmet abbreviation, you should write it as text node, e.g. wrap with {
and }
.
So, your snippet should look like this:
"p1": "{<!‑‑{if }‑‑>}"
(by carry0987、Sergey Chikuyonok)