diff --git a/examples/gno.land/p/demo/md/md.gno b/examples/gno.land/p/demo/md/md.gno index 71ba4f22481..1b2aaec8d09 100644 --- a/examples/gno.land/p/demo/md/md.gno +++ b/examples/gno.land/p/demo/md/md.gno @@ -83,12 +83,14 @@ func InlineCode(code string) string { return ufmt.Sprintf("`%s`", code) } -// CodeBlock returns a code block for markdown, optionally specifying the language -func CodeBlock(code string, language string) string { - if language != "" { - return ufmt.Sprintf("```%s\n%s\n```", language, code) - } - return ufmt.Sprintf("```\n%s\n```", code) +// CodeBlock creates a markdown code block +func CodeBlock(content string) string { + return ufmt.Sprintf("```\n%s\n```", content) +} + +// LanguageCodeBlock creates a markdown code block with language-specific syntax highlighting +func LanguageCodeBlock(language, content string) string { + return ufmt.Sprintf("```%s\n%s\n```", language, content) } // LineBreak returns the specified number of line breaks for markdown @@ -118,3 +120,8 @@ func Image(altText, url string) string { func Footnote(reference, text string) string { return ufmt.Sprintf("[%s]: %s", reference, text) } + +// Paragraph wraps the given text in a Markdown paragraph +func Paragraph(content string) string { + return ufmt.Sprintf("%s\n\n", content) +} diff --git a/examples/gno.land/p/demo/md/md_test.gno b/examples/gno.land/p/demo/md/md_test.gno index c58da47ba75..d8faa506f91 100644 --- a/examples/gno.land/p/demo/md/md_test.gno +++ b/examples/gno.land/p/demo/md/md_test.gno @@ -64,13 +64,15 @@ func Test_InlineCode(t *testing.T) { uassert.Equal(t, result, "`code`") } -func Test_CodeBlock(t *testing.T) { - result := CodeBlock("print('Hello')", "python") +func Test_LanguageCodeBlock(t *testing.T) { + result := LanguageCodeBlock("python", "print('Hello')") expected := "```python\nprint('Hello')\n```" uassert.Equal(t, result, expected) +} - result = CodeBlock("print('Hello')", "") - expected = "```\nprint('Hello')\n```" +func Test_CodeBlock(t *testing.T) { + result := CodeBlock("print('Hello')") + expected := "```\nprint('Hello')\n```" uassert.Equal(t, result, expected) } @@ -104,6 +106,11 @@ func Test_Footnote(t *testing.T) { uassert.Equal(t, result, "[1]: This is a footnote.") } +func Test_Paragraph(t *testing.T) { + result := Paragraph("This is a paragraph.") + uassert.Equal(t, result, "This is a paragraph.\n\n") +} + func Test_Table(t *testing.T) { table, err := NewTable([]string{"Header1", "Header2"}, [][]string{ {"Row1Col1", "Row1Col2"},