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.8KB

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