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 class
MarkdownTable.ColumnSpan
static class
MarkdownTable.IndexSpanOffset
-
Field Summary
Fields Modifier and Type Field Description private CellAlignment[]
alignments
private TableSection[]
ALL_BODY_ROWS
private TableSection[]
ALL_CONTENT_ROWS
private TableSection[]
ALL_HEADER_ROWS
private TableSection[]
ALL_SECTIONS
static NumericSuffixPredicate
ALL_SUFFIXES_NO_SORT
static NumericSuffixPredicate
ALL_SUFFIXES_SORT
private TableSection[]
ALL_TABLE_ROWS
TableSection
body
TableSection
caption
static CharPredicate
COLON_TRIM_CHARS
private int[]
columnWidths
(package private) java.lang.CharSequence
formatTableIndentPrefix
TableSection
header
private boolean
isHeading
private boolean
isSeparator
static NumericSuffixPredicate
NO_SUFFIXES
TableFormatOptions
options
TableSection
separator
private java.lang.CharSequence
tableChars
private @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 void
addCell(@NotNull TableCell cell)
boolean
addTrackedOffset(int offset)
Deprecated.UseaddTrackedOffset(TrackedOffset)
To create: TrackedOffset.track(offset)boolean
addTrackedOffset(int offset, boolean afterSpace)
Deprecated.UseaddTrackedOffset(TrackedOffset)
To create: TrackedOffset.track(offset, afterSpace)boolean
addTrackedOffset(int offset, boolean afterSpace, boolean afterDelete)
Deprecated.UseaddTrackedOffset(TrackedOffset)
To create: TrackedOffset.track(offset, afterSpace, afterDelete)boolean
addTrackedOffset(int offset, java.lang.Character c, boolean afterDelete)
Deprecated.UseaddTrackedOffset(TrackedOffset)
To create: TrackedOffset.track(offset, c, afterDelete)boolean
addTrackedOffset(@NotNull TrackedOffset trackedOffset)
private CellAlignment
adjustCellAlignment(CellAlignment alignment)
private int
aggregateTotalColumnsWithoutColumns(TableSection[] sections, java.util.function.BiFunction<java.lang.Integer,java.lang.Integer,java.lang.Integer> aggregator, int... skipColumns)
private int
aggregateTotalColumnsWithoutRows(TableSection[] sections, java.util.function.BiFunction<java.lang.Integer,java.lang.Integer,java.lang.Integer> aggregator, int... skipRows)
private void
appendColumnSpan(LineAppendable out, int span, int cellInsideEndOffset, int trackedSpanOffset)
(package private) int
appendDashes(LineAppendable out, int dashCount, BasedSequence sepDashes, int dashOffset)
static void
appendFormattedCaption(LineAppendable out, BasedSequence caption, TableFormatOptions options)
private void
appendRows(LineAppendable out, java.util.List<TableRow> rows, boolean isHeader, java.lang.CharSequence linePrefix)
void
appendTable(LineAppendable out)
private BasedSequence
cellText(java.util.List<TableCell> cells, int index, boolean withTrackedOffset, boolean isHeader, int width, CellAlignment alignment, Ref<java.lang.Integer> delta)
void
deleteColumns(int column, int count)
void
deleteRows(int rowIndex, int count)
void
fillMissingColumns()
void
fillMissingColumns(java.lang.Integer minColumn)
void
finalizeTable()
private @Nullable TrackedOffset
findTrackedOffset(int offset)
void
forAllBodyRows(int startIndex, int count, TableRowManipulator manipulator)
void
forAllBodyRows(int startIndex, TableRowManipulator manipulator)
void
forAllBodyRows(TableRowManipulator manipulator)
void
forAllContentRows(int startIndex, int count, TableRowManipulator manipulator)
void
forAllContentRows(int startIndex, TableRowManipulator manipulator)
void
forAllContentRows(TableRowManipulator manipulator)
void
forAllHeaderRows(int startIndex, int count, TableRowManipulator manipulator)
void
forAllHeaderRows(int startIndex, TableRowManipulator manipulator)
void
forAllHeaderRows(TableRowManipulator manipulator)
void
forAllRows(int startIndex, int count, TableRowManipulator manipulator)
void
forAllRows(int startIndex, TableRowManipulator manipulator)
void
forAllRows(TableRowManipulator manipulator)
void
forAllSectionRows(int startIndex, int count, TableRowManipulator manipulator)
void
forAllSectionRows(int startIndex, TableRowManipulator manipulator)
void
forAllSectionRows(TableRowManipulator manipulator)
private void
forAllSectionsRows(int startIndex, int count, TableSection[] sections, TableRowManipulator manipulator)
static java.lang.String
formattedCaption(BasedSequence caption, TableFormatOptions options)
java.util.List<TableRow>
getAllContentRows()
int
getAllContentRowsCount()
java.util.List<TableRow>
getAllRows()
int
getAllRowsCount()
TableSection
getAllRowsSection(int index)
java.util.List<TableRow>
getAllSectionRows()
private java.util.List<TableRow>
getAllSectionsRows(TableSection... sections)
int
getAllSectionsRowsCount()
int
getBodyRowCount()
BasedSequence
getCaption()
TableCell
getCaptionCell()
int
getCaptionRowCount()
TableCellOffsetInfo
getCellOffsetInfo(int offset)
java.lang.CharSequence
getFormatTableIndentPrefix()
boolean
getHaveCaption()
boolean
getHeader()
int
getHeadingRowCount()
int
getMaxBodyColumns()
int
getMaxColumns()
int
getMaxColumnsWithoutColumns(boolean withSeparator, int... skipColumns)
int
getMaxColumnsWithoutRows(boolean withSeparator, int... skipRows)
int
getMaxHeadingColumns()
int
getMaxSeparatorColumns()
int
getMinColumns()
int
getMinColumnsWithoutColumns(boolean withSeparator, int... skipColumns)
int
getMinColumnsWithoutRows(boolean withSeparator, int... skipRows)
int
getSeparatorRowCount()
java.lang.CharSequence
getTableChars()
int
getTableStartOffset()
@Nullable TrackedOffset
getTrackedOffset(int offset)
int
getTrackedOffsetIndex(int offset)
@NotNull java.util.List<TrackedOffset>
getTrackedOffsets()
void
insertColumns(int column, int count)
void
insertRows(int rowIndex, int count)
private void
insertRows(java.util.ArrayList<TableRow> rows, int index, int count, int maxColumns)
boolean
isAllRowsEmptyAt(int rowIndex)
Test a row for having all empty columnsboolean
isAllRowsSeparator(int index)
boolean
isContentRowsEmptyAt(int rowIndex)
Test a row for having all empty columnsboolean
isEmptyColumn(int column)
Test all rows for having given column empty.private boolean
isEmptyRowAt(int rowIndex, TableSection[] sections)
Test a row for having all empty columnsboolean
isSeparator()
void
moveColumn(int fromColumn, int toColumn)
void
nextRow()
void
normalize()
private boolean
pipeNeedsSpaceAfter(TableCell cell)
private boolean
pipeNeedsSpaceBefore(TableCell cell)
void
setBody()
void
setCaption(java.lang.CharSequence caption)
void
setCaptionCell(TableCell captionCell)
void
setCaptionWithMarkers(Node tableCellNode, java.lang.CharSequence captionOpen, java.lang.CharSequence caption, java.lang.CharSequence captionClose)
void
setFormatTableIndentPrefix(java.lang.CharSequence formatTableIndentPrefix)
void
setHeader()
void
setHeader(boolean header)
void
setSeparator()
void
setSeparator(boolean separator)
private boolean
setTrackedOffsetIndex(int offset, int index)
MarkdownTable
sorted(ColumnSort[] columnSorts, int textCollectionFlags, @Nullable NumericSuffixPredicate numericSuffixTester)
Sort tableprivate int
spanFixedWidth(java.util.BitSet unfixedColumns, int col, int columnSpan)
private int
spanWidth(int col, int columnSpan)
java.lang.String
toString()
MarkdownTable
transposed(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:
toString
in classjava.lang.Object
-
-