@@ -17,11 +17,11 @@ public class TableBlockParser extends AbstractBlockParser {
1717
1818 private final TableBlock block = new TableBlock ();
1919 private final List <SourceLine > rowLines = new ArrayList <>();
20- private final List <TableCell . Alignment > columns ;
20+ private final List <TableCellInfo > columns ;
2121
2222 private boolean canHaveLazyContinuationLines = true ;
2323
24- private TableBlockParser (List <TableCell . Alignment > columns , SourceLine headerLine ) {
24+ private TableBlockParser (List <TableCellInfo > columns , SourceLine headerLine ) {
2525 this .columns = columns ;
2626 this .rowLines .add (headerLine );
2727 }
@@ -120,7 +120,9 @@ private TableCell parseCell(SourceLine cell, int column, InlineParser inlinePars
120120 }
121121
122122 if (column < columns .size ()) {
123- tableCell .setAlignment (columns .get (column ));
123+ TableCellInfo cellInfo = columns .get (column );
124+ tableCell .setAlignment (cellInfo .getAlignment ());
125+ tableCell .setWidth (cellInfo .getWidth ());
124126 }
125127
126128 CharSequence content = cell .getContent ();
@@ -187,11 +189,12 @@ private static List<SourceLine> split(SourceLine line) {
187189 // -|-
188190 // |-|-|
189191 // --- | ---
190- private static List <TableCell . Alignment > parseSeparator (CharSequence s ) {
191- List <TableCell . Alignment > columns = new ArrayList <>();
192+ private static List <TableCellInfo > parseSeparator (CharSequence s ) {
193+ List <TableCellInfo > columns = new ArrayList <>();
192194 int pipes = 0 ;
193195 boolean valid = false ;
194196 int i = 0 ;
197+ int width = 0 ;
195198 while (i < s .length ()) {
196199 char c = s .charAt (i );
197200 switch (c ) {
@@ -216,10 +219,12 @@ private static List<TableCell.Alignment> parseSeparator(CharSequence s) {
216219 if (c == ':' ) {
217220 left = true ;
218221 i ++;
222+ width ++;
219223 }
220224 boolean haveDash = false ;
221225 while (i < s .length () && s .charAt (i ) == '-' ) {
222226 i ++;
227+ width ++;
223228 haveDash = true ;
224229 }
225230 if (!haveDash ) {
@@ -229,8 +234,10 @@ private static List<TableCell.Alignment> parseSeparator(CharSequence s) {
229234 if (i < s .length () && s .charAt (i ) == ':' ) {
230235 right = true ;
231236 i ++;
237+ width ++;
232238 }
233- columns .add (getAlignment (left , right ));
239+ columns .add (new TableCellInfo (getAlignment (left , right ), width ));
240+ width = 0 ;
234241 // Next, need another pipe
235242 pipes = 0 ;
236243 break ;
@@ -270,7 +277,7 @@ public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockPar
270277 if (paragraphLines .size () == 1 && Characters .find ('|' , paragraphLines .get (0 ).getContent (), 0 ) != -1 ) {
271278 SourceLine line = state .getLine ();
272279 SourceLine separatorLine = line .substring (state .getIndex (), line .getContent ().length ());
273- List <TableCell . Alignment > columns = parseSeparator (separatorLine .getContent ());
280+ List <TableCellInfo > columns = parseSeparator (separatorLine .getContent ());
274281 if (columns != null && !columns .isEmpty ()) {
275282 SourceLine paragraph = paragraphLines .get (0 );
276283 List <SourceLine > headerCells = split (paragraph );
@@ -284,4 +291,22 @@ public BlockStart tryStart(ParserState state, MatchedBlockParser matchedBlockPar
284291 return BlockStart .none ();
285292 }
286293 }
294+
295+ private static class TableCellInfo {
296+ private final TableCell .Alignment alignment ;
297+ private final int width ;
298+
299+ public TableCell .Alignment getAlignment () {
300+ return alignment ;
301+ }
302+
303+ public int getWidth () {
304+ return width ;
305+ }
306+
307+ public TableCellInfo (TableCell .Alignment alignment , int width ) {
308+ this .alignment = alignment ;
309+ this .width = width ;
310+ }
311+ }
287312}
0 commit comments