Class Structure

java.lang.Object
org.tealeaf.javamarkdown.MarkdownElement
org.tealeaf.javamarkdown.types.Structure
Direct Known Subclasses:
CodeBlock, Header, ListStructure, Table

public abstract class Structure extends MarkdownElement

A base class for any MarkdownElement that formats its contents into a structure-syntax, such as tables or lists. This usually indicates that this Markdown Element can't inserted within another Markdown Element

Since:
0.0.7
Author:
Thomas Kwashnak
  • Constructor Details

    • Structure

      public Structure()
  • Method Details

    • checkType

      protected <T> T checkType(T object) throws IllegalContentsException

      Checks the type of a passed object. This method is specific to each element and throws an IllegalContentsException if 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 the MarkdownElement.toString() of any markdown element will force it to be accepted in any spot

      Throws IllegalContentsException if object is an instance of the Structure class
      Specified by:
      checkType in class MarkdownElement
      Type Parameters:
      T - The type of the item
      Parameters:
      object - 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.7
    • requiresNewlineAfter

      public 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 text
       

      Thus, by requiring a new line after the element is rendered, we get the following output instead:

           - item 1
           - item 2
           - item 3
           some text
       

      This method is natively used in MarkdownWriter.appendMarkdownElement(MarkdownElement) to handle adding newlines when necessary

      Specified by:
      requiresNewlineAfter in class MarkdownElement
      Returns:
      true
      Since:
      0.0.19
    • requiresNewlineBefore

      public boolean requiresNewlineBefore()

      Whether the element requires at least one \n before printing itself in a document

      In instances such as in-line elements (like Bold), this would return false because bolds can be inserted directly in-line. However, in instances such as NumberedList, it would be required that there is a new line to prevent the following

           Some sentence - item 1
           - item 2
           - item 3
       

      and instead print the following

           Some sentence
           - item 1
           - item 2
       

      This method is natively used in MarkdownWriter.appendMarkdownElement(MarkdownElement) to handle adding newlines when necessary

      Specified by:
      requiresNewlineBefore in class MarkdownElement
      Returns:
      true
      Since:
      0.0.19