You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VSCode扩展的injectionSelector中同时添加HTML和Markdown?

让VSCode扩展同时作用于HTML和Markdown的配置方法

要让你的VSCode扩展同时应用于HTML和Markdown,只需在injectionSelector中用逗号分隔多个目标选择器,同时保留injectTo数组里的两个值即可。

修改后的完整配置示例如下:

"contributes": {
  "grammars": [
    {
      "language": "html",
      "scopeName": "your.extension.scope",
      "injectTo": [
        "text.html.derivative",
        "text.html.markdown"
      ],
      "injectionSelector": "L:text.html.derivative, L:text.html.markdown"
    }
  ]
}

这里的核心是injectionSelector支持多选择器语法,用逗号分隔后,VSCode会同时将你的扩展内容注入到HTML(text.html.derivative)和Markdown(text.html.markdown)的语言上下文环境中,搭配injectTo的配置就能实现同时生效的效果。

如果你的扩展不是语法注入类型(比如代码片段、命令),则需要调整activationEvents来包含两种语言的激活条件,比如:

"activationEvents": [
  "onLanguage:html",
  "onLanguage:markdown"
]

内容的提问来源于stack exchange,提问作者zacoons

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 02:57:04