Skip to content

md: emit newline before closing fence in codeBlock#358

Merged
kjk merged 1 commit intogomarkdown:masterfrom
kardamanov:fix-md-codeblock-trailing-newline
Apr 17, 2026
Merged

md: emit newline before closing fence in codeBlock#358
kjk merged 1 commit intogomarkdown:masterfrom
kardamanov:fix-md-codeblock-trailing-newline

Conversation

@kardamanov
Copy link
Copy Markdown
Contributor

Fixes #357.

Summary

  • md.Renderer.codeBlock used to write the closing ``` fence directly after the node literal. If the CodeBlock.Literal did not already end with \n (e.g. when the AST was constructed manually), the result was malformed markdown with the closing fence glued to the last content line. TestRenderCodeBlock exercised exactly this case and has been failing as a result — it was only hidden because the CI workflow runs go test on ., ./ast, ./parser, ./html and not on ./md.
  • Emit \n before the closing fence when the literal does not already end with one. Literals produced by the parser end with a newline, so TestRenderCodeWithParagraph and other parser-driven tests are unaffected.
  • Update TestRenderCodeBlock's expected string to end with \n\n (matching the doubleSpace + closing-block semantics used by every other test in the file).

See #357 for the full reproduction and root-cause analysis.

Test plan

  • go test -v ./md — 16/16 pass (previously 15/16)
  • go test ./... — all previously passing packages still pass; examples/ still fails to build for an unrelated reason (missing github.com/alecthomas/chroma/styles module)

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).
@kjk kjk merged commit 7d523f7 into gomarkdown:master Apr 17, 2026
1 check passed
@kjk
Copy link
Copy Markdown
Contributor

kjk commented Apr 17, 2026

thanks!

@kardamanov kardamanov deleted the fix-md-codeblock-trailing-newline branch April 17, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

md: TestRenderCodeBlock fails — closing fence not preceded by newline

2 participants