Skip to content

Start .PD 0 on a new line for man line breaks - #671

Merged
jgm merged 1 commit into
commonmark:masterfrom
sagaragas:man-linebreak-cr
Nov 30, 2026
Merged

jgm merged 1 commit into
commonmark:masterfrom
sagaragas:man-linebreak-cr

Conversation

@sagaragas

Copy link
Copy Markdown
Contributor

In cmark -t man, hard line breaks and --hardbreaks soft breaks write .PD 0\n.P\n.PD without a leading newline:

$ printf 'foo  \nbar\n' | cmark -t man
.PP
foo.PD 0
.P
.PD
bar

Because .PD 0 isn't on its own line, groff prints it as literal text (foo.PD 0). That also stops .PD 0 from running, so .P leaves a full paragraph gap before bar.

I added CR() before LIT(".PD 0\n.P\n.PD") in both CMARK_NODE_LINEBREAK and the CMARK_OPT_HARDBREAKS branch, which matches every other macro in src/man.c. With groff -man -Tutf8 and man -l, foo and bar now sit on adjacent lines with no stray .PD 0.

I added five regression cases to render_man in api_test/main.c for hard breaks, --hardbreaks (with and without --nobreaks), wrapping, and consecutive breaks. All five fail on master and pass with the fix.

In src/man.c, CMARK_NODE_LINEBREAK and CMARK_NODE_SOFTBREAK under
CMARK_OPT_HARDBREAKS emit `.PD 0\n.P\n.PD` without a leading CR().
When text precedes the break, `.PD 0` is appended to that line
(e.g. `foo.PD 0`), so roff renders it as literal text and `.P` leaves
a full paragraph gap instead of a zero-spaced line break.

Call CR() before emitting `.PD 0\n.P\n.PD` in both branches, matching
every other macro in src/man.c, and add regression tests in
api_test/main.c.
@jgm
jgm merged commit 4bc0a0b into commonmark:master Nov 30, 2026
15 checks passed
@jgm

jgm commented Nov 30, 2026

Copy link
Copy Markdown
Member

Good, thanks.

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.

2 participants