-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Added fenced code block syntax highlighting in markdown #3771
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
base: master
Are you sure you want to change the base?
Added fenced code block syntax highlighting in markdown #3771
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.
-
Syntax highlighting for Python (and a few others) code blocks doesn't work at all. At least part of the problem is that you seem to have used
python3(from the filename python3.yaml) rather thanpython(from thefiletype: pythonspecified inside the file).

-
We should probably stick to 4 space indentation and use quotes (
") around the regexes to be consistent with other syntax files. -
The starting line should allow aliases like
pyfor Python orrbfor ruby. Github uses linguist for syntax highlighting inside markdown so that might be a good source for these aliases. 1 Another option to look at would be textmate syntax for markdown that is used by VS Code. 2 They seem to have some differences so I guess there is no actual standard. -
commentis not the appropriate syntax group for code snippets. I'd change it todefaultto make the included syntaxes work properly. You can uselimit-group: commentto make just the lines with backticks comment-colored. -
I'm not sure if it's a great idea to include all syntaxes. A handful of most common ones would be good enough for vast majority of users and less likely to cause issues in the future.
Footnotes
Thank you for the feedback @Andriamanitra ! I changed from comment to defaul, correctly referenced the I guess the regexes from VS code seems the easiest to adopt, if logic to handle several names for a language should be adopted from other sources? Right now I did just a quick mapping myself. It seems like my vscode is auto-indenting everything after rules, but I comitted wihtout that now. Regarding Again, thank you for taking your time. |
They should be indented, by 4 spaces (like they are in other syntax files and were in this one before this PR). The indentation size can be configured in VS Code (although why are you using VS Code over micro anyway? 😄 ).
filetype: markdown
detect:
filename: ".md$"
rules:
- special: "^#{1,6}.*"
- default:
start: "```rb"
end: "```"
limit-group: comment
rules:
- include: rubygives highlighting like seen here on the left (compared to the one on the right without
Here we could again use what VS Code does as a starting point. I'm not sure if we want to support all of the same ones but at the very least I'd add
|
Good question ;)
Now I have fixed this, using the match patterns from vscode - however I seem to have som trouble getting the yaml syntax highlighting to work. I am sure there must be something misconfigured somewhere, but I cant find it. The yaml.yaml file works for syntax highlighting, the regex is the same for all other languages (which works).. |
|
A long time ago, I made a script that generates a markdown syntax file with all the syntaxes available in the editor for one of the plugins I use. This is the output (does not use special regex for the markdown.yamlfiletype: markdown
detect:
filename: "\\.(livemd|md|mkd|mkdn|markdown)$"
rules:
# Tables (Github extension)
- type: ".*[ :]\\|[ :].*"
# quotes
- statement: "^>.*"
# Emphasis
- type: "(^|[[:space:]])(_[^ ][^_]*_|\\*[^ ][^*]*\\*)"
# Strong emphasis
- type: "(^|[[:space:]])(__[^ ][^_]*__|\\*\\*[^ ][^*]*\\*\\*)"
# strike-through
- type: "(^|[[:space:]])~~[^ ][^~]*~~"
# horizontal rules
- special: "^(---+|===+|___+|\\*\\*\\*+)\\s*$"
# headlines
- special: "^#{1,6}.*"
# lists
- identifier: "^[[:space:]]*[\\*+-] |^[[:space:]]*[0-9]+\\. "
# misc
- preproc: "(\\(([CcRr]|[Tt][Mm])\\)|\\.{3}|(^|[[:space:]])\\-\\-($|[[:space:]]))"
# links
- constant: "\\[[^]]+\\]"
- constant: "\\[([^][]|\\[[^]]*\\])*\\]\\([^)]+\\)"
# images
- underlined: "!\\[[^][]*\\](\\([^)]+\\)|\\[[^]]+\\])"
# urls
- underlined: "https?://[^ )>]+"
- special: "^```$"
- default:
start: "```PowerShell"
end: "```"
rules:
- include: "PowerShell"
- default:
start: "```ada"
end: "```"
rules:
- include: "ada"
- default:
start: "```apacheconf"
end: "```"
rules:
- include: "apacheconf"
- default:
start: "```arduino"
end: "```"
rules:
- include: "arduino"
- default:
start: "```asciidoc"
end: "```"
rules:
- include: "asciidoc"
- default:
start: "```asm"
end: "```"
rules:
- include: "asm"
- default:
start: "```ats"
end: "```"
rules:
- include: "ats"
- default:
start: "```awk"
end: "```"
rules:
- include: "awk"
- default:
start: "```bat"
end: "```"
rules:
- include: "bat"
- default:
start: "```c"
end: "```"
rules:
- include: "c"
- default:
start: "```caddyfile"
end: "```"
rules:
- include: "caddyfile"
- default:
start: "```cake"
end: "```"
rules:
- include: "cake"
- default:
start: "```clojure"
end: "```"
rules:
- include: "clojure"
- default:
start: "```cmake"
end: "```"
rules:
- include: "cmake"
- default:
start: "```coffeescript"
end: "```"
rules:
- include: "coffeescript"
- default:
start: "```colortest"
end: "```"
rules:
- include: "colortest"
- default:
start: "```conky"
end: "```"
rules:
- include: "conky"
- default:
start: "```cpp"
end: "```"
rules:
- include: "cpp"
- default:
start: "```crontab"
end: "```"
rules:
- include: "crontab"
- default:
start: "```crystal"
end: "```"
rules:
- include: "crystal"
- default:
start: "```csharp"
end: "```"
rules:
- include: "csharp"
- default:
start: "```css"
end: "```"
rules:
- include: "css"
- default:
start: "```csx"
end: "```"
rules:
- include: "csx"
- default:
start: "```cuda"
end: "```"
rules:
- include: "cuda"
- default:
start: "```cython"
end: "```"
rules:
- include: "cython"
- default:
start: "```d"
end: "```"
rules:
- include: "d"
- default:
start: "```dart"
end: "```"
rules:
- include: "dart"
- default:
start: "```default"
end: "```"
rules:
- include: "default"
- default:
start: "```dockerfile"
end: "```"
rules:
- include: "dockerfile"
- default:
start: "```dot"
end: "```"
rules:
- include: "dot"
- default:
start: "```elixir"
end: "```"
rules:
- include: "elixir"
- default:
start: "```elm"
end: "```"
rules:
- include: "elm"
- default:
start: "```erb"
end: "```"
rules:
- include: "erb"
- default:
start: "```erlang"
end: "```"
rules:
- include: "erlang"
- default:
start: "```fish"
end: "```"
rules:
- include: "fish"
- default:
start: "```forth"
end: "```"
rules:
- include: "forth"
- default:
start: "```fortran"
end: "```"
rules:
- include: "fortran"
- default:
start: "```freebsd-kernel"
end: "```"
rules:
- include: "freebsd-kernel"
- default:
start: "```fsharp"
end: "```"
rules:
- include: "fsharp"
- default:
start: "```gdscript"
end: "```"
rules:
- include: "gdscript"
- default:
start: "```gemini"
end: "```"
rules:
- include: "gemini"
- default:
start: "```gentoo-ebuild"
end: "```"
rules:
- include: "gentoo-ebuild"
- default:
start: "```gentoo-etc-portage"
end: "```"
rules:
- include: "gentoo-etc-portage"
- default:
start: "```git-commit"
end: "```"
rules:
- include: "git-commit"
- default:
start: "```git-config"
end: "```"
rules:
- include: "git-config"
- default:
start: "```git-rebase-todo"
end: "```"
rules:
- include: "git-rebase-todo"
- default:
start: "```glsl"
end: "```"
rules:
- include: "glsl"
- default:
start: "```gnuplot"
end: "```"
rules:
- include: "gnuplot"
- default:
start: "```go"
end: "```"
rules:
- include: "go"
- default:
start: "```godoc"
end: "```"
rules:
- include: "godoc"
- default:
start: "```golo"
end: "```"
rules:
- include: "golo"
- default:
start: "```gomod"
end: "```"
rules:
- include: "gomod"
- default:
start: "```graphql"
end: "```"
rules:
- include: "graphql"
- default:
start: "```groff"
end: "```"
rules:
- include: "groff"
- default:
start: "```groovy"
end: "```"
rules:
- include: "groovy"
- default:
start: "```haml"
end: "```"
rules:
- include: "haml"
- default:
start: "```hare"
end: "```"
rules:
- include: "hare"
- default:
start: "```haskell"
end: "```"
rules:
- include: "haskell"
- default:
start: "```hc"
end: "```"
rules:
- include: "hc"
- default:
start: "```html"
end: "```"
rules:
- include: "html"
- default:
start: "```html4"
end: "```"
rules:
- include: "html4"
- default:
start: "```html5"
end: "```"
rules:
- include: "html5"
- default:
start: "```ini"
end: "```"
rules:
- include: "ini"
- default:
start: "```inputrc"
end: "```"
rules:
- include: "inputrc"
- default:
start: "```java"
end: "```"
rules:
- include: "java"
- default:
start: "```javascript"
end: "```"
rules:
- include: "javascript"
- default:
start: "```jinja2"
end: "```"
rules:
- include: "jinja2"
- default:
start: "```json"
end: "```"
rules:
- include: "json"
- default:
start: "```jsonnet"
end: "```"
rules:
- include: "jsonnet"
- default:
start: "```julia"
end: "```"
rules:
- include: "julia"
- default:
start: "```justfile"
end: "```"
rules:
- include: "justfile"
- default:
start: "```keymap"
end: "```"
rules:
- include: "keymap"
- default:
start: "```kickstart"
end: "```"
rules:
- include: "kickstart"
- default:
start: "```kotlin"
end: "```"
rules:
- include: "kotlin"
- default:
start: "```kvlang"
end: "```"
rules:
- include: "kvlang"
- default:
start: "```ledger"
end: "```"
rules:
- include: "ledger"
- default:
start: "```lfe"
end: "```"
rules:
- include: "lfe"
- default:
start: "```lilypond"
end: "```"
rules:
- include: "lilypond"
- default:
start: "```lisp"
end: "```"
rules:
- include: "lisp"
- default:
start: "```log"
end: "```"
rules:
- include: "log"
- default:
start: "```lua"
end: "```"
rules:
- include: "lua"
- default:
start: "```mail"
end: "```"
rules:
- include: "mail"
- default:
start: "```makefile"
end: "```"
rules:
- include: "makefile"
- default:
start: "```man"
end: "```"
rules:
- include: "man"
- default:
start: "```mc"
end: "```"
rules:
- include: "mc"
- default:
start: "```micro"
end: "```"
rules:
- include: "micro"
- default:
start: "```mpdconf"
end: "```"
rules:
- include: "mpdconf"
- default:
start: "```msbuild"
end: "```"
rules:
- include: "msbuild"
- default:
start: "```nanorc"
end: "```"
rules:
- include: "nanorc"
- default:
start: "```nftables"
end: "```"
rules:
- include: "nftables"
- default:
start: "```nginx"
end: "```"
rules:
- include: "nginx"
- default:
start: "```nim"
end: "```"
rules:
- include: "nim"
- default:
start: "```nix"
end: "```"
rules:
- include: "nix"
- default:
start: "```nu"
end: "```"
rules:
- include: "nu"
- default:
start: "```objc"
end: "```"
rules:
- include: "objc"
- default:
start: "```ocaml"
end: "```"
rules:
- include: "ocaml"
- default:
start: "```octave"
end: "```"
rules:
- include: "octave"
- default:
start: "```odin"
end: "```"
rules:
- include: "odin"
- default:
start: "```pascal"
end: "```"
rules:
- include: "pascal"
- default:
start: "```patch"
end: "```"
rules:
- include: "patch"
- default:
start: "```peg"
end: "```"
rules:
- include: "peg"
- default:
start: "```perl"
end: "```"
rules:
- include: "perl"
- default:
start: "```php"
end: "```"
rules:
- include: "php"
- default:
start: "```pkg-config"
end: "```"
rules:
- include: "pkg-config"
- default:
start: "```po"
end: "```"
rules:
- include: "po"
- default:
start: "```pony"
end: "```"
rules:
- include: "pony"
- default:
start: "```pov"
end: "```"
rules:
- include: "pov"
- default:
start: "```privoxy-action"
end: "```"
rules:
- include: "privoxy-action"
- default:
start: "```privoxy-config"
end: "```"
rules:
- include: "privoxy-config"
- default:
start: "```privoxy-filter"
end: "```"
rules:
- include: "privoxy-filter"
- default:
start: "```proto"
end: "```"
rules:
- include: "proto"
- default:
start: "```puppet"
end: "```"
rules:
- include: "puppet"
- default:
start: "```python2"
end: "```"
rules:
- include: "python2"
- default:
start: "```python3"
end: "```"
rules:
- include: "python3"
- default:
start: "```r"
end: "```"
rules:
- include: "r"
- default:
start: "```raku"
end: "```"
rules:
- include: "raku"
- default:
start: "```reST"
end: "```"
rules:
- include: "reST"
- default:
start: "```renpy"
end: "```"
rules:
- include: "renpy"
- default:
start: "```rpmspec"
end: "```"
rules:
- include: "rpmspec"
- default:
start: "```ruby"
end: "```"
rules:
- include: "ruby"
- default:
start: "```rust"
end: "```"
rules:
- include: "rust"
- default:
start: "```sage"
end: "```"
rules:
- include: "sage"
- default:
start: "```scad"
end: "```"
rules:
- include: "scad"
- default:
start: "```scala"
end: "```"
rules:
- include: "scala"
- default:
start: "```sed"
end: "```"
rules:
- include: "sed"
- default:
start: "```sh"
end: "```"
rules:
- include: "sh"
- default:
start: "```sls"
end: "```"
rules:
- include: "sls"
- default:
start: "```smalltalk"
end: "```"
rules:
- include: "smalltalk"
- default:
start: "```solidity"
end: "```"
rules:
- include: "solidity"
- default:
start: "```sql"
end: "```"
rules:
- include: "sql"
- default:
start: "```stata"
end: "```"
rules:
- include: "stata"
- default:
start: "```svelte"
end: "```"
rules:
- include: "svelte"
- default:
start: "```swift"
end: "```"
rules:
- include: "swift"
- default:
start: "```systemd"
end: "```"
rules:
- include: "systemd"
- default:
start: "```tcl"
end: "```"
rules:
- include: "tcl"
- default:
start: "```terraform"
end: "```"
rules:
- include: "terraform"
- default:
start: "```tex"
end: "```"
rules:
- include: "tex"
- default:
start: "```toml"
end: "```"
rules:
- include: "toml"
- default:
start: "```twig"
end: "```"
rules:
- include: "twig"
- default:
start: "```typescript"
end: "```"
rules:
- include: "typescript"
- default:
start: "```v"
end: "```"
rules:
- include: "v"
- default:
start: "```vala"
end: "```"
rules:
- include: "vala"
- default:
start: "```verilog"
end: "```"
rules:
- include: "verilog"
- default:
start: "```vhdl"
end: "```"
rules:
- include: "vhdl"
- default:
start: "```vi"
end: "```"
rules:
- include: "vi"
- default:
start: "```vue"
end: "```"
rules:
- include: "vue"
- default:
start: "```xml"
end: "```"
rules:
- include: "xml"
- default:
start: "```xresources"
end: "```"
rules:
- include: "xresources"
- default:
start: "```yaml"
end: "```"
rules:
- include: "yaml"
- default:
start: "```yum"
end: "```"
rules:
- include: "yum"
- default:
start: "```zig"
end: "```"
rules:
- include: "zig"
- default:
start: "```zscript"
end: "```"
rules:
- include: "zscript"
- default:
start: "```zsh"
end: "```"
rules:
- include: "zsh"
- special:
start: "`"
end: "`"
rules: []
I think at least the syntaxes used in this project should be included: |
But using it would be the right way, when this bug is solved (f2286d0 based on #3127): 😉 |
runtime/syntax/markdown.yaml
Outdated
| filename: "\\.(livemd|md|mkd|mkdn|markdown)$" | ||
|
|
||
| filename: \.(livemd|md|mkd|mkdn|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.
Why touching these two lines at all?
What is the benefit of removing the quotes? The most of the rules are created with quotes and so we should stick to this style/approach.
Please just leave it as it was before this PR (with quotes and additional newline).
At the end this PR should include just 3 commits (currently we've 7):
- change of comments
- change of indentations
- additional rules
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.
Sorry, it comes from the yaml parser and linter used to build the yaml.
When it comes to the number of commits I dont understand what you want me to do. Any feedback that are resolved will generate comitts. Resolving the latter will leave us at 8. If this repo does not allow for squash and merge, I would have to close the PR in that case, as there is no going back afaik.
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.
When it comes to the number of commits I dont understand what you want me to do. Any feedback that are resolved will generate comitts. Resolving the latter will leave us at 8. If this repo does not allow for squash and merge, I would have to close the PR in that case, as there is no going back afaik.
You can rebase locally to squash the commits together (git rebase --interactive master) and then git push --force.
…guage that has syntax highlighting by default in micro
Am I right in interpreting that we should not yet use |
29e1b1a to
d6529a7
Compare
|
I have now squashed commits to the best of ability, with the initial adding og languages, the adding of new lagnuages and regex match groups from vscode and an formatting fix. |
Fixed double set of ?$ Removed whitespace and renamed the syntax highlighting section Reverted dedenting of filename: Fixed indentation of include
d6529a7 to
1f5b858
Compare
From my perspective |
Right, but it is still screwed from single commit perspective: |
But it is not supported right now? I am pretty sure the formatting broke when using |
Could we just squash everything together and add |
|
The diff should look like this at the end...
Yes, we can do and you can keep it commented out if you want. Then we have to activate it when #3127 is merged. |





This is done for every language that has a syntaxfile by default. See issue #3770 . (Note that I have incorporated the feedback from that issue and include each syntaxfile rather than copy the content. I tried to make a master-file that contain all the includes, but nested includes seems to not be supported.