Markdown渲染示例

暂无信息

2024-11-01

27k 22 min ... / ...

1. 排版

粗体

斜体

删除线

引用:

Onion主题为大部分Markdown格式配置了样式

有序列表:

  1. 项目1
  2. 项目2
  3. 项目3

无序列表:

  • 项目1
  • 项目2
  • 项目3

嵌套列表:

  • 项目1
    • 项目1.1
    • 项目1.2
      1. 项目1.2.1
      2. 项目1.2.2
    • 项目1.3
  • 项目2
    1. 项目2.1
    2. 项目2.2
  • 项目3

2. 图片与链接

图片:

链接:

Onion主题Github仓库

3. 标题

Onion主题会将h1、h2标题统一渲染为h3标题并添加下边框,其余标题渲染为h5。

4. 代码

行内代码块实例:hello worldgit bash here

整块代码高亮示例(代码来自GPT4):

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

class Rectangle {
public:
    Rectangle(double w, double h) : width(w), height(h) {}
    double area() { return width * height; }
    double perimeter() { return 2 * (width + height); }

private:
    double width, height;
};

int main() {
    cout << "C++ Syntax Test" << endl;

    vector<int> numbers = {1, 2, 3, 4, 5};
    for (int i : numbers) {
        cout << "Number: " << i << endl;
    }

    Rectangle rect(10.5, 20.3);
    cout << "Area: " << rect.area() << endl;
    cout << "Perimeter: " << rect.perimeter() << endl;

    return 0;
}
import math

class Circle:
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return math.pi * self.radius ** 2

    def perimeter(self):
        return 2 * math.pi * self.radius

if __name__ == "__main__":
    print("Python Syntax Test")
    
    numbers = [1, 2, 3, 4, 5]
    for num in numbers:
        print(f"Number: {num}")
    
    circle = Circle(10)
    print(f"Area: {circle.area()}")
    print(f"Perimeter: {circle.perimeter()}")
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HTML Syntax Test</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
        }
        h1 {
            color: #333;
        }
        .highlight {
            color: #0077cc;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <h1>HTML Syntax Test</h1>
    <p>Here is some text with <span class="highlight">highlighted text</span>.</p>
    <ul>
        <li>Item 1</li>
        <li>Item 2</li>
        <li>Item 3</li>
    </ul>
    <button onclick="alert('Button clicked!')">Click Me</button>
</body>
</html>
function greet(name) {
    return `Hello, ${name}!`;
}

const numbers = [10, 20, 30, 40, 50];

let sum = 0;
numbers.forEach(num => {
    sum += num;
    console.log(`Number: ${num}, Current Sum: ${sum}`);
});

const person = {
    name: "Alice",
    age: 25,
    greet: function() {
        console.log(greet(this.name));
    }
};

person.greet();

const factorial = (n) => {
    return (n === 0 || n === 1) ? 1 : n * factorial(n - 1);
};

console.log(`Factorial of 5: ${factorial(5)}`);

5. 表格

Item Value
Computer $1600
Phone $12
Pipe $1

可以指定对齐方式, 如Item列左对齐, Value列右对齐, Qty列居中对齐

Item Value Qty
Computer $1600 5
Phone $12 12
Pipe $1 234

6. Html 标签

支持在 Markdown 语法中嵌套 Html 标签,譬如,你可以用 Html 写一个纵跨两行的表格:

值班人员 星期一 星期二 星期三
李强 张明 王平

提示, 如果想对图片的宽度和高度进行控制, 你也可以通过img标签, 如:

7. 脚注

basic footnote[1]

here is an inline footnote[2]

and another one[3]

and another one[4]

8. LaTeX 公式

行内公式:

质能守恒方程可以用一个很简洁的方程式\(E=mc^2\)来表达。

整行公式:

\[ \frac{1}{2} + \frac{3}{4} = \frac{5}{4} \]

\[ \frac{d}{dx} \left( x^2 + 3x + 2 \right) = 2x + 3 \]

\[ lim_{x \to 0} \frac{\sin x}{x} = 1 \]

\[ A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \]

\[ \sin x = \sum_{n=0}^{\infty} (-1)^n \frac{x^{2n+1}}{(2n+1)!} \]


  1. [1]basic footnote content ↩︎
  2. [2]inline footnote ↩︎
  3. [3]paragraph footnote content ↩︎
  4. [4]footnote content with some markdown ↩︎