-
Notifications
You must be signed in to change notification settings - Fork 588
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] add syntax highlighting in code fences for a few languages #1274
[Markdown] add syntax highlighting in code fences for a few languages #1274
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about other frequently used languages like Java, JavaScript, C (and variants) etc.?
Markdown/Markdown.sublime-syntax
Outdated
- match: |- | ||
(?x) | ||
{{fenced_code_block_start}} | ||
((?i:python)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add the 'py' variant, which I use all the time
😉
Markdown/Markdown.sublime-syntax
Outdated
embed_scope: markup.raw.code-fence.xml.markdown | ||
escape: '^[ ]{,3}\1\s*$' | ||
escape_captures: | ||
0: markup.raw.code-fence.xml.markdown punctuation.definition.raw.code-fence.end.markdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the fences should get the punctuation scope, not any whitespace surrounding it.
Adjustments made - I deliberately didn't add too many languages to start with in case tweaks were needed, as unfortunately variables are not supported in the |
Markdown/Markdown.sublime-syntax
Outdated
- match: |- | ||
(?x) | ||
{{fenced_code_block_start}} | ||
((?i:javascript)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
js
also
Disregard, github was only showing me one of the two commits.
Following github's GFM docs I found this: https://github.com/github/linguist/blob/master/lib/linguist/languages.yml. Looks like it's a case-insensitive match of the name and also supports |
I would expect shell is probably one of the most popular fenced syntaxes. According Tiobe, things like C, PHP, Ruby, Obj-C, and Go would probably be higher on the priority list than Rust. |
I vote for the R syntax. (According Tiobe, R scores higher than GO) |
I vote for |
@keith-hall That is an interesting idea. Make embedding sort of optional. The escape would still work, but if the embedded syntax isn't present, just print a warning saying it couldn't be found. |
It would then potentially be possible (though I'm not sure if we want to) to add code fence support for some popular third party syntaxes too :) |
Well, if it printed a warning when they were missing, that would cause the CI tests to fail |
Added C, C++, Go, ObjC, ObjC++, R, Ruby |
Crosslinking to #266, where code fences and strikethrough are the last two issues. |
This won't work correctly until sublimehq/sublime_text#1062 is fixed. For example, comments, line-continuations and character escapes are not rendered for Bash. |
I spent a bit of time on sublimehq/sublime_text#1062 before 3157 went out, but wasn't able to come up with an implementation that didn't break existing default syntaxes in funny ways. I think this is largely due to implementation details, but also this would end up being a change in behavior, so I may just end up documenting the edge case. |
56db252
to
1382bc4
Compare
Markdown/Markdown.sublime-syntax
Outdated
((?i:xml)) | ||
\s*$ # any whitespace until EOL | ||
captures: | ||
2: markup.raw.code-fence.xml.markdown-gfm punctuation.definition.raw.code-fence.begin.markdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these captures should be getting the markup.raw
scope. They aren't part of the "raw" segment since they are not rendered verbatim. (Also, I have dimmed background for markup.raw
and it would be nice if that started on the first line of the raw block.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the escape_captures
for 0
should be removed.
Markdown/Markdown.sublime-syntax
Outdated
1: punctuation.definition.raw.code-fence.begin.markdown | ||
2: constant.other.language-name.markdown | ||
2: punctuation.definition.raw.code-fence.begin.markdown | ||
3: constant.other.language-name.markdown | ||
push: | ||
- meta_scope: markup.raw.code-fence.markdown-gfm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the same reason, this should be meta_content_scope
. And if it would otherwise match on the newline, the match probably needs to include \n
also, but I'm not sure about that.
How about code fence highlighting for JSON as a subset of JavaScript? |
@rwols can you give some examples of some Bash code that doesn't highlight correctly in the Markdown code fence please - I've added some test assertions for comments and character escapes and it seems to be working in build 3161, but maybe I'm missing something? |
I checked out the |
maybe let's get this merged then 😃 🎆 |
@keith-hall |
Is this variable perhaps only used in a pop pattern? If it is, it's not a problem, but checking from mobile isn't worthwhile. |
It is indeed only used from
(at the current state of the Packages/Markdown/Markdown.sublime-syntax Line 123 in 289782f
EDIT 2018-10-29: I have logged this minor problem with the incorrect warning here: sublimehq/sublime_text#2465 |
R Markdown is based on the built in Markdown syntax and I recently received an issue and that seems to be related to this bug. Particular, that is resolved by reverting this PR. |
This PR uses the new
embed
action to add syntax highlighting inside Markdown code fences for XML, SQL, Python and Graphviz.