Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injection grammars with embeddedLanguages #34316

Closed
mjbvz opened this issue Sep 13, 2017 · 2 comments · Fixed by #34327
Closed

Injection grammars with embeddedLanguages #34316

mjbvz opened this issue Sep 13, 2017 · 2 comments · Fixed by #34327
Assignees
Labels
api grammar Syntax highlighting grammar verification-needed Verification of issue is requested verified Verification succeeded

Comments

@mjbvz
Copy link
Collaborator

mjbvz commented Sep 13, 2017

Problem
I'm trying to write an injection for css grammar into JS/TS template strings. The following injection works, the embeddedLanguages property does not seem to be observed for injections

    "grammars": [
      {
        "scopeName": "meta.embedded.css",
        "path": "./syntaxes/injection.json",
        "injectTo": [
          "source.js",
          "source.jsx",
          "source.ts",
          "source.tsx"
        ],
        "embeddedLanguages": {
          "meta.embedded.css": "css"
        }
      }
    ]
@mjbvz mjbvz added api grammar Syntax highlighting grammar labels Sep 13, 2017
@mjbvz mjbvz added this to the September 2017 milestone Sep 13, 2017
mjbvz added a commit to mjbvz/vscode that referenced this issue Sep 13, 2017
Fixes microsoft#34316

Enables contributed injection grammars to specify an embedded language for their injection targets:

```json
"grammars": [
  {
	"scopeName": "meta.embedded.css",
	"path": "./syntaxes/injection.json",
	"injectTo": [
	  "source.js",
	  "source.jsx",
	  "source.ts",
	  "source.tsx"
	],
	"embeddedLanguages": {
	  "meta.embedded.css": "css"
	}
  }
]
```
@mjbvz mjbvz added the verification-needed Verification of issue is requested label Sep 18, 2017
mjbvz added a commit that referenced this issue Sep 18, 2017
Fixes #34316

Enables contributed injection grammars to specify an embedded language for their injection targets:

```json
"grammars": [
  {
	"scopeName": "meta.embedded.css",
	"path": "./syntaxes/injection.json",
	"injectTo": [
	  "source.js",
	  "source.jsx",
	  "source.ts",
	  "source.tsx"
	],
	"embeddedLanguages": {
	  "meta.embedded.css": "css"
	}
  }
]
```
@mjbvz
Copy link
Collaborator Author

mjbvz commented Sep 18, 2017

To verify, try creating a new injection grammar such as:

{
	"fileTypes": [],
	"injectionSelector": "L:markup.fenced_code.block.markdown",
	"patterns": [
		{
			"include": "#superjs-code-block"
		}
	],
	"repository": {
		"superjs-code-block": {
			"begin": "superjs",
			"end": "(^|\\G)(?=\\s*[`~]{3,}\\s*$)",
			"patterns": [
				{
					"include": "source.js"
				}
			]
		}
	},
	"scopeName": "markdown.superjs.codeblock"
}

with contributes:

{
        "scopeName": "markdown.superjs.codeblock",
        "path": "./syntaxes/test.json",
        "injectTo": [
          "text.html.markdown"
        ]
      }

This will highlight:

```superjs
1 + 1
```

blocks in markdown. Try adding embeddedLanguages and confirm that the content of the code block are the correct language

@alexdima
Copy link
Member

@mjbvz The best is to reach out to @aeschli . he implemented all the injection stuff in vscode-textmate.

@roblourens roblourens added the verified Verification succeeded label Sep 27, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api grammar Syntax highlighting grammar verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants