diff --git a/pkg/document/markdown.go b/pkg/document/markdown.go index 6a7fb6f..ab05bcb 100644 --- a/pkg/document/markdown.go +++ b/pkg/document/markdown.go @@ -134,3 +134,19 @@ func (m MarkdownDocument) FormatCode(text string) string { return fmt.Sprintf("`%s`", text) } + +const CodeBlockMarker string = "```" + +func (m *MarkdownDocument) WriteCodeBlockMarker() *MarkdownDocument { + m.WriteText(CodeBlockMarker) + m.WriteNewLine() + + return m +} + +func (m *MarkdownDocument) WriteCodeBlockMarkerWithFormat(format string) *MarkdownDocument { + m.WriteText(fmt.Sprintf("%s%s", CodeBlockMarker, format)) + m.WriteNewLine() + + return m +} diff --git a/pkg/document/markdown_test.go b/pkg/document/markdown_test.go index c7764e1..71e0085 100644 --- a/pkg/document/markdown_test.go +++ b/pkg/document/markdown_test.go @@ -180,3 +180,39 @@ func TestMarkdownFormatCode(t *testing.T) { assert.Equal(t, tc.expectedCode, document.NewMarkdownDocument().FormatCode(tc.text)) } } + +func TestMarkdownWriteCodeBlockMarker(t *testing.T) { + t.Parallel() + + doc := document.NewMarkdownDocument() + doc.WriteCodeBlockMarker() + assert.Equal(t, "```\n", doc.Render()) +} + +func TestMarkdownWriteCodeBlockMarkerFormat(t *testing.T) { + t.Parallel() + + testCases := []struct { + format string + expected string + }{ + { + "yaml", + "```yaml\n", + }, + { + "python", + "```python\n", + }, + { + "sh", + "```sh\n", + }, + } + + for _, tc := range testCases { + doc := document.NewMarkdownDocument() + doc.WriteCodeBlockMarkerWithFormat(tc.format) + assert.Equal(t, tc.expected, doc.Render()) + } +}