microsoft/vscode-textmate

Grammar Injection doesn't not work on multi-line content

mjbvz opened this issue · 8 comments

mjbvz commented

From @zh4ui on October 29, 2017 13:8

I tried to inject TOML grammar into markdown, however the TOML colorizer only works on the first line (i.e. a = "b" in the image), it doesn't work on the following line (i.e. d = "c" in the image)

begin-toml-end

My tmLanguage.json for the injection is like:

{
	"fileTypes": [],
	"injectionSelector": "text.html.markdown",
	"name": "tomlfrontmatter",
	"patterns": [
		{
			"begin": "\\Abegin\\s*",
			"end": "(^|\\G)end\\s*$",
				
				"patterns": [
					{
						"include": "source.toml"
					}
				]
		}
	],
	"scopeName": "toml.frontmatter.markdown"
}

The complete source code is at: https://github.com/zh4ui/vscode-markdowntoml.git

  • VSCode Version: Version 1.17.2 (1.17.2)
  • OS Version: macOS 10.13 (17A405)

Steps to Reproduce:

  1. install the Better TOML for TOML colorizer
  2. git clone https://github.com/zh4ui/vscode-markdowntoml.git
  3. cd vscode-markdowntoml && code .
  4. F5 to debug the code
  5. Create a markdown file in the [Extension Development Host]
  6. type in the content
begin a = "b"
c = "d"
end

Reproduces without extensions: No

Copied from original issue: microsoft/vscode#37098

mjbvz commented

I believe we currently only support injecting into a begin end rule. This grammar ends up getting injected into a begin while instead (meta.paragraph.markdown) and ends up not being applied after the first line

r-laf commented

@mjbvz thanks. But would you explain a little bit more about it. What is a "begin...while". TextMate's documentation language_grammars talks about "begin ... end", but it says nothing about "begin...while". What's the difference? Some document for "begin...while" would be perfect for me.

Additionally, can I take your comment for that vscode currently doesn't support multi-line grammar injection?

r-laf commented

Okay. Writing a TextMate Grammar: Some Lessons Learned gives a fairly good explanation about "begin..end" and "begin...while".

I am wondering is there a plan for vscode-textmate to support "begin...while"?

r-laf commented

Well, I've figured out another way to fullfill my need, which is using a markdown-it plugin, according to the api-markdown document.

@mjbvz I think this issue can be closed. Thanks very much.

Related: #41

@zh4ui AFAIK we support "begin...while".

Closing this issue as requested.

@zh4ui How does markdown-it help here? Doesn't it only deal with the markdown preview?
@alexandrudima If it is not "begin...while" issue, what went wrong?

I tried

		{
			"begin": "begin",
			"end": "end",
			"name": "AAA",
			"patterns": [
				{
					"name": "BBB",
					"match": ".+"
			    }
			]
		}

The above pattern correctly recognises each line in the body as BBB

However replacing match to .*, it only recognises the first line. The rest lines are parsed as markdown instead.

r-laf commented

@colinfang

Yes, markdown-it only deals with markdown preview. So I gave up trying.

I've got an impression that currently grammar injection is just a hack, rather than a useable feature.