-
Notifications
You must be signed in to change notification settings - Fork 275
LineAppendable
LineAppendableImpl
is a replacement for LineFormattingAppendable
intended to facilitate
creating line based, formatted output including keeping track of source offset information by
using SegmentedBuilder
for accumulating the output to SegmentedSequence
final result.
Formatting features include removing/adding prefix to each line as it is generated, collapsing spans of spaces to a single space, removing leading and/or trailing spaces of each line.
The implementation accumulates output as a list of lines. For each line the appendable keeps position for each line where its prefix end and line text begins.
On appending of an EOL the accumulated line is committed and added to the list of accumulated lines.
Line which is in the process of being accumulated is accumulated in its own SegmentBuilder
to
allow quick modification or regeneration of the line's text with minimal performance penalty.
Options define the behaviour of the appendable during output construction:
-
CONVERT_TABS
: expand tabs on column multiples of 4 -
COLLAPSE_WHITESPACE
: collapse multiple tabs and spaces to single space -
SUPPRESS_TRAILING_WHITESPACE
: don't output trailing whitespace -
PASS_THROUGH
: just pass everything through to appendable with no formatting -
ALLOW_LEADING_WHITESPACE
: allow leading spaces on a line, else remove -
ALLOW_LEADING_EOL
: allow EOL at offset 0 -
PREFIX_PRE_FORMATTED
: when prefixing lines, prefix pre-formatted lines
ℹ️ COLLAPSE_WHITESPACE
overrides CONVERT_TABS
because converted tags will
be converted to a space.
LineAppendable
tracks the length
and column
of the accumulating line to facilitate
formatting decisions by rendering code.
LineAppendable
provides methods to allow applying conditional formatting logic based on
accumulated output generated by child elements of a given node, specifically applying prefix
change only after an EOL is appended or registering callbacks when an EOL is appended.
It is also possible to modify the prefixes for lines, after they are constructed. However, the core renderers perform their activity without resorting to modifying the lines after they are committed.
Line prefix modification feature is used by Markdown Navigator plugin when accumulating text from JetBrains IDE parse tree which is not ideally suited for tracking parent prefixes.
For this purpose the LineAppendable
allows modifying the prefix end of each line as parent
prefixes are removed from the text.