You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

syntax-highlighting.md 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. +++
  2. title = "Syntax Highlighting"
  3. weight = 80
  4. +++
  5. Gutenberg comes with built-in syntax highlighting but you first
  6. need to enable it in the [configuration](./documentation/getting-started/configuration.md).
  7. Once this is done, Gutenberg will automatically highlight all code blocks
  8. in your content. A code block in Markdown looks like the following:
  9. ````md
  10. ```rust
  11. let highlight = true;
  12. ```
  13. ````
  14. You can replace the `rust` by the language you want to highlight or not put anything to get it
  15. interpreted as plain text.
  16. Here is a full list of the supported languages and the short names you can use:
  17. ```
  18. - Plain Text -> ["txt"]
  19. - Assembly x86 (NASM) -> ["asm", "inc", "nasm"]
  20. - Crystal -> ["cr"]
  21. - Elixir -> ["ex", "exs"]
  22. - Handlebars -> ["handlebars", "handlebars.html", "hbr", "hbrs", "hbs", "hdbs", "hjs", "mu", "mustache", "rac", "stache", "template", "tmpl"]
  23. - Jinja2 -> ["j2", "jinja2"]
  24. - Julia -> ["jl"]
  25. - Kotlin -> ["kt", "kts"]
  26. - Less -> ["less", "css.less"]
  27. - MiniZinc (MZN) -> ["mzn", "dzn"]
  28. - Nim -> ["nim", "nims"]
  29. - ASP -> ["asa"]
  30. - HTML (ASP) -> ["asp"]
  31. - ActionScript -> ["as"]
  32. - AppleScript -> ["applescript", "script editor"]
  33. - Batch File -> ["bat", "cmd"]
  34. - NAnt Build File -> ["build"]
  35. - C# -> ["cs", "csx"]
  36. - C++ -> ["cpp", "cc", "cp", "cxx", "c++", "C", "h", "hh", "hpp", "hxx", "h++", "inl", "ipp"]
  37. - C -> ["c", "h"]
  38. - CSS -> ["css", "css.erb", "css.liquid"]
  39. - Clojure -> ["clj"]
  40. - D -> ["d", "di"]
  41. - Diff -> ["diff", "patch"]
  42. - Erlang -> ["erl", "hrl", "Emakefile", "emakefile"]
  43. - HTML (Erlang) -> ["yaws"]
  44. - Git Attributes -> ["attributes", "gitattributes", ".gitattributes"]
  45. - Git Commit -> ["COMMIT_EDITMSG", "MERGE_MSG", "TAG_EDITMSG"]
  46. - Git Config -> ["gitconfig", ".gitconfig", ".gitmodules"]
  47. - Git Ignore -> ["exclude", "gitignore", ".gitignore"]
  48. - Git Link -> [".git"]
  49. - Git Log -> ["gitlog"]
  50. - Git Rebase Todo -> ["git-rebase-todo"]
  51. - Go -> ["go"]
  52. - Graphviz (DOT) -> ["dot", "DOT", "gv"]
  53. - Groovy -> ["groovy", "gvy", "gradle", "Jenkinsfile"]
  54. - HTML -> ["html", "htm", "shtml", "xhtml"]
  55. - Haskell -> ["hs"]
  56. - Literate Haskell -> ["lhs"]
  57. - Java Server Page (JSP) -> ["jsp"]
  58. - Java -> ["java", "bsh"]
  59. - Java Properties -> ["properties"]
  60. - JSON -> ["json", "sublime-settings", "sublime-menu", "sublime-keymap", "sublime-mousemap", "sublime-theme", "sublime-build", "sublime-project", "sublime-completions", "sublime-commands", "sublime-macro", "sublime-color-scheme"]
  61. - JavaScript -> ["js", "htc"]
  62. - BibTeX -> ["bib"]
  63. - LaTeX -> ["tex", "ltx"]
  64. - TeX -> ["sty", "cls"]
  65. - Lisp -> ["lisp", "cl", "clisp", "l", "mud", "el", "scm", "ss", "lsp", "fasl"]
  66. - Lua -> ["lua"]
  67. - Makefile -> ["make", "GNUmakefile", "makefile", "Makefile", "makefile.am", "Makefile.am", "makefile.in", "Makefile.in", "OCamlMakefile", "mak", "mk"]
  68. - Markdown -> ["md", "mdown", "markdown", "markdn"]
  69. - MATLAB -> ["matlab"]
  70. - OCaml -> ["ml", "mli"]
  71. - OCamllex -> ["mll"]
  72. - OCamlyacc -> ["mly"]
  73. - Objective-C++ -> ["mm", "M", "h"]
  74. - Objective-C -> ["m", "h"]
  75. - PHP -> ["php", "php3", "php4", "php5", "php7", "phps", "phpt", "phtml"]
  76. - Pascal -> ["pas", "p", "dpr"]
  77. - Perl -> ["pl", "pm", "pod", "t", "PL"]
  78. - Python -> ["py", "py3", "pyw", "pyi", "pyx", "pyx.in", "pxd", "pxd.in", "pxi", "pxi.in", "rpy", "cpy", "SConstruct", "Sconstruct", "sconstruct", "SConscript", "gyp", "gypi", "Snakefile", "wscript"]
  79. - R -> ["R", "r", "s", "S", "Rprofile"]
  80. - Rd (R Documentation) -> ["rd"]
  81. - HTML (Rails) -> ["rails", "rhtml", "erb", "html.erb"]
  82. - JavaScript (Rails) -> ["js.erb"]
  83. - Ruby Haml -> ["haml", "sass"]
  84. - Ruby on Rails -> ["rxml", "builder"]
  85. - SQL (Rails) -> ["erbsql", "sql.erb"]
  86. - Regular Expression -> ["re"]
  87. - reStructuredText -> ["rst", "rest"]
  88. - Ruby -> ["rb", "Appfile", "Appraisals", "Berksfile", "Brewfile", "capfile", "cgi", "Cheffile", "config.ru", "Deliverfile", "Fastfile", "fcgi", "Gemfile", "gemspec", "Guardfile", "irbrc", "jbuilder", "podspec", "prawn", "rabl", "rake", "Rakefile", "Rantfile", "rbx", "rjs", "ruby.rail", "Scanfile", "simplecov", "Snapfile", "thor", "Thorfile", "Vagrantfile"]
  89. - Rust -> ["rs"]
  90. - SQL -> ["sql", "ddl", "dml"]
  91. - Scala -> ["scala", "sbt"]
  92. - Bourne Again Shell (bash) -> ["sh", "bash", "zsh", "fish", ".bash_aliases", ".bash_completions", ".bash_functions", ".bash_login", ".bash_logout", ".bash_profile", ".bash_variables", ".bashrc", ".profile", ".textmate_init", ".zshrc"]
  93. - HTML (Tcl) -> ["adp"]
  94. - Tcl -> ["tcl"]
  95. - Textile -> ["textile"]
  96. - XML -> ["xml", "xsd", "xslt", "tld", "dtml", "rss", "opml", "svg"]
  97. - YAML -> ["yaml", "yml", "sublime-syntax"]
  98. - SWI-Prolog -> ["pro"]
  99. - Reason -> ["re", "rei"]
  100. - CMake C Header -> ["h.in"]
  101. - CMake C++ Header -> ["hh.in", "hpp.in", "hxx.in", "h++.in"]
  102. - CMake -> ["CMakeLists.txt", "cmake"]
  103. - CMakeCache -> ["CMakeCache.txt"]
  104. - Generic Config -> ["cfg", "conf", "config", "ini", "pro", "mak", "mk", "Doxyfile", "inputrc", ".inputrc", "dircolors", ".dircolors", "gitmodules", ".gitmodules", "gitignore", ".gitignore", "gitattributes", ".gitattributes"]
  105. - Elm -> ["elm"]
  106. - Linker Script -> ["ld"]
  107. - TOML -> ["toml", "tml"]
  108. - TypeScript -> ["ts"]
  109. - TypeScriptReact -> ["tsx"]
  110. - VimL -> ["vim"]
  111. - TOML -> ["toml", "tml", "Cargo.lock", "Gopkg.lock"]
  112. ```
  113. If you want to highlight a language not on that list, please open an issue or a pull request on the [Gutenberg repo](https://github.com/Keats/gutenberg).
  114. Alternatively, the `extra_syntaxes` config option can be used to add additional syntax files.
  115. If your site source is laid out as follows:
  116. ```
  117. .
  118. ├── config.toml
  119. ├── content/
  120. │   └── ...
  121. ├── static/
  122. │   └── ...
  123. ├── syntaxes/
  124. │   ├── Sublime-Language1/
  125. │   │   └── lang1.sublime-syntax
  126. │   └── lang2.sublime-syntax
  127. └── templates/
  128. └── ...
  129. ```
  130. you would set your `extra_syntaxes` to `["syntaxes", "syntaxes/Sublime-Language1"]` in order to load `lang1.sublime-syntax` and `lang2.sublime-syntax`.