只需使用 三重反引號(```)括住 Mermaid 語句,即可讓文件呈現圖表、具備視覺化效果。
```mermaid
%%Mermaid code### 繪製流程圖
生成一個從左到右排列、A 指向 B、B 指向 C、C 指向的流程圖。
```mermaid
graph LR;
A-->B;
B-->C;
C-->D;
graph LR;
A-->B;
B-->C;
C-->D;如果想要增加連結的標籤,可以使用 |文字| 來註解。
graph LR;
A-->|連結1|B;
B-->|連結2|C;
C-->|連結3|D;
graph LR;
A-->|連結1|B;
B-->|連結2|C;
C-->|連結3|D;可以使用 style 設定節點的樣式,圖表可以包含:
("文字")代表橢圓形{"文字"}代表菱形["文字"]代表矩形
graph LR;
style A fill:#f9f,stroke:#333,stroke-width:2px;
style B fill:#ff0,stroke:#333,stroke-width:2px;
A("開始") --> B{"條件判斷"};
B -->|是| C["執行動作"];
B -->|否| D[結束];
graph LR;
style A fill:#f9f,stroke:#333,stroke-width:2px;
style B fill:#ff0,stroke:#333,stroke-width:2px;
A("開始") --> B{"條件判斷"};
B -->|是| C["執行動作"];
B -->|否| D[結束];使用 graph LR;(由左到右)、或 graph TD;(由上到下)來繪製流程圖。
flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]sequenceDiagram
Alice->>+John: Hello John, how are you?
Alice->>+John: John, can you hear me?
John-->>-Alice: Hi Alice, I can hear you!
John-->>-Alice: I feel great!
sequenceDiagram
Alice->>+John: Hello John, how are you?
Alice->>+John: John, can you hear me?
John-->>-Alice: Hi Alice, I can hear you!
John-->>-Alice: I feel great!gantt
title A Gantt Diagram
dateFormat YYYY-MM-DD
section Section
A task :a1, 2014-01-01, 30d
Another task :after a1 , 20d
section Another
Task in sec :2014-01-12 , 12d
another task : 24d
gantt
title A Gantt Diagram
dateFormat YYYY-MM-DD
section Section
A task :a1, 2014-01-01, 30d
Another task :after a1 , 20d
section Another
Task in sec :2014-01-12 , 12d
another task : 24dclassDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}stateDiagram
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]pie title Pets adopted by volunteers
"Dogs" : 386
"Cats" : 85
"Rats" : 15
pie title Pets adopted by volunteers
"Dogs" : 386
"Cats" : 85
"Rats" : 15erDiagram
CUSTOMER }|..|{ DELIVERY-ADDRESS : has
CUSTOMER ||--o{ ORDER : places
CUSTOMER ||--o{ INVOICE : "liable for"
DELIVERY-ADDRESS ||--o{ ORDER : receives
INVOICE ||--|{ ORDER : covers
ORDER ||--|{ ORDER-ITEM : includes
PRODUCT-CATEGORY ||--|{ PRODUCT : contains
PRODUCT ||--o{ ORDER-ITEM : "ordered in"
erDiagram
CUSTOMER }|..|{ DELIVERY-ADDRESS : has
CUSTOMER ||--o{ ORDER : places
CUSTOMER ||--o{ INVOICE : "liable for"
DELIVERY-ADDRESS ||--o{ ORDER : receives
INVOICE ||--|{ ORDER : covers
ORDER ||--|{ ORDER-ITEM : includes
PRODUCT-CATEGORY ||--|{ PRODUCT : contains
PRODUCT ||--o{ ORDER-ITEM : "ordered in"graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
sequenceDiagram
participant Alice
participant Bob
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Some note
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
gantt
dateFormat YYYY-MM-DD
title Adding GANTT diagram to mermaid
excludes weekdays 2014-01-10
section A section
Completed task :done, des1, 2014-01-06,2014-01-08
Active task :active, des2, 2014-01-09, 3d
Future task : des3, after des2, 5d
Future task2 : des4, after des3, 5d
classDiagram
Class01 <|-- AveryLongClass : Cool
Class03 *-- Class04
Class05 o-- Class06
Class07 .. Class08
Class09 --> C2 : Where am i?
Class09 --* C3
Class09 --|> Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
Class08 <--> C2: Cool label
flowchart LR
A{藍芽連線}
B{#91;*IDN?#93;<br>與 Inverter 連線}
C{#91;暫時停止判斷#93;<br>P1_2 == 0<br>&<br>P3_5 == 0}
D[至設定畫面頁<br>暫時停止按鈕顯示於ON位置]
E{#91;退出暫時停止#93;<br>設定 P_3 = 1}
F[Do anything]
G[異常停止]
H[正常<br>開始輪詢]
%%N[fa:fa-car Car]
%%J(Go shopping)
%% 使用圓角矩形
%%P[inverter連線]
%%H[Crash]
%% style P fill:#f9c2ff,stroke:#333,stroke-width:2px;
A --> |OK|B
A --> |NG|G
B --> |NG| C
B --> |OK| H
C --> |Yes|D
C --> |No|G
D --> E
E --> |Yes|B
E --> |No|F
F --> |至設定畫面頁|D
F --> F
flowchart LR
B((輸出))
C{P1_2 == 0}
D["#91;外部供電#93;<br>OUTOFF = 1<br>P1_3 = 0"]
E["#91;未供電#93;<br>OUTOFF = 1"]
F(停止輸出)
B-->|暫時停止| C
C-->|Yes| D
C-->|No| E
D-->F
E-->F
G(停止輸出)
H{P1_2 == 0}
I["#91;外部供電#93;<br>OUTOFF = 0<br>P1_3 = 1"]
J["#91;未供電#93;<br>OUTOFF = 0"]
K(輸出)
G-->|恢復輸出| H
H-->|Yes| I
H-->|No| J
I-->K
J-->K
===
Follow this Hello World exercise to learn GitHub's pull request workflow.
This tutorial teaches you GitHub essentials like repositories, branches, commits, and pull requests. You'll create your own Hello World repository and learn GitHub's pull request workflow, a popular way to create and review code. In this quickstart guide, you will:
-
Create and use a repository.
-
Start and manage a new branch.
-
Make changes to a file and push them to GitHub as commits.
-
Open and merge a pull request.
-
You must have a GitHub account. For more information, see Creating an account on GitHub.
-
You don't need to know how to code, use the command line, or install Git (the version control software that GitHub is built on).
The first thing we'll do is create a repository. You can think of a repository as a folder that contains related items, such as files, images, videos, or even other folders. A repository usually groups together items that belong to the same "project" or thing you're working on. Often, repositories include a README file, a file with information about your project. README files are written in Markdown, which is an easy-to-read, easy-to-write language for formatting plain text. We'll learn more about Markdown in the next tutorial, Setting up your profile. GitHub lets you add a README file at the same time you create your new repository. GitHub also offers other common options such as a license file, but you do not have to select any of them now. Your
hello-worldrepository can be a place where you store ideas, resources, or even share and discuss things with others.
-
In the upper-right corner of any page, select , then click New repository.

-
In the "Repository name" box, type
hello-world. -
In the "Description" box, type a short description. For example, type "This repository is for practicing the GitHub Flow."
-
Select whether your repository will be Public or Private.
-
Select Add a README file.
-
Click Create repository.
Branching lets you have different versions of a repository at one time. By default, your repository has one branch named
mainthat is considered to be the definitive branch. You can create additional branches off ofmainin your repository. Branching is helpful when you want to add new features to a project without changing the main source of code. The work done on different branches will not show up on the main branch until you merge it, which we will cover later in this guide. You can use branches to experiment and make edits before committing them tomain. When you create a branch off themainbranch, you're making a copy, or snapshot, ofmainas it was at that point in time. If someone else made changes to themainbranch while you were working on your branch, you could pull in those updates. This diagram shows:
-
The
mainbranch -
A new branch called
feature -
The journey that
featuretakes through stages for "Commit changes," "Submit pull request," and "Discuss proposed changes" before it's merged intomain
-
Click the Code tab of your
hello-worldrepository. -
Above the file list, click the dropdown menu that says main.

-
Type a branch name,
readme-edits, into the text box. -
Click Create branch: readme-edits from main.
Now you have two branches, mainandreadme-edits. Right now, they look exactly the same. Next you'll add changes to the newreadme-editsbranch.When you created a new branch in the previous step, GitHub brought you to the code page for your new
readme-editsbranch, which is a copy ofmain. You can make and save changes to the files in your repository. On GitHub, saved changes are called commits. Each commit has an associated commit message, which is a description explaining why a particular change was made. Commit messages capture the history of your changes so that other contributors can understand what you’ve done and why. -
Under the
readme-editsbranch you created, click theREADME.mdfile. -
To edit the file, click .
-
In the editor, write a bit about yourself.
-
Click Commit changes.
-
In the "Commit changes" box, write a commit message that describes your changes.
-
Click Commit changes. These changes will be made only to the README file on your
readme-editsbranch, so now this branch contains content that's different frommain.Now that you have changes in a branch off of
main, you can open a pull request. Pull requests are the heart of collaboration on GitHub. When you open a pull request, you're proposing your changes and requesting that someone review and pull in your contribution and merge them into their branch. Pull requests show diffs, or differences, of the content from both branches. The changes, additions, and subtractions are shown in different colors. As soon as you make a commit, you can open a pull request and start a discussion, even before the code is finished. In this step, you'll open a pull request in your own repository and then merge it yourself. It's a great way to practice the GitHub flow before working on larger projects. -
Click the Pull requests tab of your
hello-worldrepository. -
Click New pull request.
-
In the Example Comparisons box, select the branch you made,
readme-edits, to compare withmain(the original). -
Look over your changes in the diffs on the Compare page, make sure they're what you want to submit.

-
Click Create pull request.
-
Give your pull request a title and write a brief description of your changes. You can include emojis and drag and drop images and gifs.
-
Click Create pull request.
When you start collaborating with others, this is the time you'd ask for their review. This allows your collaborators to comment on, or propose changes to, your pull request before you merge the changes into the
mainbranch. We won't cover reviewing pull requests in this tutorial, but if you're interested in learning more, see About pull request reviews. Alternatively, try the GitHub Skills "Reviewing pull requests" course.In this final step, you will merge your
readme-editsbranch into themainbranch. After you merge your pull request, the changes on yourreadme-editsbranch will be incorporated intomain. Sometimes, a pull request may introduce changes to code that conflict with the existing code onmain. If there are any conflicts, GitHub will alert you about the conflicting code and prevent merging until the conflicts are resolved. You can make a commit that resolves the conflicts or use comments in the pull request to discuss the conflicts with your team members. In this walk-through, you should not have any conflicts, so you are ready to merge your branch into the main branch. -
At the bottom of the pull request, click Merge pull request to merge the changes into
main. -
Click Confirm merge. You will receive a message that the request was successfully merged and the request was closed.
-
Click Delete branch. Now that your pull request is merged and your changes are on
main, you can safely delete thereadme-editsbranch. If you want to make more changes to your project, you can always create a new branch and repeat this process. -
Click back to the Code tab of your
hello-worldrepository to see your published changes onmain.By completing this tutorial, you've learned to create a project and make a pull request on GitHub. As part of that, we've learned how to:
-
Create a repository.
-
Start and manage a new branch.
-
Change a file and commit those changes to GitHub.
-
Open and merge a pull request.
-
Take a look at your GitHub profile and you'll see your work reflected on your contribution graph.
-
If you want to practice the skills you've learned in this tutorial again, try the GitHub Skills "Introduction to GitHub" course.
-
In the next tutorial, Setting up your profile, you'll learn how to personalize your profile and you'll also learn some basic Markdown syntax for writing on GitHub.