Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion markdown/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ func writeBlock(w io.Writer, block Block) error {
return err
case OutputBlock:
fence := fenceFor(b.Content)
_, err := fmt.Fprintf(w, "%soutput\n%s%s\n", fence, b.Content, fence)
sep := ""
if b.Content != "" && !strings.HasSuffix(b.Content, "\n") {
sep = "\n"
}
_, err := fmt.Fprintf(w, "%soutput\n%s%s%s\n", fence, b.Content, sep, fence)
return err
case ImageOutputBlock:
_, err := fmt.Fprintf(w, "![%s](%s)\n", b.AltText, b.Filename)
Expand Down
15 changes: 15 additions & 0 deletions markdown/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,21 @@ func TestWriteOutputNoBackticks(t *testing.T) {
}
}

func TestWriteOutputNoTrailingNewline(t *testing.T) {
var buf strings.Builder
blocks := []Block{
OutputBlock{Content: "hello"},
}
err := Write(&buf, blocks)
if err != nil {
t.Fatal(err)
}
expected := "```output\nhello\n```\n"
if buf.String() != expected {
t.Errorf("expected:\n%q\ngot:\n%q", expected, buf.String())
}
}

func TestWriteTitleWithDocumentID(t *testing.T) {
var buf strings.Builder
blocks := []Block{
Expand Down