Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trailing newline in code blocks #113

Merged
merged 1 commit into from
Mar 18, 2024
Merged
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
2 changes: 1 addition & 1 deletion md2man/roff.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const (
codespanTag = "\\fB"
codespanCloseTag = "\\fR"
codeTag = "\n.EX\n"
codeCloseTag = "\n.EE\n"
codeCloseTag = ".EE\n" // Do not prepend a newline character since code blocks, by definition, include a newline already (or at least as how blackfriday gives us on).
quoteTag = "\n.PP\n.RS\n"
quoteCloseTag = "\n.RE\n"
listTag = "\n.RS\n"
Expand Down
8 changes: 6 additions & 2 deletions md2man/roff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ type TestParams struct {
func TestCodeBlocks(t *testing.T) {
tests := []string{
"```\nsome code\n```\n",
".nh\n\n.EX\nsome code\n\n.EE\n",
".nh\n\n.EX\nsome code\n.EE\n",

"```bash\necho foo\n```\n",
".nh\n\n.EX\necho foo\n\n.EE\n",
".nh\n\n.EX\necho foo\n.EE\n",

// make sure literal new lines surrounding the markdown block are preserved as they are intentional
"```bash\n\nsome code\n\n```",
".nh\n\n.EX\n\nsome code\n\n.EE\n",
}
doTestsParam(t, tests, TestParams{blackfriday.FencedCode})
}
Expand Down
Loading