Skip to content

Commit

Permalink
Fix inline markup causing table cells to split
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
thaJeztah committed Jul 13, 2021
1 parent 9414b4c commit 9962558
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion md2man/roff.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (r *roffRenderer) handleText(w io.Writer, node *blackfriday.Node, entering
end = tableCellEnd
} else {
// end rows that aren't terminated by "tableCellEnd" with a cr if end of row
if node.Parent.Next == nil && !node.Parent.IsHeader {
if node.Parent.Next == nil && node.Next == nil && !node.Parent.IsHeader {
end = crTag
}
}
Expand Down
33 changes: 33 additions & 0 deletions md2man/roff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,39 @@ row two x
doTestsInlineParam(t, tests, TestParams{blackfriday.Tables})
}

func TestTableWrapping(t *testing.T) {
var tests = []string{
`
| Col1 | Col2 |
| ----------- | ----------------------------------------- |
| row one | This is a short line. |
| row\|two | Col1 should not wrap. |
| row three | no\|wrap |
| row four | Inline _cursive_ should not wrap. |
| row five | Inline ` + "`code`" + ` should not wrap. |
| 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. |
`,
`.nh
.TS
allbox;
l l
l l .
\fB\fCCol1\fR \fB\fCCol2\fR
row one This is a short line.
row|two Col1 should not wrap.
row three no|wrap
row four Inline \fIcursive\fP should not wrap.
row five Inline \fB\fCcode\fR should not wrap.
row six T{
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.
T}
.TE
`,
}
doTestsInlineParam(t, tests, TestParams{blackfriday.Tables})
}

func TestLinks(t *testing.T) {
var tests = []string{
"See [docs](https://docs.docker.com/) for\nmore",
Expand Down

0 comments on commit 9962558

Please sign in to comment.