APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.org.commonmark.renderer.markdown

public Class MarkdownWriter

extends Object
Class Inheritance
Imports
jdk.internal.org.commonmark.text.CharMatcher, java.io.IOException, java.util.LinkedList

Writer for Markdown (CommonMark) text.

Field Summary

Modifier and TypeField and Description
private boolean
private int
private final Appendable
private char
private final LinkedList<String>
private final LinkedList<CharMatcher>
private final LinkedList<Boolean>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
append(char c, CharMatcher escape)

public void
block()

Enqueue a block separator to be written before the next text is written.

private void
flushBlockSeparator()

If a block separator has been enqueued with block() but not yet written, write it now.

public char
getLastChar()

Returns: the last character that was written

public boolean
isAtLineStart()

Returns: whether we're at the line start (not counting any prefixes), i.e. after a line or block.

private boolean
public void
line()

Write a newline (line terminator).

private boolean
needsEscaping(char c, CharMatcher escape)

public void
popPrefix()

Remove the last prefix from the top of the stack.

public void
popRawEscape()

Remove the last raw escape from the top of the stack.

public void
popTight()

Remove the last "tight" setting from the top of the stack.

public void
pushPrefix(String
the raw prefix string
prefix
)

Push a prefix onto the top of the stack.

public void
pushRawEscape(CharMatcher
the characters to escape in raw text
rawEscape
)

Escape the characters matching the supplied matcher, in all text (text and raw).

public void
pushTight(boolean tight)

Change whether blocks are tight or loose.

public void
raw(String s)

Write the supplied string (raw/unescaped except if pushRawEscape was used).

public void
raw(char c)

Write the supplied character (raw/unescaped except if pushRawEscape was used).

private boolean
public void
text(String
the string to write
s
,
CharMatcher
which characters to escape
escape
)

Write the supplied string with escaping.

private void
private void
write(char c)

public void
writePrefix(String
the raw prefix string to write
prefix
)

Write a prefix.

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

atLineStartback to summary
private boolean atLineStart
blockSeparatorback to summary
private int blockSeparator
bufferback to summary
private final Appendable buffer
lastCharback to summary
private char lastChar
prefixesback to summary
private final LinkedList<String> prefixes
rawEscapesback to summary
private final LinkedList<CharMatcher> rawEscapes
tightback to summary
private final LinkedList<Boolean> tight

Constructor Detail

MarkdownWriterback to summary
public MarkdownWriter(Appendable out)

Method Detail

appendback to summary
private void append(char c, CharMatcher escape) throws IOException
blockback to summary
public void block()

Enqueue a block separator to be written before the next text is written. Block separators are not written straight away because if there are no more blocks to write we don't want a separator (at the end of the document).

flushBlockSeparatorback to summary
private void flushBlockSeparator()

If a block separator has been enqueued with block() but not yet written, write it now.

getLastCharback to summary
public char getLastChar()
Returns:char

the last character that was written

isAtLineStartback to summary
public boolean isAtLineStart()
Returns:boolean

whether we're at the line start (not counting any prefixes), i.e. after a line or block.

isTightback to summary
private boolean isTight()
lineback to summary
public void line()

Write a newline (line terminator).

needsEscapingback to summary
private boolean needsEscaping(char c, CharMatcher escape)
popPrefixback to summary
public void popPrefix()

Remove the last prefix from the top of the stack.

popRawEscapeback to summary
public void popRawEscape()

Remove the last raw escape from the top of the stack.

popTightback to summary
public void popTight()

Remove the last "tight" setting from the top of the stack.

pushPrefixback to summary
public void pushPrefix(String prefix)

Push a prefix onto the top of the stack. All prefixes are written at the beginning of each line, until the prefix is popped again.

Parameters
prefix:String

the raw prefix string

pushRawEscapeback to summary
public void pushRawEscape(CharMatcher rawEscape)

Escape the characters matching the supplied matcher, in all text (text and raw). This might be useful to extensions that add another layer of syntax, e.g. the tables extension that uses `|` to separate cells and needs all `|` characters to be escaped (even in code spans).

Parameters
rawEscape:CharMatcher

the characters to escape in raw text

pushTightback to summary
public void pushTight(boolean tight)

Change whether blocks are tight or loose. Loose is the default where blocks are separated by a blank line. Tight is where blocks are not separated by a blank line. Tight blocks are used in lists, if there are no blank lines within the list.

Note that changing this does not affect block separators that have already been enqueued with block(), only future ones.

rawback to summary
public void raw(String s)

Write the supplied string (raw/unescaped except if pushRawEscape was used).

rawback to summary
public void raw(char c)

Write the supplied character (raw/unescaped except if pushRawEscape was used).

rawNeedsEscapingback to summary
private boolean rawNeedsEscaping(char c)
textback to summary
public void text(String s, CharMatcher escape)

Write the supplied string with escaping.

Parameters
s:String

the string to write

escape:CharMatcher

which characters to escape

writeback to summary
private void write(String s, CharMatcher escape)
writeback to summary
private void write(char c)
writePrefixback to summary
public void writePrefix(String prefix)

Write a prefix.

Parameters
prefix:String

the raw prefix string to write

writePrefixesback to summary
private void writePrefixes()