moul_md_filetest.gno
9.12 Kb · 390 lines
1// Package main
2// This is a filetest. It's somewhat similar to Go's 'Example' files/functions. It's there to showcase functionality and print the output of a specific scenario related to the package it's testing. In this case, it's related to the `Render` function.
3package main
4
5import "gno.land/r/docs/moul_md"
6
7func main() {
8 // Test the main Render function
9 println(moul_md.Render(""))
10}
11
12// Output:
13// # Package Demo: `p/moul/md`
14// This document demonstrates the features of the [gno\.land/p/moul/md](https://gno.land/p/moul/md) package, showing both the source code and the rendered result for each feature.
15//
16//
17// > **Note:** The md package provides helper functions to generate markdown programmatically, making it easier to create dynamic documentation and content.
18//
19// ## Text Formatting
20//
21// ### Bold Text
22// ```go
23// md.Bold("Important text")
24// ```
25// Result: **Important text**
26//
27//
28// ### Italic Text
29// ```go
30// md.Italic("Emphasized text")
31// ```
32// Result: *Emphasized text*
33//
34//
35// ### Strikethrough Text
36// ```go
37// md.Strikethrough("Deprecated feature")
38// ```
39// Result: ~~Deprecated feature~~
40//
41//
42// ### Combined Formatting
43// ```go
44// md.Bold(md.Italic("Very important"))
45// ```
46// Result: ***Very important***
47//
48//
49// ## Headers
50// The package supports all six levels of markdown headers:
51//
52//
53// ```go
54// md.H1("Main Title")
55// md.H2("Section")
56// md.H3("Subsection")
57// md.H4("Sub-subsection")
58// md.H5("Minor heading")
59// md.H6("Smallest heading")
60// ```
61// Result:
62// # Main Title
63// ## Section
64// ### Subsection
65// #### Sub-subsection
66// ##### Minor heading
67// ###### Smallest heading
68//
69// ## Lists
70//
71// ### Bullet Lists
72// ```go
73// items := []string{
74// "First item",
75// "Second item",
76// "Third item with\nmultiple lines",
77// }
78// md.BulletList(items)
79// ```
80// Result:
81// - First item
82// - Second item
83// - Third item with
84// multiple lines
85//
86// ### Ordered Lists
87// ```go
88// steps := []string{
89// "First step",
90// "Second step",
91// "Third step with\nadditional details",
92// }
93// md.OrderedList(steps)
94// ```
95// Result:
96// 1. First step
97// 2. Second step
98// 3. Third step with
99// additional details
100//
101// ### Todo Lists
102// ```go
103// tasks := []string{
104// "Completed task",
105// "Another completed task",
106// "Pending task",
107// "Another pending task",
108// }
109// completed := []bool{true, true, false, false}
110// md.TodoList(tasks, completed)
111// ```
112// Result:
113// - [x] Completed task
114// - [x] Another completed task
115// - [ ] Pending task
116// - [ ] Another pending task
117//
118// ### Nested Lists
119// ```go
120// md.BulletItem("Parent item") +
121// md.Nested(
122// md.BulletItem("Nested item 1") +
123// md.BulletItem("Nested item 2") +
124// md.Nested(
125// md.BulletItem("Deeply nested"),
126// " ",
127// ),
128// " ",
129// )
130// ```
131// Result:
132// - Parent item
133// - Nested item 1
134// - Nested item 2
135// - Deeply nested
136//
137// ## Links and Images
138//
139// ### Regular Links
140// ```go
141// md.Link("Gno Homepage", "https://gno.land")
142// ```
143// Result: [Gno Homepage](https://gno.land)
144//
145//
146// ### User Links
147// ```go
148// md.UserLink("moul")
149// ```
150// Result: [@moul](/u/moul)
151//
152//
153// ```go
154// md.UserLink("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
155// ```
156// Result: [g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5](/u/g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5)
157//
158//
159// ### Images
160// ```go
161// md.Image("Gno Logo", "/public/imgs/gnoland.svg")
162// ```
163// Result:
164// 
165// ### Clickable Images
166// ```go
167// md.InlineImageWithLink("Click me!", "/public/imgs/gnoland.svg", "https://gno.land")
168// ```
169// Result:
170// [](https://gno.land)
171// ## Code
172//
173// ### Inline Code
174// ```go
175// "Use " + md.InlineCode("gno test") + " to run tests"
176// ```
177// Result: Use `gno test` to run tests
178//
179//
180// ### Simple Code Block
181// ```go
182// md.CodeBlock("func main() {\n println(\"Hello, Gno!\")\n}")
183// ```
184// Result:
185// ```
186// func main() {
187// println("Hello, Gno!")
188// }
189// ```
190// ### Language-specific Code Block
191// ```go
192// md.LanguageCodeBlock("go", "package main\n\nfunc main() {\n println(\"Hello!\")\n}")
193// ```
194// Result:
195// ```go
196// package main
197//
198// func main() {
199// println("Hello!")
200// }
201// ```
202// ## Blockquotes
203// ```go
204// md.Blockquote("This is an important note.")
205// ```
206// Result:
207// > This is an important note.
208//
209// ```go
210// md.Blockquote("Multi-line quotes\nare also supported\nwith proper formatting.")
211// ```
212// Result:
213// > Multi-line quotes
214// > are also supported
215// > with proper formatting.
216//
217// ## Advanced Features
218//
219// ### Collapsible Sections
220// ```go
221// md.CollapsibleSection("Click to expand", "Hidden content here!")
222// ```
223// Result:
224// <details><summary>Click to expand</summary>
225//
226// Hidden content here!
227// </details>
228//
229// ### Two Columns
230// ```go
231// md.Columns([]string{
232// "Left column content",
233// "Right column content",
234// }, false)
235// ```
236// Result:
237// <gno-columns>
238// Left column content
239// |||
240// Right column content
241// </gno-columns>
242//
243// ### Multiple Columns (3 per row)
244// ```go
245// md.ColumnsN([]string{
246// "Item 1", "Item 2", "Item 3",
247// "Item 4", "Item 5", "Item 6",
248// }, 3, true)
249// ```
250// Result:
251// <gno-columns>
252// Item 1
253// |||
254// Item 2
255// |||
256// Item 3
257// </gno-columns>
258// <gno-columns>
259// Item 4
260// |||
261// Item 5
262// |||
263// Item 6
264// </gno-columns>
265//
266// ## Utility Functions
267//
268// ### Horizontal Rule
269// ```go
270// md.HorizontalRule()
271// ```
272// Result:
273// ---
274//
275// ### Footnotes
276// ```go
277// "This has a footnote[1].\n\n" + md.Footnote("1", "Footnote content here.")
278// ```
279// Result:
280// This has a footnote[1].
281//
282// [1]: Footnote content here.
283// ### Paragraphs
284// ```go
285// md.Paragraph("This ensures proper spacing.")
286// ```
287// Result:
288// This ensures proper spacing.
289//
290//
291// ## Practical Example
292// Here's a complete example showing how to build a rich user profile page using columns, images, and various md features:
293//
294//
295// ```go
296// // Example function that generates a rich user profile with balanced columns
297// func RenderProfile(username, name, bio string, avatar string, tasks []string, completed []bool) string {
298// // First row: Avatar/Basic Info | Bio
299// avatarSection := md.Image(name + " avatar", avatar) + "\n\n" +
300// md.H3("Basic Info") +
301// md.BulletList([]string{
302// md.Bold("Name:") + " " + name,
303// md.Bold("Username:") + " " + md.UserLink(username),
304// md.Bold("Status:") + " 🟢 Active",
305// md.Bold("Joined:") + " January 2024",
306// })
307//
308// bioSection := md.H3("Bio") +
309// md.Blockquote(bio)
310//
311// // Second row: Tasks | Links
312// tasksSection := md.H3("Current Tasks") +
313// md.TodoList(tasks, completed)
314//
315// linksSection := md.H3("Links") +
316// md.BulletList([]string{
317// md.Link("GitHub", "https://github.com/" + username),
318// md.Link("Portfolio", "https://example.com/" + username),
319// md.Link("LinkedIn", "https://linkedin.com/in/" + username),
320// })
321//
322// // Combine with main title and two sets of columns
323// return md.H1("User Profile: " + name) +
324// md.HorizontalRule() +
325// md.Columns([]string{avatarSection, bioSection}, true) +
326// "\n" +
327// md.Columns([]string{tasksSection, linksSection}, true)
328// }
329//
330// // Usage:
331// profile := RenderProfile(
332// "johndoe",
333// "John Doe",
334// "Passionate Gno developer building the future of smart contracts. Love working with blockchain technology and contributing to open source.",
335// "/public/imgs/gnoland.svg",
336// []string{"Complete Gno tutorial", "Build first realm", "Deploy to testnet", "Write documentation"},
337// []bool{true, true, false, false},
338// )
339// ```
340// Result when called with the above parameters:
341// # User Profile: John Doe
342// ---
343// <gno-columns>
344// 
345//
346// ### Basic Info
347// - **Name:** John Doe
348// - **Username:** [@johndoe](/u/johndoe)
349// - **Status:** 🟢 Active
350// - **Joined:** January 2024
351//
352// |||
353// ### Bio
354// > Passionate Gno developer building the future of smart contracts. Love working with blockchain technology and contributing to open source.
355//
356// |||
357//
358// |||
359//
360// </gno-columns>
361//
362// <gno-columns>
363// ### Current Tasks
364// - [x] Complete Gno tutorial
365// - [x] Build first realm
366// - [ ] Deploy to testnet
367// - [ ] Write documentation
368//
369// |||
370// ### Links
371// - [GitHub](https://github.com/johndoe)
372// - [Portfolio](https://example.com/johndoe)
373// - [LinkedIn](https://linkedin.com/in/johndoe)
374//
375// |||
376//
377// |||
378//
379// </gno-columns>
380//
381// ## Best Practices
382// 1. Prioritize code readability over performance in Render() - use clear variable names, logical grouping, and readable concatenation for humans
383// 2. Use the md package for all programmatic markdown generation in Render() methods
384// 3. Combine functions for complex formatting: `md.Bold(md.Italic("text"))`
385// 4. Use `md.Paragraph()` to ensure proper spacing between elements
386// 5. Leverage `md.ColumnsN()` for responsive layouts
387//
388// ## See Also
389// - [gno\.land/p/moul/md](https://gno.land/p/moul/md) - The md package source code
390// - [Markdown on Gno](https://gno.land/r/docs/markdown) - Comprehensive guide on Gno Flavored Markdown syntax