如何使用 Emmet 在 Sublime 中添加非 html 語法片段? (How to add not html syntax snippet in Sublime with Emmet?)


問題描述

如何使用 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 carry0987Sergey Chikuyonok)

參考文件

  1. How to add not html syntax snippet in Sublime with Emmet? (CC BY‑SA 2.5/3.0/4.0)

#emmet #sublimetext3






相關問題

什麼 zen 編碼表達式擴展為 <input type="hidden" name="FieldName"/>? (What zen coding expression expand to <input type="hidden" name="FieldName"/>?)

使用 zen 編碼片段編輯現有的 html (Edit existing html with zen coding snippet)

43 個 div 的 Emmet 片段 (Emmet snippet for 43 divs)

Webstorm JSX emmet 擴展 (Webstorm JSX emmet expansion)

原子中的 emmet 不能與玉一起使用嗎? (Does emmet in atom not work with jade?)

Vim 中的 ZenCoding 不正確地擴展 css 屬性 (ZenCoding in Vim expands css-properties incorrectly)

用 PHP 標記括號包裹當前行(emmet?) (Wrap current line with PHP tags Brackets (emmet?))

如何在 vscode 中添加對 .mdx/markdown 反應文件類型的 emmet 支持 (How to add emmet support for .mdx / markdown react file types in vscode)

如何使用 Emmet 在 Sublime 中添加非 html 語法片段? (How to add not html syntax snippet in Sublime with Emmet?)

在 VS 代碼中使用 emmet 時,我無法在新行中獲取 <a></a> 標記 (I can't get <a></a> tags in new lines when using emmet in VS code)

VS Code 開始自動關閉標籤,例如 meta、label、input br (VS Code started to selfclose tags like meta, label, input br)

VSCode 缺少 Emmet 換行與縮寫 (VSCode Missing Emmet Wrap Individual Lines with Abbreviation)







留言討論