Markdown Syntax in Hexo
Writing a blog requires using Markdown, so it’s necessary to be familiar with its syntax rules. Although Markdown syntax is relatively simple, looking up each rule one by one can be quite tedious (the table of contents messed up due to the preview of headings…).
Common Markdown syntax rules are:
This post was translated from my Chinese blog post with the aid of ChatGpt.
- Headings (I moved the headings to the bottom of the webpage, which messed up the table of contents…)
- Bold and Italic Formatting
- Blockquotes
- Horizontal Rules
- Images
- Hyperlinks
- Lists
- Tables
- Code Blocks
- Small Text
- Escaping Special Characters
- Font Color and Size
- Text Alignment
- Checkboxes
- First-line Indentation
- Linking to Other Articles
- Text Background Color
- Tags
- Tabs
- Buttons
Bold and Italic Formatting
To italicize text, you need to add one *
on each side of the text.
To make text bold, you need to add two *
on each side of the text.
To make text both bold and italic, you need to add three *
on each side of the text.
To add strikethrough to text, you need to add two ~~
on each side of the text.
Markdown doesn’t support underlining directly, you can use the HTML <u>
tag to achieve it.
Example
1 | *Italicized text* |
Preview
Italicized text
Bold text
Bold and italicized textStrikethrough text
Underlined text
Blockquotes
To create a blockquote, you need to add a >
before the quoted text. Blockquotes can be nested, for example using two >>
or three >>>
.
Example
1 | > Quoted text |
Preview
Quoted text
Nested quoted text
Further nested text
Horizontal Rule
Horizontal rules are created by using three or more consecutive *
or -
characters. Leave a blank line before and after when there are paragraphs.
Example
1 | *** |
Preview
Hyperlinks
Syntax
1 | [Link Text](URL) |
Example
1 | [GitHub](https://github.com) |
Preview
Deprecated Old Syntax
Regular Link Syntax
Syntax
1 | [Link Text](URL Link Title) |
Link Title
is optional and will be displayed when hovering over the link.
Example
1 | [GitHub](https://github.com GitHub) |
Preview
[GitHub](https://github.com GitHub)
Advanced Link Syntax
Example
1 | Using 1 as a variable [GitHub][1] |
Preview
Using 1 as a variable [GitHub][1]
Assign 1 at the end
[1]:https://github.com
Lists
There are ordered lists and unordered lists. Both can be nested by adding a Tab
or three spaces before the next list item.
For ordered lists, you can use the symbols *
, +
, or -
.
Example
1 | - C |
Preview
- C
- C++
- Java
- Nested 1
- Nested 2
- Nested 3
- Nested 2
C
C++
Java
Nested 1
- Nested 2
- Nested 2 (1)
- Nested 2 (2)
- Nested 3
- Nested 3 (1)
- Nested 2 (3)
Nested 1 (1)
Tables
Example
1 | Header 1 | Header 2 | Header 3 |
In the second row, alignment is specified:
- Default is left-aligned, represented by
-
- Center-aligned is
:-:
- Right-aligned is
-:
Preview
Header 1 | Header 2 | Header 3 |
---|---|---|
Content 1 | Content 2 | Content 3 |
Content 4 | Content 5 | Content 6 |
Code
Code is enclosed with backticks ` (located on the keyboard left of the 1
key, not the right side quotes). Triple backticks can create code blocks. If you want to nest code blocks, the outer code block should have three more backticks than the inner one, and so on. The characters following the triple backticks indicate the language type. The example below includes additional brackets for demonstration purposes.
Basic Syntax
Example
1 | [```cpp] |
Preview
1 |
|
Advanced Syntax
Note that the link and link text must exist simultaneously, and the link format should be correct. Otherwise, they will be treated as headers.
Example
1 | ```[language] [title] [link] [link text] |
Preview
1 |
|
Code Block Language Specification
Hexo uses highlight.js for code highlighting by default. Below are commonly used language styles. For more styles, please visit the official website. The text following the triple backticks indicates the language format.
Language | Format |
---|---|
Bash | bash, sh, zsh |
C# | csharp, cs |
C | c,h |
C++ | cpp, hpp, cc, hh, c++, h++, cxx, hxx |
CSS | css |
Django | django, jinja |
DOS | dos, bat, cmd |
Excel | excel, xls, xlsx |
Go | go, golang |
HTML | xml, html, xhtml, rss, atom, xjb, xsd, xsl, plist, svg |
ini | ini |
JSON | json |
Java | java, jsp |
JavaScript | javascript, js, jsx |
LaTeX | tex |
Matlab | matlab |
Markdown | markdown, md, mkdown, mkd |
Makefile | makefile, mk, mak, make |
Nginx | nginx, nginxconf |
Objective-C | objectivec, mm, objc, obj-c, obj-c++, objective-c++ |
PHP | php |
PostgreSQL & PL/pgSQL | pgsql, postgres, postgresql |
PowerShell | powershell, ps, ps1 |
Processing | processing |
Python | python, py, gyp |
R | r |
Ruby | ruby, rb, gemspec, podspec, thor, irb |
SQL | sql |
Shell | shell, console |
Stylus | stylus, styl |
Swift | swift |
TypeScript | typescript, ts |
VBScript | vbscript, vbs, vb |
VB.Net | vbnet |
Vim Script | vim |
x86 Assembly | x86asm |
YAML | yml, yaml |
Small Text
To create small text, add <small>
at the beginning and </small>
at the end of the text.
Example<small>Small Text</small>
Preview
Small Text
Escaping Characters
When using special symbols (such as #
), you need to add a backslash \
before the symbol to escape it. Otherwise, the symbol won’t display properly.
Example
1 | \# |
Preview
#
*
!
+
-
Special Character Escapes
Some special characters require using escape sequences. Below is a reference table. Not all situations require escapes, this is for reference only.
Special Character | Escape | Chinese Name | English Name |
---|---|---|---|
“!” | ! | 感叹号 | Exclamation mark |
" | " " | 双引号 | Quotation mark |
# | # | 数字标志 | Number sign |
$ | $ | 美元标志 | Dollar sign |
% | % | 百分号 | Percent sign |
& | & & | 与 | Ampersand |
' | ' | 单引号 | Apostrophe |
( | ( | 小括号左边部分 | Left parenthesis |
) | ) | 小括号右边部分 | Right parenthesis |
* | * | 星号 | Asterisk |
+ | + | 加号 | Plus sign |
< | < < | 小于号 | Less than |
= | = | 等于符号 | Equals sign |
- | - − | 减号 | Minus |
> | > > | 大于号 | Greater than |
? | ? | 问号 | Question mark |
@ | @ | 艾特 | Commercial at |
[ | [ | 中括号左边部分 | Left square bracket |
\ | \ | 反斜杠 | Reverse solidus (backslash) |
] | ] | — 中括号右边部分 | Right square bracket |
{ | { | 大括号左边部分 | Left curly brace |
| | | | 竖线 | Vertical bar |
} | } | 大括号右边部分 | Right curly brace |
  | 空格 | Space |
Font Color and Size
- Hexo only supports black font color, but you can use HTML to adjust the color. Use
<font color="ff0000">
and</font>
to wrap the text you want to change color for. Replaceff0000
with other color codes. - Font size can also be adjusted using HTML. Use
<font size=12>
and</font>
to wrap the text you want to resize.font size=
is followed by the desired font size. - Font style can also be adjusted using HTML. Use
<font face="FontName">
and</font>
to wrap the text you want to change the font for.font face=
is followed by the desired font name. - Color, font size, and font style can be combined.
Example
1 | <font color="ff0000">Red Text</font> |
Preview
Red Text
Size 2 Text
Huawen Caiyun Font
Size 2 Red Huawen Caiyun Font
Centering Text
Centering text can also be achieved using HTML tags.
Example
1 | <center>This is centered text</center> |
Deprecated Methods
Example
1 | {% centerquote %}This is centered text{% endcenterquote %} |
Preview
This is centered text
This is centered text
This is centered text
Checkbox
A checkbox-like feature, similar to a todo list. Note that these checkboxes are for display purposes only and cannot be interacted with.
Example
1 | - [ ] This is an unchecked checkbox |
Preview
- This is an unchecked checkbox
- This is a checked checkbox
Deprecated Indentation
Indentation (Deprecated)
Hexo ignores indented spaces, so you need to use escapes for first-line indentation.
Example
1 |   This text is indented |
Preview
This text is indented
Linking to Other Articles
Hexo supports linking to other articles using the syntax {% post_path slug %}
and {% post_link slug [title] %}
, where slug
is the filename of the Markdown file you want to link to, and title
is the title of the linked article.
1 | {% post_link hexo-guide [Hexo Blog Guide to Avoiding Pitfalls] %} |
Preview
[Hexo Blog Guide to Avoiding Pitfalls]Text Background Color
Setting the background color for text requires using HTML tables. Use the bgcolor
attribute followed by the color’s English name.
Example
1 | <table><tr><td bgcolor=lightblue>亮蓝色背景色</td></tr></table> |
Preview
亮蓝色背景色 |
Note Tag
Configuration
You need to choose a style for the Note tag in the Next theme configuration. Open the _config.next.yml
file and search for Note tag (bs-callout)
. Below is my configuration. There are four available style
options, and you can preview them here. The icon
option is used to determine whether to display an icon. The titles within the Note tag will also appear in the table of contents.
1 | # Note tag (bootstrap callout) |
Usage
1 | {% note [class] [no-icon] [summary] %} |
[class]
: An optional parameter that controls the style of the Note. There are six options:- default
- primary
- success
- info
- warning
- danger.
[no-icon]
: An optional parameter. When enabled, the Note’s icon will not be displayed.[summary]
: An optional parameter. Serves as a summary or overview of the Note’s content. When enabled, the remaining content will be collapsed.
Examples
1 | {% note %} |
1 | {% note default %} |
1 | {% note info no-icon %} |
1 | {% note info Style with Summary %} |
Old Method (Not Recommended)
Old Method (Not Recommended)
Wrap the content to be displayed with <div>
. Use the class
attribute to specify the note’s style. Adding no-icon
will hide the icon.
Example
1 | <div class="note default"><p>default</p></div> |
Preview
default
primary
success
info
warning
danger
Label标签
Adjust the label’s style before the @
, and input the content to be displayed after the @
.
Example
1 | {% label default@This is default %} |
Preview
This is default This is primary This is success This is info This is warning This is dangerTab tag - Options Tab
Configuration
Search for Tabs tag
in the Next theme files, and set enable
to true
. Below is my configuration:
1 | # Tabs tag |
Usage
There are many customization options available.
Example
1 | {% tabs First unique name %} |
Preview
This is Tab 1.
This is Tab 2.
This is Tab 3.
Example
The number 3 in the first line indicates the default tab to display. Setting it to -1 means no default tab will be displayed.
1 | {% tabs Second unique name, 3 %} |
Preview
This is Tab 1.
This is Tab 2.
This is Tab 3.
Example
The names and icons of the options can be customized. Adjust them in <!-- tab Custom Name@Custom Icon -->
.
1 | {% tabs Third unique name %} |
Preview
This is Tab 1.
This is Tab 2.
This is Tab 3.
Buttons
Example
Use button
or btn
, followed by the link you want to navigate to. If no link is provided, it defaults to the current page.
1 | // Display text only, where Text is the content of the button |
Preview
Display text only:
Multiple buttons side by side:
Home Text & TitleDisplay icon only:
Display text and icon:
Text & Icon (buggy) Text & Icon (fixed width)
Link Grid
Can be used individually or combined to create a grid of links.
Example
1 | {% linkgrid %} |
1 | {% linkgrid %} |
Inserting Music/Videos
Due to the limited space provided by GitHub Pages, it’s recommended to upload music and videos to platforms like Bilibili (B站) or YouTube and then embed them using HTML language. Simply copy the sharing link provided by the platform. You can use the width
attribute to set the width and the height
attribute to set the height.
<video>
tag
Use source src
to set video link
Example
1 | <video width="480" height="320" controls> |
Preview(Without a real video)