Skip to content

Commit

Permalink
define Paragraph function
Browse files Browse the repository at this point in the history
  • Loading branch information
sunspirit99 committed Oct 8, 2024
1 parent 0aaf911 commit 8674cf0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
19 changes: 13 additions & 6 deletions examples/gno.land/p/demo/md/md.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
15 changes: 11 additions & 4 deletions examples/gno.land/p/demo/md/md_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit 8674cf0

Please sign in to comment.