Class MarkdownElement
- Direct Known Subclasses:
InlineElement,Structure
- Since:
- 0.0.8
- Author:
- Thomas Kwashnak
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract StringasString()Formats the element to a stringasString(boolean newLineBefore) Formats the element to a string, including required new-lines as neededprotected abstract <T> TcheckType(T item) Checks the type of a passed object.abstract booleanWhether a new line should be added after inserting the element into a document.abstract booleanWhether the element requires at least one\nbefore printing itself in a document<T extends Appendable>
TtoAppendable(T appendable) Outputs the MarkdownElement into an appendable classtoString()Prints the compiled string representation of the element<T extends Writer>
TtoWriter(T writer) Writes the formatted item to a Writer
-
Constructor Details
-
MarkdownElement
public MarkdownElement()
-
-
Method Details
-
toWriter
Writes the formatted item to a Writer- Type Parameters:
T- The base type of the writer used. This type must extendWriter- Parameters:
writer- Writer to write contents to- Returns:
- The writer passed in the parameters
- Throws:
IOException- If any exceptions were thrown during writing- Since:
- 0.0.8
-
toAppendable
Outputs the MarkdownElement into an appendable class- Type Parameters:
T- The type of appendable. This type must implement theAppendableinterface- Parameters:
appendable- The appendable object to write this element to- Returns:
- The appendable object passed in as the parameter
- Throws:
IOException- If any exceptions were thrown during appending- Since:
- 0.0.21
-
asString
Formats the element to a string- Returns:
- String representation of the formatted item
- Since:
- 0.0.8
-
toString
Prints the compiled string representation of the element
Uses the
asString()to compile -
requiresNewlineBefore
public abstract boolean requiresNewlineBefore()Whether the element requires at least one
\nbefore printing itself in a documentIn instances such as in-line elements (like
Bold), this would returnfalsebecause bolds can be inserted directly in-line. However, in instances such asNumberedList, it would be required that there is a new line to prevent the followingSome sentence - item 1 - item 2 - item 3and instead print the following
Some sentence - item 1 - item 2This method is natively used in
MarkdownWriter.appendMarkdownElement(MarkdownElement)to handle adding newlines when necessary- Returns:
trueif element requires a new line beforehand,falseotherwise- Since:
- 0.0.8
-
requiresNewlineAfter
public abstract boolean requiresNewlineAfter()Whether a new line should be added after inserting the element into a document. This is particularly useful for structures that need to have a newline after it gets rendered
For example, if some text was printed immediately after a list, it would render as:
- item 1 - item 2 - item 3some textThus, by requiring a new line after the element is rendered, we get the following output instead:
- item 1 - item 2 - item 3 some textThis method is natively used in
MarkdownWriter.appendMarkdownElement(MarkdownElement)to handle adding newlines when necessary- Returns:
trueif element requires a new line after,falseotherwise- Since:
- 0.0.8
-
checkType
Checks the type of a passed object. This method is specific to each element and throws an
IllegalContentsExceptionif the passed object cannot be put in as a content of that element. This prevents instances such as nested tables, where a table is put inside another table. If such feature is necessary, using thetoString()of any markdown element will force it to be accepted in any spot- Type Parameters:
T- The type of the item- Parameters:
item- The item to check it's class- Returns:
- That item if it is not an instance of any illegal types
- Throws:
IllegalContentsException- if the object passed is an illegal type for the element- Since:
- 0.0.11
-
asString
Formats the element to a string, including required new-lines as needed
- Parameters:
newLineBefore- Whether or not there is a new line directly before printing this element- Returns:
- The string representation of this element, adapting to whether or not there is a newline directly before
- Since:
- 0.0.21
-