Package com.vladsch.flexmark.util.format
Class MarkdownTable
- java.lang.Object
-
- com.vladsch.flexmark.util.format.MarkdownTable
-
public class MarkdownTable extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classMarkdownTable.ColumnSpanstatic classMarkdownTable.IndexSpanOffset
-
Field Summary
Fields Modifier and Type Field Description private CellAlignment[]alignmentsprivate TableSection[]ALL_BODY_ROWSprivate TableSection[]ALL_CONTENT_ROWSprivate TableSection[]ALL_HEADER_ROWSprivate TableSection[]ALL_SECTIONSstatic NumericSuffixPredicateALL_SUFFIXES_NO_SORTstatic NumericSuffixPredicateALL_SUFFIXES_SORTprivate TableSection[]ALL_TABLE_ROWSTableSectionbodyTableSectioncaptionstatic CharPredicateCOLON_TRIM_CHARSprivate int[]columnWidths(package private) java.lang.CharSequenceformatTableIndentPrefixTableSectionheaderprivate booleanisHeadingprivate booleanisSeparatorstatic NumericSuffixPredicateNO_SUFFIXESTableFormatOptionsoptionsTableSectionseparatorprivate java.lang.CharSequencetableCharsprivate @NotNull java.util.ArrayList<TrackedOffset>trackedOffsets
-
Constructor Summary
Constructors Constructor Description MarkdownTable(@NotNull java.lang.CharSequence tableChars, @Nullable DataHolder options)MarkdownTable(@NotNull java.lang.CharSequence tableChars, @Nullable TableFormatOptions options)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCell(@NotNull TableCell cell)booleanaddTrackedOffset(int offset)Deprecated.UseaddTrackedOffset(TrackedOffset)To create: TrackedOffset.track(offset)booleanaddTrackedOffset(int offset, boolean afterSpace)Deprecated.UseaddTrackedOffset(TrackedOffset)To create: TrackedOffset.track(offset, afterSpace)booleanaddTrackedOffset(int offset, boolean afterSpace, boolean afterDelete)Deprecated.UseaddTrackedOffset(TrackedOffset)To create: TrackedOffset.track(offset, afterSpace, afterDelete)booleanaddTrackedOffset(int offset, java.lang.Character c, boolean afterDelete)Deprecated.UseaddTrackedOffset(TrackedOffset)To create: TrackedOffset.track(offset, c, afterDelete)booleanaddTrackedOffset(@NotNull TrackedOffset trackedOffset)private CellAlignmentadjustCellAlignment(CellAlignment alignment)private intaggregateTotalColumnsWithoutColumns(TableSection[] sections, java.util.function.BiFunction<java.lang.Integer,java.lang.Integer,java.lang.Integer> aggregator, int... skipColumns)private intaggregateTotalColumnsWithoutRows(TableSection[] sections, java.util.function.BiFunction<java.lang.Integer,java.lang.Integer,java.lang.Integer> aggregator, int... skipRows)private voidappendColumnSpan(LineAppendable out, int span, int cellInsideEndOffset, int trackedSpanOffset)(package private) intappendDashes(LineAppendable out, int dashCount, BasedSequence sepDashes, int dashOffset)static voidappendFormattedCaption(LineAppendable out, BasedSequence caption, TableFormatOptions options)private voidappendRows(LineAppendable out, java.util.List<TableRow> rows, boolean isHeader, java.lang.CharSequence linePrefix)voidappendTable(LineAppendable out)private BasedSequencecellText(java.util.List<TableCell> cells, int index, boolean withTrackedOffset, boolean isHeader, int width, CellAlignment alignment, Ref<java.lang.Integer> delta)voiddeleteColumns(int column, int count)voiddeleteRows(int rowIndex, int count)voidfillMissingColumns()voidfillMissingColumns(java.lang.Integer minColumn)voidfinalizeTable()private @Nullable TrackedOffsetfindTrackedOffset(int offset)voidforAllBodyRows(int startIndex, int count, TableRowManipulator manipulator)voidforAllBodyRows(int startIndex, TableRowManipulator manipulator)voidforAllBodyRows(TableRowManipulator manipulator)voidforAllContentRows(int startIndex, int count, TableRowManipulator manipulator)voidforAllContentRows(int startIndex, TableRowManipulator manipulator)voidforAllContentRows(TableRowManipulator manipulator)voidforAllHeaderRows(int startIndex, int count, TableRowManipulator manipulator)voidforAllHeaderRows(int startIndex, TableRowManipulator manipulator)voidforAllHeaderRows(TableRowManipulator manipulator)voidforAllRows(int startIndex, int count, TableRowManipulator manipulator)voidforAllRows(int startIndex, TableRowManipulator manipulator)voidforAllRows(TableRowManipulator manipulator)voidforAllSectionRows(int startIndex, int count, TableRowManipulator manipulator)voidforAllSectionRows(int startIndex, TableRowManipulator manipulator)voidforAllSectionRows(TableRowManipulator manipulator)private voidforAllSectionsRows(int startIndex, int count, TableSection[] sections, TableRowManipulator manipulator)static java.lang.StringformattedCaption(BasedSequence caption, TableFormatOptions options)java.util.List<TableRow>getAllContentRows()intgetAllContentRowsCount()java.util.List<TableRow>getAllRows()intgetAllRowsCount()TableSectiongetAllRowsSection(int index)java.util.List<TableRow>getAllSectionRows()private java.util.List<TableRow>getAllSectionsRows(TableSection... sections)intgetAllSectionsRowsCount()intgetBodyRowCount()BasedSequencegetCaption()TableCellgetCaptionCell()intgetCaptionRowCount()TableCellOffsetInfogetCellOffsetInfo(int offset)java.lang.CharSequencegetFormatTableIndentPrefix()booleangetHaveCaption()booleangetHeader()intgetHeadingRowCount()intgetMaxBodyColumns()intgetMaxColumns()intgetMaxColumnsWithoutColumns(boolean withSeparator, int... skipColumns)intgetMaxColumnsWithoutRows(boolean withSeparator, int... skipRows)intgetMaxHeadingColumns()intgetMaxSeparatorColumns()intgetMinColumns()intgetMinColumnsWithoutColumns(boolean withSeparator, int... skipColumns)intgetMinColumnsWithoutRows(boolean withSeparator, int... skipRows)intgetSeparatorRowCount()java.lang.CharSequencegetTableChars()intgetTableStartOffset()@Nullable TrackedOffsetgetTrackedOffset(int offset)intgetTrackedOffsetIndex(int offset)@NotNull java.util.List<TrackedOffset>getTrackedOffsets()voidinsertColumns(int column, int count)voidinsertRows(int rowIndex, int count)private voidinsertRows(java.util.ArrayList<TableRow> rows, int index, int count, int maxColumns)booleanisAllRowsEmptyAt(int rowIndex)Test a row for having all empty columnsbooleanisAllRowsSeparator(int index)booleanisContentRowsEmptyAt(int rowIndex)Test a row for having all empty columnsbooleanisEmptyColumn(int column)Test all rows for having given column empty.private booleanisEmptyRowAt(int rowIndex, TableSection[] sections)Test a row for having all empty columnsbooleanisSeparator()voidmoveColumn(int fromColumn, int toColumn)voidnextRow()voidnormalize()private booleanpipeNeedsSpaceAfter(TableCell cell)private booleanpipeNeedsSpaceBefore(TableCell cell)voidsetBody()voidsetCaption(java.lang.CharSequence caption)voidsetCaptionCell(TableCell captionCell)voidsetCaptionWithMarkers(Node tableCellNode, java.lang.CharSequence captionOpen, java.lang.CharSequence caption, java.lang.CharSequence captionClose)voidsetFormatTableIndentPrefix(java.lang.CharSequence formatTableIndentPrefix)voidsetHeader()voidsetHeader(boolean header)voidsetSeparator()voidsetSeparator(boolean separator)private booleansetTrackedOffsetIndex(int offset, int index)MarkdownTablesorted(ColumnSort[] columnSorts, int textCollectionFlags, @Nullable NumericSuffixPredicate numericSuffixTester)Sort tableprivate intspanFixedWidth(java.util.BitSet unfixedColumns, int col, int columnSpan)private intspanWidth(int col, int columnSpan)java.lang.StringtoString()MarkdownTabletransposed(int columnHeaders)Transpose table
-
-
-
Field Detail
-
header
public final TableSection header
-
separator
public final TableSection separator
-
body
public final TableSection body
-
caption
public final TableSection caption
-
options
public TableFormatOptions options
-
isHeading
private boolean isHeading
-
isSeparator
private boolean isSeparator
-
formatTableIndentPrefix
java.lang.CharSequence formatTableIndentPrefix
-
alignments
private CellAlignment[] alignments
-
columnWidths
private int[] columnWidths
-
trackedOffsets
@NotNull private final @NotNull java.util.ArrayList<TrackedOffset> trackedOffsets
-
ALL_SECTIONS
private final TableSection[] ALL_SECTIONS
-
ALL_TABLE_ROWS
private final TableSection[] ALL_TABLE_ROWS
-
ALL_CONTENT_ROWS
private final TableSection[] ALL_CONTENT_ROWS
-
ALL_HEADER_ROWS
private final TableSection[] ALL_HEADER_ROWS
-
ALL_BODY_ROWS
private final TableSection[] ALL_BODY_ROWS
-
COLON_TRIM_CHARS
public static final CharPredicate COLON_TRIM_CHARS
-
tableChars
private final java.lang.CharSequence tableChars
-
NO_SUFFIXES
public static final NumericSuffixPredicate NO_SUFFIXES
-
ALL_SUFFIXES_SORT
public static final NumericSuffixPredicate ALL_SUFFIXES_SORT
-
ALL_SUFFIXES_NO_SORT
public static final NumericSuffixPredicate ALL_SUFFIXES_NO_SORT
-
-
Constructor Detail
-
MarkdownTable
public MarkdownTable(@NotNull @NotNull java.lang.CharSequence tableChars, @Nullable @Nullable DataHolder options)
-
MarkdownTable
public MarkdownTable(@NotNull @NotNull java.lang.CharSequence tableChars, @Nullable @Nullable TableFormatOptions options)
-
-
Method Detail
-
getTableChars
public java.lang.CharSequence getTableChars()
-
getCaptionCell
public TableCell getCaptionCell()
-
getFormatTableIndentPrefix
public java.lang.CharSequence getFormatTableIndentPrefix()
-
setFormatTableIndentPrefix
public void setFormatTableIndentPrefix(java.lang.CharSequence formatTableIndentPrefix)
-
setCaptionCell
public void setCaptionCell(TableCell captionCell)
-
getCaption
public BasedSequence getCaption()
-
setCaption
public void setCaption(java.lang.CharSequence caption)
-
setCaptionWithMarkers
public void setCaptionWithMarkers(Node tableCellNode, java.lang.CharSequence captionOpen, java.lang.CharSequence caption, java.lang.CharSequence captionClose)
-
getHeadingRowCount
public int getHeadingRowCount()
-
getSeparatorRowCount
public int getSeparatorRowCount()
-
getBodyRowCount
public int getBodyRowCount()
-
getCaptionRowCount
public int getCaptionRowCount()
-
getMaxHeadingColumns
public int getMaxHeadingColumns()
-
getMaxSeparatorColumns
public int getMaxSeparatorColumns()
-
getMaxBodyColumns
public int getMaxBodyColumns()
-
getHaveCaption
public boolean getHaveCaption()
-
getMinColumns
public int getMinColumns()
-
getMaxColumns
public int getMaxColumns()
-
getMinColumnsWithoutColumns
public int getMinColumnsWithoutColumns(boolean withSeparator, int... skipColumns)
-
getMaxColumnsWithoutColumns
public int getMaxColumnsWithoutColumns(boolean withSeparator, int... skipColumns)
-
getMinColumnsWithoutRows
public int getMinColumnsWithoutRows(boolean withSeparator, int... skipRows)
-
getMaxColumnsWithoutRows
public int getMaxColumnsWithoutRows(boolean withSeparator, int... skipRows)
-
getTrackedOffsets
@NotNull public @NotNull java.util.List<TrackedOffset> getTrackedOffsets()
-
findTrackedOffset
@Nullable private @Nullable TrackedOffset findTrackedOffset(int offset)
-
getTrackedOffset
@Nullable public @Nullable TrackedOffset getTrackedOffset(int offset)
-
getTrackedOffsetIndex
public int getTrackedOffsetIndex(int offset)
-
getTableStartOffset
public int getTableStartOffset()
-
getCellOffsetInfo
public TableCellOffsetInfo getCellOffsetInfo(int offset)
-
addTrackedOffset
@Deprecated public boolean addTrackedOffset(int offset)
Deprecated.UseaddTrackedOffset(TrackedOffset)To create: TrackedOffset.track(offset)
-
addTrackedOffset
@Deprecated public boolean addTrackedOffset(int offset, boolean afterSpace)Deprecated.UseaddTrackedOffset(TrackedOffset)To create: TrackedOffset.track(offset, afterSpace)
-
addTrackedOffset
@Deprecated public boolean addTrackedOffset(int offset, boolean afterSpace, boolean afterDelete)Deprecated.UseaddTrackedOffset(TrackedOffset)To create: TrackedOffset.track(offset, afterSpace, afterDelete)
-
addTrackedOffset
@Deprecated public boolean addTrackedOffset(int offset, java.lang.Character c, boolean afterDelete)Deprecated.UseaddTrackedOffset(TrackedOffset)To create: TrackedOffset.track(offset, c, afterDelete)
-
addTrackedOffset
public boolean addTrackedOffset(@NotNull @NotNull TrackedOffset trackedOffset)
-
getAllRows
public java.util.List<TableRow> getAllRows()
-
getAllContentRows
public java.util.List<TableRow> getAllContentRows()
-
getAllSectionRows
public java.util.List<TableRow> getAllSectionRows()
-
getAllSectionsRows
private java.util.List<TableRow> getAllSectionsRows(TableSection... sections)
-
isAllRowsSeparator
public boolean isAllRowsSeparator(int index)
-
getAllRowsSection
public TableSection getAllRowsSection(int index)
-
getAllRowsCount
public int getAllRowsCount()
-
getAllContentRowsCount
public int getAllContentRowsCount()
-
getAllSectionsRowsCount
public int getAllSectionsRowsCount()
-
forAllRows
public void forAllRows(TableRowManipulator manipulator)
-
forAllRows
public void forAllRows(int startIndex, TableRowManipulator manipulator)
-
forAllRows
public void forAllRows(int startIndex, int count, TableRowManipulator manipulator)
-
forAllContentRows
public void forAllContentRows(TableRowManipulator manipulator)
-
forAllContentRows
public void forAllContentRows(int startIndex, TableRowManipulator manipulator)
-
forAllContentRows
public void forAllContentRows(int startIndex, int count, TableRowManipulator manipulator)
-
forAllSectionRows
public void forAllSectionRows(TableRowManipulator manipulator)
-
forAllSectionRows
public void forAllSectionRows(int startIndex, TableRowManipulator manipulator)
-
forAllSectionRows
public void forAllSectionRows(int startIndex, int count, TableRowManipulator manipulator)
-
forAllHeaderRows
public void forAllHeaderRows(TableRowManipulator manipulator)
-
forAllHeaderRows
public void forAllHeaderRows(int startIndex, TableRowManipulator manipulator)
-
forAllHeaderRows
public void forAllHeaderRows(int startIndex, int count, TableRowManipulator manipulator)
-
forAllBodyRows
public void forAllBodyRows(TableRowManipulator manipulator)
-
forAllBodyRows
public void forAllBodyRows(int startIndex, TableRowManipulator manipulator)
-
forAllBodyRows
public void forAllBodyRows(int startIndex, int count, TableRowManipulator manipulator)
-
deleteRows
public void deleteRows(int rowIndex, int count)
-
insertRows
public void insertRows(int rowIndex, int count)
-
insertRows
private void insertRows(java.util.ArrayList<TableRow> rows, int index, int count, int maxColumns)
-
insertColumns
public void insertColumns(int column, int count)
-
deleteColumns
public void deleteColumns(int column, int count)
-
moveColumn
public void moveColumn(int fromColumn, int toColumn)
-
isEmptyColumn
public boolean isEmptyColumn(int column)
Test all rows for having given column empty. All columns after row's max column are empty- Parameters:
column- index in allRows list- Returns:
- true if column is empty for all rows, separator row excluded
-
isAllRowsEmptyAt
public boolean isAllRowsEmptyAt(int rowIndex)
Test a row for having all empty columns- Parameters:
rowIndex- index in allRows list- Returns:
- true if row is empty or is a separator row
-
isContentRowsEmptyAt
public boolean isContentRowsEmptyAt(int rowIndex)
Test a row for having all empty columns- Parameters:
rowIndex- index in allRows list- Returns:
- true if row is empty or is a separator row
-
isEmptyRowAt
private boolean isEmptyRowAt(int rowIndex, TableSection[] sections)Test a row for having all empty columns- Parameters:
rowIndex- index in allRows listsections- sections to use for rows array generation- Returns:
- true if row is empty or is a separator row
-
getHeader
public boolean getHeader()
-
setHeader
public void setHeader(boolean header)
-
isSeparator
public boolean isSeparator()
-
setSeparator
public void setSeparator(boolean separator)
-
setHeader
public void setHeader()
-
setSeparator
public void setSeparator()
-
setBody
public void setBody()
-
nextRow
public void nextRow()
-
addCell
public void addCell(@NotNull @NotNull TableCell cell)- Parameters:
cell- cell to add
-
normalize
public void normalize()
-
finalizeTable
public void finalizeTable()
-
fillMissingColumns
public void fillMissingColumns()
-
fillMissingColumns
public void fillMissingColumns(java.lang.Integer minColumn)
-
setTrackedOffsetIndex
private boolean setTrackedOffsetIndex(int offset, int index)
-
transposed
public MarkdownTable transposed(int columnHeaders)
Transpose table- Parameters:
columnHeaders- number of first columns to use as header rows, 0..maxColumns- Returns:
- transposed table
-
sorted
public MarkdownTable sorted(ColumnSort[] columnSorts, int textCollectionFlags, @Nullable @Nullable NumericSuffixPredicate numericSuffixTester)
Sort table- Parameters:
columnSorts- column sort informationtextCollectionFlags- collection flags to use for collecting cell textnumericSuffixTester- predicate to test non-numeric suffix of numeric column content, return true if suffix is acceptable, null will result in all suffixes being accepted- Returns:
- sorted table
-
appendDashes
int appendDashes(LineAppendable out, int dashCount, BasedSequence sepDashes, int dashOffset)
-
appendTable
public void appendTable(LineAppendable out)
-
appendFormattedCaption
public static void appendFormattedCaption(LineAppendable out, BasedSequence caption, TableFormatOptions options)
-
formattedCaption
public static java.lang.String formattedCaption(BasedSequence caption, TableFormatOptions options)
-
pipeNeedsSpaceBefore
private boolean pipeNeedsSpaceBefore(TableCell cell)
-
pipeNeedsSpaceAfter
private boolean pipeNeedsSpaceAfter(TableCell cell)
-
appendRows
private void appendRows(LineAppendable out, java.util.List<TableRow> rows, boolean isHeader, java.lang.CharSequence linePrefix)
-
appendColumnSpan
private void appendColumnSpan(LineAppendable out, int span, int cellInsideEndOffset, int trackedSpanOffset)
-
cellText
private BasedSequence cellText(java.util.List<TableCell> cells, int index, boolean withTrackedOffset, boolean isHeader, int width, CellAlignment alignment, Ref<java.lang.Integer> delta)
-
spanWidth
private int spanWidth(int col, int columnSpan)
-
spanFixedWidth
private int spanFixedWidth(java.util.BitSet unfixedColumns, int col, int columnSpan)
-
adjustCellAlignment
private CellAlignment adjustCellAlignment(CellAlignment alignment)
-
aggregateTotalColumnsWithoutColumns
private int aggregateTotalColumnsWithoutColumns(TableSection[] sections, java.util.function.BiFunction<java.lang.Integer,java.lang.Integer,java.lang.Integer> aggregator, int... skipColumns)
-
aggregateTotalColumnsWithoutRows
private int aggregateTotalColumnsWithoutRows(TableSection[] sections, java.util.function.BiFunction<java.lang.Integer,java.lang.Integer,java.lang.Integer> aggregator, int... skipRows)
-
forAllSectionsRows
private void forAllSectionsRows(int startIndex, int count, TableSection[] sections, TableRowManipulator manipulator)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-