Skip to content

Markdown ที่เราสามารถเขียนได้ใน .md

Header Anchors

markdown
# Using custom anchors {#my-anchor}

TODO header anchors

ตัวอย่างโค้ด
markdown
[ลิงค์ไปหน้าหน้าอื่นๆใน vitepress](/courses/vitepress/writing/asset-handling)
ตัวอย่างโค้ด
markdown
[ลิงค์ไปยังลิงค์ด้านนอก](https://www.youtube.com/watch?v=techmgGVOhk)

Frontmatter

กำหนดไว้ที่ด้านบนสุดท้าย .md

markdown
---
title: Blogging Like a Hacker
lang: en-US
---

Usage

markdown
{{ $frontmatter.title }}

Output

Blogging Like a Hacker

Tables

TablesAreCool
col 3 isright-aligned$1600
col 2 iscentered$12
zebra stripesare neat$1
ตัวอย่างโค้ด
markdown
| Tables        |      Are      |  Cool |
| ------------- | :-----------: | ----: |
| col 3 is      | right-aligned | $1600 |
| col 2 is      |   centered    |   $12 |
| zebra stripes |   are neat    |    $1 |

Emoji

🎉 💯

ตัวอย่างโค้ด
markdown
:tada: :100:

🧳🌂☂️🧵🪡🪢🪭🧶👓🕶🥽🥼🦺👔👕👖🧣🧤🧥

ตัวอย่างโค้ด
markdown
🧳🌂☂️🧵🪡🪢🪭🧶👓🕶🥽🥼🦺👔👕👖🧣🧤🧥

Table of Contents

ตัวอย่างโค้ด
markdown
[[toc]]

Custom Containers

GitHub-flavored Alerts

NOTE

Highlights information that users should take into account, even when skimming.

TIP

Optional information to help a user be more successful.

IMPORTANT

Crucial information necessary for users to succeed.

WARNING

Critical content demanding immediate user attention due to potential risks.

CAUTION

Negative potential consequences of an action.

ตัวอย่างโค้ด
markdown
> [!NOTE]
> Highlights information that users should take into account, even when skimming.

> [!TIP]
> Optional information to help a user be more successful.

> [!IMPORTANT]
> Crucial information necessary for users to succeed.

> [!WARNING]
> Critical content demanding immediate user attention due to potential risks.

> [!CAUTION]
> Negative potential consequences of an action.

Syntax Highlighting in Code Blocks

html
<ul> 
	<li v-for="todo in todos" :key="todo.id"> {{ todo.text }
	</li> 
</ul>
ตัวอย่างโค้ด
```html
<ul>
  <li v-for="todo in todos" :key="todo.id">
    {{ todo.text }}
  </li>
</ul>
```

Line Highlighting in Code Blocks

  • บรรทัดเดียว
js
export default { 
	data () { 
		return { 
			msg: 'Highlighted!' 
		} 
	} 
}
ตัวอย่างโค้ด
```js{4}
export default {
  data () {
    return {
      msg: 'Highlighted!'
    }
  }
}
```
  • หลายบรรทัด
js
export default { // Highlighted
  data () {
    return {
      msg: `Highlighted!
      This line isn't highlighted,
      but this and the next 2 are.`,
      motd: 'VitePress is awesome',
      lorem: 'ipsum'
    }
  }
}
ตัวอย่างโค้ด
```js{1,4,6-8}
export default { // Highlighted
  data () {
    return {
      msg: `Highlighted!
      This line isn't highlighted,
      but this and the next 2 are.`,
      motd: 'VitePress is awesome',
      lorem: 'ipsum'
    }
  }
}
```

Focus in Code Blocks

js
export default {
	data() {
		return {
			msg: "Focused!", 
		};
	},
};
ตัวอย่างโค้ด
```js
export default {
  data () {
    return {
      msg: 'Focused!'
    }
  }
}
```

Colored Diffs in Code Blocks

js
export default {
  data () {
    return {
      msg: 'Removed'
      msg: 'Added'
    }
  }
}
ตัวอย่างโค้ด
``js
export default {
  data () {
    return {
      msg: 'Removed'
      msg: 'Added'
    }
  }
}
```

Errors and Warnings in Code Blocks

js
export default {
	data() {
		return {
			msg: "Error", 
			msg: "Warning", 
		};
	},
};
ตัวอย่างโค้ด
``js
export default {
  data () {
    return {
      msg: 'Error',
      msg: 'Warning'
    }
  }
}
```

Line Numbers

สามารถตั้งค่า line number ที่ vitepress/config.mts ได้

ts
export default {
	data() {
		return {
			msg: "Highlighted!",
		};
	},
};
ts
// line-numbers is disabled by default
const line2 = "This is line 2";
const line3 = "This is line 3";
ts
// line-numbers is enabled
const line2 = 'This is line 2'
const line3 = 'This is line 3'
ts
// line-numbers is enabled and start from 2
const line3 = 'This is line 3'
const line4 = 'This is line 4'
ตัวอย่างโค้ด
```ts {1}
// line-numbers is disabled by default
const line2 = 'This is line 2'
const line3 = 'This is line 3'
```

```ts:line-numbers {1}
// line-numbers is enabled
const line2 = 'This is line 2'
const line3 = 'This is line 3'
```

```ts:line-numbers=2 {1}
// line-numbers is enabled and start from 2
const line3 = 'This is line 3'
const line4 = 'This is line 4'
```

Import Code Snippets

TODO import code snippet

ตัวอย่างโค้ด
markdown
[ลิงค์ไปยังลิงค์ด้านนอก](https://www.youtube.com/watch?v=techmgGVOhk)

Code Groups

js
/**
 * @type {import('vitepress').UserConfig}
 */
const config = {
	// ...
};

export default config;
ts
import type { UserConfig } from "vitepress";

const config: UserConfig = {
	// ...
};

export default config;

TODO codegroup

ตัวอย่างโค้ด

Markdown File Inclusion

นำเข้า Markdown จากไฟล์อื่นเข้ามาได้ เช่นจากตัวอย่าง เรานำเข้า frontmatter.md เข้ามาไฟล์ไฟล์ markdown-extensions.md

นำเข้าทั้งไฟล์

Input

markdown
Hello

<!--@include: ./color-list.md-->
markdown
- black
- orange
- pink
- blue

Output

Hello

  • black
  • orange
  • pink
  • blue

นำเข้าเฉพาะบรรทัดที่กำหนด

Input

markdown
Hello

<!--@include: ./color-list.md{2,}-->
markdown
- black
- orange
- pink
- blue

Output

Hello

  • orange
  • pink
  • blue

Math Equations

When a0, there are two solutions to (ax2+bx+c=0) and they are

x=b±b24ac2a

Maxwell's equations:

equationdescription
B=0divergence of B is zero
×E+1cBt=0curl of E is proportional to the rate of change of B
×B1cEt=4πcjE=4πρwha?
ตัวอย่างโค้ด
When $a \ne 0$, there are two solutions to $(ax^2 + bx + c = 0)$ and they are
$$ x = {-b \pm \sqrt{b^2-4ac} \over 2a} $$

**Maxwell's equations:**

| equation                                                                                                                                                                  | description                                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| $\nabla \cdot \vec{\mathbf{B}}  = 0$                                                                                                                                      | divergence of $\vec{\mathbf{B}}$ is zero                                               |
| $\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t}  = \vec{\mathbf{0}}$                                                          | curl of $\vec{\mathbf{E}}$ is proportional to the rate of change of $\vec{\mathbf{B}}$ |
| $\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} = \frac{4\pi}{c}\vec{\mathbf{j}}    \nabla \cdot \vec{\mathbf{E}} = 4 \pi \rho$ | _wha?_                                                                                 |

config.mjs, config.mts

Image Lazy Loading

js
export default {
	markdown: {
		image: {
			// image lazy loading is disabled by default
			lazyLoading: true,
		},
	},
};

Advanced Configuration

js
import markdownItAnchor from "markdown-it-anchor";
import markdownItFoo from "markdown-it-foo";
import { defineConfig } from "vitepress";

export default defineConfig({
	markdown: {
		// options for markdown-it-anchor
		// https://github.com/valeriangalliat/markdown-it-anchor#usage
		anchor: {
			permalink: markdownItAnchor.permalink.headerLink(),
		},

		// options for @mdit-vue/plugin-toc
		// https://github.com/mdit-vue/mdit-vue/tree/main/packages/plugin-toc#options
		toc: { level: [1, 2] },

		config: (md) => {
			// use more markdown-it plugins!
			md.use(markdownItFoo);
		},
	},
});

Released under the MIT License