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

Markdown.@md_str breaks syntax highlighting #244

Closed
joshday opened this issue Jun 15, 2021 · 8 comments · Fixed by #249
Closed

Markdown.@md_str breaks syntax highlighting #244

joshday opened this issue Jun 15, 2021 · 8 comments · Fixed by #249

Comments

@joshday
Copy link

joshday commented Jun 15, 2021

Every other string macro I've tried is fine, but md"text" breaks the syntax highlighting for the rest of the document.

Screen Shot 2021-06-15 at 10 05 29 AM

@jeremiahpslewis
Copy link

jeremiahpslewis commented Nov 7, 2021

This seems like it still is an issue and may need to be reopened, example here.

@jeremiahpslewis
Copy link

(Ref: github-linguist/linguist#5637)

@pfitzseb
Copy link
Collaborator

pfitzseb commented Nov 7, 2021

Yeah, turns out I only committed the changelog entry in that PR. Should actually be fixed with #252.

@jeremiahpslewis
Copy link

jeremiahpslewis commented Nov 7, 2021

Hahaha, shame on me for believing the release notes ;) Can you tag a new version so I can annoy github about updating linguist? Just saw 0.22.0. Thanks!

@jeremiahpslewis
Copy link

PR is here for reference: github-linguist/linguist#5638

@Alhadis
Copy link

Alhadis commented Nov 7, 2021

Pro-tip: When embedding third-party grammars (particularly those you have no control over), it's always prudent to use a fixed-size pattern rather than a begin/end pair; i.e., this…

name: "string.quoted.double.julia"
match: '(")((?:[^"\\\\]|\\\\.)*+)(")'
captures:
	1: name: "punctuation.definition.string.begin.julia"
	2: name: "text.embedded.md", patterns: [include: "text.md"]
	3: name: "punctuation.definition.string.end.julia"

… instead of this:

name:  "string.quoted.double.julia"
begin: '"'
end:   '"'
beginCaptures: 0: name: "punctuation.definition.string.begin.julia"
endCaptures:   0: name: "punctuation.definition.string.end.julia"
contentName: "text.embedded.md"
patterns: [include: "text.md"]

I call this technique "clamping", because patterns that would otherwise threaten to spill past the end pattern (and ruin the document's highlighting) are confined to an existing capture group. The trade-off is that it isn't possible to embed multiline patterns this way, but that's a pretty sane trade-off when the alternative is screwing with the entire document.

@pfitzseb
Copy link
Collaborator

pfitzseb commented Nov 7, 2021

Thanks, that's a great solution. Do you have any ideas for multi-line strings, short of removing those rules?

@Alhadis
Copy link

Alhadis commented Nov 7, 2021

Do you have any ideas for multi-line strings, short of removing those rules?

Yes, though it's a little trickier:

name:  "string.quoted.double.julia"
begin: '"'
end:   '"'
beginCaptures: 0: name: "punctuation.definition.string.begin.julia"
endCaptures:   0: name: "punctuation.definition.string.end.julia"
patterns: [{
	name: "text.embedded.md"
	match: '(?:[^"\\\\]|\\\\.)*+'
	captures:
		0: patterns: [include: "text.md"]
}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants