Skip to content

Commit 7d523f7

Browse files
kardamanovkjk
authored andcommitted
md: emit newline before closing fence in codeBlock
The codeBlock renderer wrote the closing backtick fence directly after the node literal. When the literal did not end with a newline (as with a manually constructed ast.CodeBlock), the result was malformed markdown like 'val x : Int = 42```' on a single line. Emit a newline before the closing fence when the literal does not already end with one. Also correct the expected string in TestRenderCodeBlock to end with \n\n (matching doubleSpace semantics used by every other test in this file).
1 parent 134a5b2 commit 7d523f7

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

md/md_renderer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ func (r *Renderer) codeBlock(w io.Writer, node *ast.CodeBlock) {
264264
}
265265
r.outs(w, "\n")
266266
r.out(w, text)
267+
if len(text) == 0 || text[len(text)-1] != '\n' {
268+
r.outs(w, "\n")
269+
}
267270
r.outs(w, "```\n\n")
268271
}
269272

md/md_renderer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestRenderCode(t *testing.T) {
7373
func TestRenderCodeBlock(t *testing.T) {
7474
input := &ast.CodeBlock{Info: []byte(string("scala"))}
7575
input.Literal = []byte(string("val x : Int = 42"))
76-
expected := "\n```scala\nval x : Int = 42\n```\n"
76+
expected := "\n```scala\nval x : Int = 42\n```\n\n"
7777
testRendering(t, input, expected)
7878
}
7979

0 commit comments

Comments
 (0)