public abstract class MarkdownBuilder<T extends MarkdownBuilder<T,S>,S extends MarkdownElement> extends java.lang.Object implements MarkdownSerializable
MarkdownElement.| Modifier and Type | Field and Description |
|---|---|
protected S |
markdownElement
The root element that content will be appended too.
|
protected MarkdownBuilder |
parentBuilder
The parent markdown builder, if available.
|
| Modifier | Constructor and Description |
|---|---|
|
MarkdownBuilder() |
protected |
MarkdownBuilder(MarkdownBuilder parentBuilder) |
| Modifier and Type | Method and Description |
|---|---|
T |
append(MarkdownSerializable value)
Attempts to serialize the specified value to markdown and appends
it to the existing root
markdownElement. |
abstract T |
append(java.lang.Object value)
Attempts to append the specified value to the existing root
markdownElement. |
MarkdownBuilder |
begin(MarkdownBuilder markdownBuilder)
All chained method calls will be called on the passed 'child' builder
until
end() will be called. |
CodeBlockBuilder |
beginCodeBlock()
Creates a new
CodeBlockBuilder instance. |
CodeBlockBuilder |
beginCodeBlock(java.lang.String language)
Creates a new
CodeBlockBuilder instance and sets the language. |
ListBuilder |
beginList()
Creates a new
ListBuilder instance. |
QuoteBuilder |
beginQuote()
Creates a new
QuoteBuilder instance. |
T |
bold(java.lang.Object value)
Appends a
BoldText element to the root markdownElement. |
S |
build()
Returns the root
markdownElement |
T |
code(java.lang.Object value)
Appends a
Code element to the root markdownElement. |
protected abstract S |
createMarkdownElement()
Creates the root element.
|
MarkdownBuilder |
end()
If a
parentBuilder is set (e.g. |
protected boolean |
endsWithLineSeparators(int count)
Checks if the root
markdownElement ends with
the specified number of new lines |
protected abstract T |
getBuilder()
Used for method chaining.
|
MarkdownBuilder |
getParentBuilder() |
T |
heading(java.lang.String value)
Appends a
Heading element with level 1 to the root markdownElement. |
T |
heading(java.lang.String value,
int level)
Appends a
Heading element to the root markdownElement. |
T |
image(java.lang.String url)
Appends an
Image element to the root markdownElement. |
T |
image(java.lang.String text,
java.lang.String url)
Appends an
Image element to the root markdownElement. |
T |
italic(java.lang.Object value)
Appends an
ItalicText element to the root markdownElement. |
T |
link(java.lang.String url)
Appends a
Link element to the root markdownElement. |
T |
link(java.lang.String text,
java.lang.String url)
Appends a
Link element to the root markdownElement. |
T |
newLine()
Appends a new line to the existing root
markdownElement. |
T |
newLines(int count)
Appends a new line to the existing root
markdownElement
if it not already ends with a new line. |
protected T |
newLinesIfRequired(int count)
Appends the specified number of new lines to the existing root
markdownElement if it not already ends with a new line. |
T |
newParagraph()
Appends two new lines to the existing root
markdownElement. |
protected T |
newParagraphIfRequired()
Appends two new lines to the existing root
markdownElement
if it not already ends with two new lines. |
T |
progress(double progress)
Appends a
ProgressBar element to the root markdownElement. |
T |
progressWithLabel(double progress)
Appends a
ProgressBar element with a value label to the root markdownElement. |
T |
quote(java.lang.String value)
Appends a
Quote element to the root markdownElement. |
T |
rule()
Appends a
HorizontalRule element to the root markdownElement. |
T |
rule(int length)
Appends a
HorizontalRule element to the root markdownElement. |
void |
setParentBuilder(MarkdownBuilder parentBuilder) |
T |
strikeThrough(java.lang.Object value)
Appends a
StrikeThroughText element to the root markdownElement. |
T |
subHeading(java.lang.String value)
Appends a
Heading element with level 2 to the root markdownElement. |
T |
taskList(TaskListItem... items)
Appends a
TaskList element to the root markdownElement. |
T |
text(java.lang.Object value)
Appends a normal
Text element to the root markdownElement. |
MarkdownElement |
toMarkdownElement() |
java.lang.String |
toString() |
T |
unorderedList(java.lang.Object... items)
Appends a
UnorderedList element to the root markdownElement. |
protected S extends MarkdownElement markdownElement
protected MarkdownBuilder parentBuilder
begin(MarkdownBuilder) method.
If set, this will be returned in the end() method.public MarkdownBuilder()
protected MarkdownBuilder(MarkdownBuilder parentBuilder)
protected abstract T getBuilder()
protected abstract S createMarkdownElement()
public MarkdownBuilder begin(MarkdownBuilder markdownBuilder)
end() will be called.markdownBuilder - the new builder which should be usedpublic MarkdownBuilder end()
parentBuilder is set (e.g. if
begin(MarkdownBuilder) was called before),
the current markdownElement will be appended
to the parent builder, which will also be returned.public T text(java.lang.Object value)
Text element to the root markdownElement.value - value for the new elementText.Text(Object)public T bold(java.lang.Object value)
BoldText element to the root markdownElement.value - value for the new elementBoldText.BoldText(Object)public T italic(java.lang.Object value)
ItalicText element to the root markdownElement.value - value for the new elementItalicText.ItalicText(Object)public T strikeThrough(java.lang.Object value)
StrikeThroughText element to the root markdownElement.value - value for the new elementStrikeThroughText.StrikeThroughText(Object)public T heading(java.lang.String value, int level)
Heading element to the root markdownElement.value - value for the new elementlevel - the heading levelHeading.Heading(Object, int)public T heading(java.lang.String value)
Heading element with level 1 to the root markdownElement.value - value for the new elementHeading.Heading(Object, int)public T subHeading(java.lang.String value)
Heading element with level 2 to the root markdownElement.value - value for the new elementHeading.Heading(Object, int)public T rule()
HorizontalRule element to the root markdownElement.HorizontalRule.HorizontalRule()public T rule(int length)
HorizontalRule element to the root markdownElement.HorizontalRule.HorizontalRule(int)public T link(java.lang.String text, java.lang.String url)
Link element to the root markdownElement.text - text for the linkurl - url for the linkLink.Link(Object, String)public T link(java.lang.String url)
Link element to the root markdownElement.url - url for the linkLink.Link(String)public T image(java.lang.String text, java.lang.String url)
Image element to the root markdownElement.text - text for the imageurl - url to the imageImage.Image(Object, String)public T image(java.lang.String url)
Image element to the root markdownElement.url - url to the imageImage.Image(String)public T progress(double progress)
ProgressBar element to the root markdownElement.progress - progress value ranging from 0 to 1ProgressBar.ProgressBar(double)public T progressWithLabel(double progress)
ProgressBar element with a value label to the root markdownElement.progress - progress value ranging from 0 to 1ProgressBar.ProgressBar(double)public QuoteBuilder beginQuote()
QuoteBuilder instance.QuoteBuilder.QuoteBuilder(MarkdownBuilder)public T quote(java.lang.String value)
Quote element to the root markdownElement.value - value for the elementQuote.Quote(Object)public CodeBlockBuilder beginCodeBlock(java.lang.String language)
CodeBlockBuilder instance and sets the language.language - the code language for syntax highlightingCodeBlockBuilder.CodeBlockBuilder(MarkdownBuilder, String)public CodeBlockBuilder beginCodeBlock()
CodeBlockBuilder instance.CodeBlockBuilder.CodeBlockBuilder(MarkdownBuilder)public T code(java.lang.Object value)
Code element to the root markdownElement.value - value for the new elementCode.Code(Object)public ListBuilder beginList()
ListBuilder instance.ListBuilder.ListBuilder(MarkdownBuilder)public T unorderedList(java.lang.Object... items)
UnorderedList element to the root markdownElement.items - elements that should be list itemsUnorderedList.UnorderedList(List)public T taskList(TaskListItem... items)
TaskList element to the root markdownElement.items - elements that should be task itemsTaskList.TaskList(List)public abstract T append(java.lang.Object value)
markdownElement.value - value to be appendedpublic T append(MarkdownSerializable value)
markdownElement.value - value to be appendedpublic T newParagraph()
markdownElement.protected T newParagraphIfRequired()
markdownElement
if it not already ends with two new lines.public T newLine()
markdownElement.public T newLines(int count)
markdownElement
if it not already ends with a new line.protected T newLinesIfRequired(int count)
markdownElement if it not already ends with a new line.count - number of new lines to be appendedprotected boolean endsWithLineSeparators(int count)
markdownElement ends with
the specified number of new linescount - number of new linespublic java.lang.String toString()
toString in class java.lang.Objectpublic MarkdownElement toMarkdownElement() throws MarkdownSerializationException
toMarkdownElement in interface MarkdownSerializableMarkdownSerializationExceptionpublic S build()
markdownElementmarkdownElementpublic MarkdownBuilder getParentBuilder()
public void setParentBuilder(MarkdownBuilder parentBuilder)