md.gno

4.72 Kb ยท 158 lines
  1package md
  2
  3import (
  4	"gno.land/p/sunspirit/md"
  5	"gno.land/p/sunspirit/table"
  6)
  7
  8func Render(path string) string {
  9	title := "A simple, flexible, and easy-to-use library for creating markdown documents in gno.land"
 10
 11	mdBuilder := md.NewBuilder().
 12		Add(md.H1(md.Italic(md.Bold(title)))).
 13
 14		// Bold Text section
 15		Add(
 16			md.H3(md.Bold("1. Bold Text")),
 17			md.Paragraph("To make text bold, use the `md.Bold()` function:"),
 18			md.Bold("This is bold text"),
 19		).
 20
 21		// Italic Text section
 22		Add(
 23			md.H3(md.Bold("2. Italic Text")),
 24			md.Paragraph("To make text italic, use the `md.Italic()` function:"),
 25			md.Italic("This is italic text"),
 26		).
 27
 28		// Strikethrough Text section
 29		Add(
 30			md.H3(md.Bold("3. Strikethrough Text")),
 31			md.Paragraph("To add strikethrough, use the `md.Strikethrough()` function:"),
 32			md.Strikethrough("This text is strikethrough"),
 33		).
 34
 35		// Headers section
 36		Add(
 37			md.H3(md.Bold("4. Headers (H1 to H6)")),
 38			md.Paragraph("You can create headers (H1 to H6) using the `md.H1()` to `md.H6()` functions:"),
 39			md.H1("This is a level 1 header"),
 40			md.H2("This is a level 2 header"),
 41			md.H3("This is a level 3 header"),
 42			md.H4("This is a level 4 header"),
 43			md.H5("This is a level 5 header"),
 44			md.H6("This is a level 6 header"),
 45		).
 46
 47		// Bullet List section
 48		Add(
 49			md.H3(md.Bold("5. Bullet List")),
 50			md.Paragraph("To create bullet lists, use the `md.BulletList()` function:"),
 51			md.BulletList([]string{"Item 1", "Item 2", "Item 3"}),
 52		).
 53
 54		// Ordered List section
 55		Add(
 56			md.H3(md.Bold("6. Ordered List")),
 57			md.Paragraph("To create ordered lists, use the `md.OrderedList()` function:"),
 58			md.OrderedList([]string{"First", "Second", "Third"}),
 59		).
 60
 61		// Todo List section
 62		Add(
 63			md.H3(md.Bold("7. Todo List")),
 64			md.Paragraph("You can create a todo list using the `md.TodoList()` function, which supports checkboxes:"),
 65			md.TodoList([]string{"Task 1", "Task 2"}, []bool{true, false}),
 66		).
 67
 68		// Blockquote section
 69		Add(
 70			md.H3(md.Bold("8. Blockquote")),
 71			md.Paragraph("To create blockquotes, use the `md.Blockquote()` function:"),
 72			md.Blockquote("This is a blockquote.\nIt can span multiple lines."),
 73		).
 74
 75		// Inline Code section
 76		Add(
 77			md.H3(md.Bold("9. Inline Code")),
 78			md.Paragraph("To insert inline code, use the `md.InlineCode()` function:"),
 79			md.InlineCode("fmt.Println() // inline code"),
 80		).
 81
 82		// Code Block section
 83		Add(
 84			md.H3(md.Bold("10. Code Block")),
 85			md.Paragraph("For multi-line code blocks, use the `md.CodeBlock()` function:"),
 86			md.CodeBlock("package main\n\nfunc main() {\n\t// Your code here\n}"),
 87		).
 88
 89		// Horizontal Rule section
 90		Add(
 91			md.H3(md.Bold("11. Horizontal Rule")),
 92			md.Paragraph("To add a horizontal rule (separator), use the `md.HorizontalRule()` function:"),
 93			md.LineBreak(1),
 94			md.HorizontalRule(),
 95		).
 96
 97		// Language-specific Code Block section
 98		Add(
 99			md.H3(md.Bold("12. Language-specific Code Block")),
100			md.Paragraph("To create language-specific code blocks, use the `md.LanguageCodeBlock()` function:"),
101			md.LanguageCodeBlock("go", "package main\n\nfunc main() {}"),
102		).
103
104		// Hyperlink section
105		Add(
106			md.H3(md.Bold("13. Hyperlink")),
107			md.Paragraph("To create a hyperlink, use the `md.Link()` function:"),
108			md.Link("Gnoland official docs", "https://docs.gno.land"),
109		).
110
111		// Image section
112		Add(
113			md.H3(md.Bold("14. Image")),
114			md.Paragraph("To insert an image, use the `md.Image()` function:"),
115			md.LineBreak(1),
116			md.Image("Gnoland Logo", "https://gnolang.github.io/blog/2024-05-21_the-gnome/src/banner.png"),
117		).
118
119		// Footnote section
120		Add(
121			md.H3(md.Bold("15. Footnote")),
122			md.Paragraph("To create footnotes, use the `md.Footnote()` function:"),
123			md.LineBreak(1),
124			md.Footnote("1", "This is a footnote."),
125		).
126
127		// Table section
128		Add(
129			md.H3(md.Bold("16. Table")),
130			md.Paragraph("To create a table, use the `md.Table()` function. Here's an example of a table:"),
131		)
132
133	// Create a table using the table package
134	tb, _ := table.New([]string{"Feature", "Description"}, [][]string{
135		{"Bold", "Make text bold using " + md.Bold("double asterisks")},
136		{"Italic", "Make text italic using " + md.Italic("single asterisks")},
137		{"Strikethrough", "Cross out text using " + md.Strikethrough("double tildes")},
138	})
139	mdBuilder.Add(md.Table(tb))
140
141	// Escaping Markdown section
142	mdBuilder.Add(
143		md.H3(md.Bold("17. Escaping Markdown")),
144		md.Paragraph("Sometimes, you need to escape special Markdown characters (like *, _, and `). Use the `md.EscapeMarkdown()` function for this:"),
145	)
146
147	// Example of escaping markdown
148	text := "- Escape special chars like *, _, and ` in markdown"
149	mdBuilder.Add(
150		md.H4("Text Without Escape:"),
151		text,
152		md.LineBreak(1),
153		md.H4("Text With Escape:"),
154		md.EscapeMarkdown(text),
155	)
156
157	return mdBuilder.Render(md.LineBreak(1))
158}