Class InlineElement

java.lang.Object
org.tealeaf.javamarkdown.MarkdownElement
org.tealeaf.javamarkdown.types.InlineElement
Direct Known Subclasses:
Link, Markup

public abstract class InlineElement extends MarkdownElement
A base type for any element that can be inserted within a sentence, such as simple markups or similar items.
Since:
0.0.11
Author:
Thomas Kwashnak
  • Constructor Details

    • InlineElement

      public InlineElement()
  • Method Details

    • checkType

      protected <T> T checkType(T object)

      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
      Throws IllegalContentsException if object is instance of the same class (such as an Italic within an Italic)
      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
      Since:
      0.0.11
    • 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:
      false
      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:
      false
      Since:
      0.0.19