Code Blocks
There are several ways to add code blocks. Most of these functions and the dependent formatting rely on the .highlight
CSS class1. You must ensure that you always assign a language to your code blocks if you want to use these functions. If you do not want to apply syntax highlighting, you can also specify plain or text as the language.
Inline code
|
|
this is an example for inline code hello world
and link
Code block
Indented code block
A simple code block can be generated by indenting several lines of code by at least two spaces.
Keep in mind this method is not recommended.
Try fenced code block
!
|
|
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example HTML5 Document</title>
</head>
<body>
<p>Test</p>
</body>
</html>
Fenced code block
If you want to gain more control of your code block you can enclose your code by at least three backticks ```
a so called fence.
In GFM (GitHub Flavored Markdown) you can also add a language specifier directly after the opening fence, ```js
, and syntax highlighting will automatically be applied according to the selected language in the rendered HTML.
|
|
|
|
Code blocks can also be uses without language specification:
|
|
|
|
Highlight shortcode
Hugo has a build-in shortcode for syntax highlighting2 using Chroma, see Syntax Highlighting for additional documentation.
|
|
results are as followed:
|
|
Gist
Hugo also support Gist3 short code to support code reference using Github Gist[4]:
|
|
This is the result:
Github Code
Sometimes we want to refer github code directly without Gist, Hugo Cosmos supports that by leveraging EmbedGithub4.
|
|
This is the result:
Jupter Notebook
TODO
alipay