Conditional Linebreaks

With all excessive white spaces being removed, conditional line breaks in a cell need to be done using a markup. The implementation recognizes the two HTML line break markups <br> and <br />.

The example below adds text to a table cell with excessive white spaces (being removed) and conditional line breaks (being translated into line breaks).

The lines 1 and 2 add a conditional line break as <br> and <br /> respectively. They appear as individual lines. The third line has an excessive line break, which will be removed, resulting in a single line.

1
2
3
4
5
6
7
8
9
10
11
12
                String text = "line 1<br>" +
                        "line 2<br/>" +
                        "line three \n still line three"
                ;
//                String text = new LoremIpsum().getParagraphs(1) + "\r\n\n<br><br><br>" + new LoremIpsum().getParagraphs(1);

                AsciiTable at = new AsciiTable();
                at.addRule();
                at.addRow(text);
                at.addRule();
                at.setTextAlignment(TextAlignment.LEFT);
                System.out.println(at.render(50));

The resulting output:

┌────────────────────────────────────────────────┐
│line 1                                          │
│line 2                                          │
│line three still line three                     │
└────────────────────────────────────────────────┘