Skip to content

Commit 9962558

Browse files
committedJul 13, 2021
Fix inline markup causing table cells to split
Before this change, markup inside a table cell would introduce a newline, which resulted in those parts creating a new table row/cell: ┌───────────────────────────────┬───────────────────────────┐ │Col1 │ Col2 │ ├───────────────────────────────┼───────────────────────────┤ │row|one │ Col1 should not wrap. │ ├───────────────────────────────┼───────────────────────────┤ │row two │ no │ ├───────────────────────────────┼───────────────────────────┤ │| │ │ ├───────────────────────────────┼───────────────────────────┤ │wrap │ │ ├───────────────────────────────┼───────────────────────────┤ │row three │ Inline │ ├───────────────────────────────┼───────────────────────────┤ │cursive markup should not wrap │ │ ├───────────────────────────────┼───────────────────────────┤ │row four │ Inline │ ├───────────────────────────────┼───────────────────────────┤ │code markup should not wrap │ │ └───────────────────────────────┴───────────────────────────┘ After this change, markup does not introduce a newline, and content is correctly rendered in a single table row / cell: ┌───────────────────────────────┬───────────────────────────┐ │Col1 │ Col2 │ ├───────────────────────────────┼───────────────────────────┤ │row|one │ Col1 should not wrap. │ ├───────────────────────────────┼───────────────────────────┤ │row two │ no|wrap │ ├───────────────────────────────┼───────────────────────────┤ │row three │ Inline cursive markup │ │ │ should not wrap │ ├───────────────────────────────┼───────────────────────────┤ │row four │ Inline core markup should │ │ │ not wrap │ └───────────────────────────────┴───────────────────────────┘ Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 9414b4c commit 9962558

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed
 

‎md2man/roff.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (r *roffRenderer) handleText(w io.Writer, node *blackfriday.Node, entering
177177
end = tableCellEnd
178178
} else {
179179
// end rows that aren't terminated by "tableCellEnd" with a cr if end of row
180-
if node.Parent.Next == nil && !node.Parent.IsHeader {
180+
if node.Parent.Next == nil && node.Next == nil && !node.Parent.IsHeader {
181181
end = crTag
182182
}
183183
}

‎md2man/roff_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,39 @@ row two x
295295
doTestsInlineParam(t, tests, TestParams{blackfriday.Tables})
296296
}
297297

298+
func TestTableWrapping(t *testing.T) {
299+
var tests = []string{
300+
`
301+
| Col1 | Col2 |
302+
| ----------- | ----------------------------------------- |
303+
| row one | This is a short line. |
304+
| row\|two | Col1 should not wrap. |
305+
| row three | no\|wrap |
306+
| row four | Inline _cursive_ should not wrap. |
307+
| row five | Inline ` + "`code`" + ` should not wrap. |
308+
| row six | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu ipsum eget tortor aliquam accumsan. Quisque ac turpis convallis, sagittis urna ac, tempor est. Mauris nibh arcu, hendrerit id eros sed, sodales lacinia ex. Suspendisse sed condimentum urna, vitae mattis lectus. Mauris imperdiet magna vel purus pretium, id interdum libero. |
309+
`,
310+
`.nh
311+
312+
.TS
313+
allbox;
314+
l l
315+
l l .
316+
\fB\fCCol1\fR \fB\fCCol2\fR
317+
row one This is a short line.
318+
row|two Col1 should not wrap.
319+
row three no|wrap
320+
row four Inline \fIcursive\fP should not wrap.
321+
row five Inline \fB\fCcode\fR should not wrap.
322+
row six T{
323+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu ipsum eget tortor aliquam accumsan. Quisque ac turpis convallis, sagittis urna ac, tempor est. Mauris nibh arcu, hendrerit id eros sed, sodales lacinia ex. Suspendisse sed condimentum urna, vitae mattis lectus. Mauris imperdiet magna vel purus pretium, id interdum libero.
324+
T}
325+
.TE
326+
`,
327+
}
328+
doTestsInlineParam(t, tests, TestParams{blackfriday.Tables})
329+
}
330+
298331
func TestLinks(t *testing.T) {
299332
var tests = []string{
300333
"See [docs](https://docs.docker.com/) for\nmore",

0 commit comments

Comments
 (0)
Please sign in to comment.