example_test.gno
4.10 Kb · 207 lines
1package md
2
3import "strings"
4
5func ExampleHeaders() {
6 println(H1("Header 1"))
7 println(H2("Header 2"))
8 println(H3("Header 3"))
9 println(H4("Header 4"))
10 println(H5("Header 5"))
11 println(H6("Header 6"))
12
13 // Output:
14 // # Header 1
15 //
16 // ## Header 2
17 //
18 // ### Header 3
19 //
20 // #### Header 4
21 //
22 // ##### Header 5
23 //
24 // ###### Header 6
25}
26
27func ExampleStyles() {
28 println(Bold("bold"))
29 println(Italic("italic"))
30 println(Strikethrough("strikethrough"))
31
32 // Output:
33 // **bold**
34 // *italic*
35 // ~~strikethrough~~
36}
37
38func ExampleLists() {
39 println(BulletList([]string{
40 "Item 1",
41 "Item 2\nMore details for item 2",
42 }))
43 println(OrderedList([]string{"Step 1", "Step 2"}))
44 println(TodoList([]string{"Task 1", "Task 2\nSubtask 2"}, []bool{true, false}))
45 println(Nested(BulletList([]string{"Parent Item", OrderedList([]string{"Child 1", "Child 2"})}), " "))
46
47 // Output:
48 // - Item 1
49 // - Item 2
50 // More details for item 2
51 //
52 // 1. Step 1
53 // 2. Step 2
54 //
55 // - [x] Task 1
56 // - [ ] Task 2
57 // Subtask 2
58 //
59 // - Parent Item
60 // - 1. Child 1
61 // 2. Child 2
62}
63
64func ExampleBlocks() {
65 print(Paragraph("This is a paragraph."))
66 // Blockquote adds multiple newlines which Output doesn't allow, so trim
67 println(strings.TrimSpace(Blockquote("This is a blockquote\nSpanning multiple lines")))
68
69 // Output:
70 // This is a paragraph.
71 //
72 // > This is a blockquote
73 // > Spanning multiple lines
74}
75
76func ExampleCode() {
77 println(InlineCode("inline `code`"))
78 println(CodeBlock("line1\nline2"))
79 println(LanguageCodeBlock("go", "func main() {\nprintln(\"Hello, world!\")\n}"))
80 println(HorizontalRule())
81
82 // Output:
83 // `` inline `code` ``
84 // ```
85 // line1
86 // line2
87 // ```
88 //
89 // ```go
90 // func main() {
91 // println("Hello, world!")
92 // }
93 // ```
94 //
95 // ---
96}
97
98func ExampleReferences() {
99 println(Link("Gno", "http://gno.land"))
100 println(Image("Alt Text", "http://example.com/image.png"))
101 println(InlineImageWithLink("Alt Text", "http://example.com/image.png", "http://example.com"))
102 println(FootnoteDefinition("ref", "This is a footnote"))
103 // LinkReferenceDefinition adds multiple newlines which Output doesn't allow, so trim
104 println(strings.TrimSpace(LinkReferenceDefinition("r-example", "/r/example", "")))
105
106 // Output:
107 //
108 // [Gno](http://gno.land)
109 // 
110 // [](http://example.com)
111 // [^ref]:
112 // This is a footnote
113 //
114 // [r-example]: /r/example
115}
116
117func ExampleColumns() {
118 println("4 columns in one gno-columns tag:")
119 println(Columns([]string{
120 "Column1\ncontent1",
121 "Column2\ncontent2",
122 "Column3\ncontent3",
123 "Column4\ncontent4",
124 }, true))
125
126 // Should be automatically placed in multiple column tags
127 println("3 cols per row without padding:")
128 println(ColumnsN([]string{
129 "Row1Column1\ncontent1",
130 "Row1Column2\ncontent2",
131 "Row1Column3\ncontent3",
132 "Row2Column1\ncontent1",
133 "Row2Column2\ncontent2",
134 "Row2Column3\ncontent3",
135 "Row3Column1\ncontent1",
136 "Row3Column2\ncontent2",
137 "Row3Column3\ncontent3",
138 }, 3, false))
139
140 // Should be padded, up to 4 cols
141 println("2 padded to 4:")
142 println(ColumnsN([]string{
143 "Column1\ncontent1",
144 "Column2\ncontent2",
145 }, 4, true))
146
147 // Output:
148 // 4 columns in one gno-columns tag:
149 // <gno-columns>
150 // Column1
151 // content1
152 // <gno-columns-sep>
153 // Column2
154 // content2
155 // <gno-columns-sep>
156 // Column3
157 // content3
158 // <gno-columns-sep>
159 // Column4
160 // content4
161 // </gno-columns>
162 //
163 // 3 cols per row without padding:
164 // <gno-columns>
165 // Row1Column1
166 // content1
167 // <gno-columns-sep>
168 // Row1Column2
169 // content2
170 // <gno-columns-sep>
171 // Row1Column3
172 // content3
173 // </gno-columns>
174 // <gno-columns>
175 // Row2Column1
176 // content1
177 // <gno-columns-sep>
178 // Row2Column2
179 // content2
180 // <gno-columns-sep>
181 // Row2Column3
182 // content3
183 // </gno-columns>
184 // <gno-columns>
185 // Row3Column1
186 // content1
187 // <gno-columns-sep>
188 // Row3Column2
189 // content2
190 // <gno-columns-sep>
191 // Row3Column3
192 // content3
193 // </gno-columns>
194 //
195 // 2 padded to 4:
196 // <gno-columns>
197 // Column1
198 // content1
199 // <gno-columns-sep>
200 // Column2
201 // content2
202 // <gno-columns-sep>
203 //
204 // <gno-columns-sep>
205 //
206 // </gno-columns>
207}