คู่มือไวยากรณ์ Markdown

ไวยากรณ์สำคัญสำหรับจัดรูปแบบเอกสาร

ภาพรวม

Markdown เป็น markup language เบาที่ใช้เพิ่มองค์ประกอบการจัดรูปแบบในเอกสารข้อความธรรมดา John Gruber สร้างเมื่อปี 2004 ปัจจุบันเป็นหนึ่งใน markup language ที่นิยมที่สุดในโลก

การใช้ Markdown ต่างจาก WYSIWYG อย่าง Word ที่คุณกดปุ่มจัดรูปแบบแล้วเห็นทันที ใน Markdown คุณใส่ไวยากรณ์ลงข้อความเพื่อบอกว่าคำหรือวลีไหนจะแสดงต่างออกไป

หัวข้อ

ใส่ # ข้างหน้าคำหรือวลี จำนวน # เทียบกับระดับหัวข้อ เช่น ### หัวข้อของฉัน = ระดับ 3

Markdown
HTML
ผลที่แสดง
# Heading level 1
<h1>Heading level 1</h1>

Heading level 1

## Heading level 2
<h2>Heading level 2</h2>

Heading level 2

### Heading level 3
<h3>Heading level 3</h3>

Heading level 3

#### Heading level 4
<h4>Heading level 4</h4>

Heading level 4

##### Heading level 5
<h5>Heading level 5</h5>
Heading level 5
###### Heading level 6
<h6>Heading level 6</h6>
Heading level 6

ย่อหน้า

สร้างย่อหน้าโดยเว้นบรรทัดว่างคั่นระหว่างบรรทัดข้อความ

Markdown
HTML
ผลที่แสดง
I really like using Markdown.

It lets me write easily.
<p>I really like using Markdown.</p>
<p>It lets me write easily.</p>

I really like using Markdown.

It lets me write easily.

ขึ้นบรรทัดใหม่

จบบรรทัดด้วยช่องว่างสองตัวขึ้นไป แล้วกด Enter

Markdown
HTML
ผลที่แสดง
This is the first line.
And this is the second line.
<p>This is the first line.<br>
And this is the second line.</p>

This is the first line.
And this is the second line.

เน้นข้อความ

เน้นได้ด้วยตัวหนาหรือตัวเอียง

ตัวหนา

ใส่ ** หรือ __ ก่อนและหลังคำหรือวลี

Markdown
HTML
ผลที่แสดง
I just love **bold text**.
I just love <strong>bold text</strong>.

I just love bold text.

I just love __bold text__.
I just love <strong>bold text</strong>.

I just love bold text.

ตัวเอียง

ใส่ * หรือ _ ก่อนและหลังคำหรือวลี

Markdown
HTML
ผลที่แสดง
The *cat* meows.
The <em>cat</em> meows.

The cat meows.

The _cat_ meows.
The <em>cat</em> meows.

The cat meows.

ตัวหนาและเอียง

ใส่ *** หรือ ___ ก่อนและหลังคำหรือวลี

Markdown
HTML
ผลที่แสดง
This text is ***really important***.
This text is <strong><em>really important</em></strong>.

This text is really important.

This text is ___really important___.
This text is <strong><em>really important</em></strong>.

This text is really important.

อ้างอิง

ใส่ > ข้างหน้าย่อหน้า

Markdown
HTML
ผลที่แสดง
> Dorothy followed her through many of the beautiful rooms in her castle.
<blockquote><p>Dorothy followed her through many of the beautiful rooms in her castle.</p></blockquote>

Dorothy followed her through many of the beautiful rooms in her castle.

อ้างอิงซ้อน

ใส่ >> ข้างหน้าบรรทัดที่ต้องการซ้อน

Markdown
ผลที่แสดง
> Dorothy followed her through many of the beautiful rooms in her castle.
>
>> The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.

Dorothy followed her through many of the beautiful rooms in her castle.

