-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathexamples_test.go
More file actions
171 lines (160 loc) · 4.36 KB
/
examples_test.go
File metadata and controls
171 lines (160 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//go:build linux || darwin
package markdown_test
import (
"os"
md "github.com/nao1215/markdown"
"github.com/nao1215/markdown/mermaid/sequence"
)
// ExampleMarkdown skips this test on Windows.
// The newline codes in the comment section where
// the expected values are written are represented as '\n',
// causing failures when testing on Windows.
func ExampleMarkdown() {
_ = md.NewMarkdown(os.Stdout).
H1("This is H1").
PlainText("This is plain text").
H2f("This is %s with text format", "H2").
PlainTextf("Text formatting, such as %s and %s, %s styles.",
md.Bold("bold"), md.Italic("italic"), md.Code("code")).
H2("Code Block").
CodeBlocks(md.SyntaxHighlightGo,
`package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}`).
H2("List").
BulletList("Bullet Item 1", "Bullet Item 2", "Bullet Item 3").
OrderedList("Ordered Item 1", "Ordered Item 2", "Ordered Item 3").
H2("CheckBox").
CheckBox([]md.CheckBoxSet{
{Checked: false, Text: md.Code("sample code")},
{Checked: true, Text: md.Link("Go", "https://golang.org")},
{Checked: false, Text: md.Strikethrough("strikethrough")},
}).
H2("Blockquote").
Blockquote("If you can dream it, you can do it.").
H3("Horizontal Rule").
HorizontalRule().
H2("Table").
Table(md.TableSet{
Header: []string{"Name", "Age", "Country"},
Rows: [][]string{
{"David", "23", "USA"},
{"John", "30", "UK"},
{"Bob", "25", "Canada"},
},
}).
H2("Image").
PlainTextf(md.Image("sample_image", "./sample.png")).
Build()
// Output:
// # This is H1
// This is plain text
// ## This is H2 with text format
// Text formatting, such as **bold** and *italic*, `code` styles.
// ## Code Block
// ```go
// package main
// import "fmt"
//
// func main() {
// fmt.Println("Hello, World!")
// }
// ```
// ## List
// - Bullet Item 1
// - Bullet Item 2
// - Bullet Item 3
// 1. Ordered Item 1
// 2. Ordered Item 2
// 3. Ordered Item 3
// ## CheckBox
// - [ ] `sample code`
// - [x] [Go](https://golang.org)
// - [ ] ~~strikethrough~~
// ## Blockquote
// > If you can dream it, you can do it.
// ### Horizontal Rule
// ---
// ## Table
// | Name | Age | Country |
// |---------|---------|---------|
// | David | 23 | USA |
// | John | 30 | UK |
// | Bob | 25 | Canada |
//
// ## Image
// 
}
// ExampleNewDiagram skips this test on Windows.
// The newline codes in the comment section where
// the expected values are written are represented as '\n',
// causing failures when testing on Windows.
func ExampleNewDiagram() {
diagram := sequence.NewDiagram(os.Stdout).
Participant("Sophia").
Participant("David").
Participant("Subaru").
LF().
SyncRequest("Sophia", "David", "Please wake up Subaru").
SyncResponse("David", "Sophia", "OK").
LF().
LoopStart("until Subaru wake up").
SyncRequest("David", "Subaru", "Wake up!").
SyncResponse("Subaru", "David", "zzz").
SyncRequest("David", "Subaru", "Hey!!!").
BreakStart("if Subaru wake up").
SyncResponse("Subaru", "David", "......").
BreakEnd().
LoopEnd().
LF().
SyncResponse("David", "Sophia", "wake up, wake up").
String()
_ = md.NewMarkdown(os.Stdout).
H2("Sequence Diagram").
CodeBlocks(md.SyntaxHighlightMermaid, diagram).
Build()
// Output:
// ## Sequence Diagram
// ```mermaid
// sequenceDiagram
// participant Sophia
// participant David
// participant Subaru
//
// Sophia->>David: Please wake up Subaru
// David-->>Sophia: OK
//
// loop until Subaru wake up
// David->>Subaru: Wake up!
// Subaru-->>David: zzz
// David->>Subaru: Hey!!!
// break if Subaru wake up
// Subaru-->>David: ......
// end
// end
//
// David-->>Sophia: wake up, wake up
// ```
}
// ExampleTableAlignment demonstrates table alignment features.
func ExampleTableAlignment() {
_ = md.NewMarkdown(os.Stdout).
H2("Table with Alignments").
Table(md.TableSet{
Header: []string{"Left Align", "Center Align", "Right Align"},
Rows: [][]string{
{"Content1", "Content2", "Content3"},
{"Content4", "Content5", "Content6"},
},
Alignment: []md.TableAlignment{md.AlignLeft, md.AlignCenter, md.AlignRight},
}).
Build()
// Output:
// ## Table with Alignments
// | Left Align | Center Align | Right Align |
// |:--------|:-------:|--------:|
// | Content1 | Content2 | Content3 |
// | Content4 | Content5 | Content6 |
}