The Witch bade her clean the pots and kettles and sweep the floor and keep the fire fed with wood.

รายการ

จัดเป็นรายการมีเลขหรือไม่มีเลขได้

รายการมีเลข

ใส่เลขตามด้วยจุดข้างหน้า แต่ละบรรทัด เลขไม่ต้องเรียง แต่ควรเริ่มที่ 1

Markdown
HTML
ผลที่แสดง
1. First item
2. Second item
3. Third item
4. Fourth item
<ol>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
  <li>Fourth item</li>
</ol>
  1. First item
  2. Second item
  3. Third item
  4. Fourth item

รายการไม่มีเลข

ใส่ - หรือ * หรือ + ข้างหน้าบรรทัด

Markdown
HTML
ผลที่แสดง
- First item
- Second item
- Third item
- Fourth item
<ul>
  <li>First item</li>
  <li>Second item</li>
  <li>Third item</li>
  <li>Fourth item</li>
</ul>
  • First item
  • Second item
  • Third item
  • Fourth item

โค้ด

ใส่คำหรือวลีใน backtick `

Markdown
HTML
ผลที่แสดง
At the command prompt, type `nano`.
At the command prompt, type <code>nano</code>.

At the command prompt, type nano.

บล็อกโค้ด

เยื้องอย่างน้อย 4 ช่องหรือ 1 tab ทุกบรรทัด หรือใช้ ``` ก่อนและหลังบล็อก

Markdown
ผลที่แสดง
```
{
  "firstName": "John",
  "lastName": "Smith",
  "age": 25
}
```
{
  "firstName": "John",
  "lastName": "Smith",
  "age": 25
}

เส้นแนวนอน

ใช้ *** หรือ --- หรือ ___ คนเดียวทั้งบรรทัด

Markdown
HTML
ผลที่แสดง
***
<hr>

---
<hr>

___
<hr>

รูปภาพ

ใส่ ! ตามด้วย [alt] แล้ว (url รูป) จะเพิ่มชื่อใน " " หลัง URL ก็ได้

Markdown
HTML
ผลที่แสดง
![The San Juan Mountains](https://mdg.imgix.net/assets/images/san-juan-mountains.jpg "San Juan Mountains")
<img src="https://mdg.imgix.net/assets/images/san-juan-mountains.jpg" alt="The San Juan Mountains" title="San Juan Mountains">
The San Juan Mountains

การ escape อักขระ

ใส่ \ ข้างหน้าอักขระที่จะใช้จัดรูปแบบ ถ้าต้องการให้แสดงตรงตัว

Markdown
ผลที่แสดง
\* Without the backslash, this would be a bullet in an unordered list.

* Without the backslash, this would be a bullet in an unordered list.

อักขระที่ escape ได้

ใช้ backslash escape อักขระเหล่านี้:

\backslash
`backtick
*asterisk
_underscore
{ }curly braces
[ ]brackets
( )parentheses
#pound sign
+plus sign
-minus sign (hyphen)
.dot
!exclamation mark
|pipe

ตาราง

ใช้ --- สร้างหัวคอลัมน์ และ | คั่นคอลัมน์ จะใส่ | ขอบตารางก็ได้

Markdown
ผลที่แสดง
| Syntax    | Description |
| --------- | ----------- |
| Header    | Title       |
| Paragraph | Text        |
SyntaxDescription
HeaderTitle
ParagraphText

การจัดแนว

ใส่ : ทางซ้าย ขวา หรือทั้งสองข้างของ --- ในแถวหัวเพื่อจัดแนวคอลัมน์

Markdown
ผลที่แสดง
| Align Left | Align Center | Align Right |
| :--- | :---: | ---: |
| This | This | This |
| column | column | column |
| will | will | will |
| align | align | align |
| left | center | right |
ชิดซ้ายกึ่งกลางชิดขวา
ThisThisThis
columncolumncolumn
willwillwill
alignalignalign
leftcenterright