Class Formatter

  • All Implemented Interfaces:
    IRender

    public class Formatter
    extends java.lang.Object
    implements IRender
    Renders a tree of nodes to Markdown.

    Start with the builder() method to configure the renderer. Example:

    
     Formatter formatter = Formatter.builder().build();
     formatter.render(node);
     
    • Field Detail

      • EMPTY_DOCUMENTS

        public static final Document[] EMPTY_DOCUMENTS
      • FORMAT_CONVERT_TABS

        @Deprecated
        public static final int FORMAT_CONVERT_TABS
        Deprecated.
      • FORMAT_COLLAPSE_WHITESPACE

        @Deprecated
        public static final int FORMAT_COLLAPSE_WHITESPACE
        Deprecated.
      • FORMAT_SUPPRESS_TRAILING_WHITESPACE

        @Deprecated
        public static final int FORMAT_SUPPRESS_TRAILING_WHITESPACE
        Deprecated.
      • FORMAT_ALL_OPTIONS

        @Deprecated
        public static final int FORMAT_ALL_OPTIONS
        Deprecated.
      • GENERATE_HEADER_ID

        public static final DataKey<java.lang.Boolean> GENERATE_HEADER_ID
      • MAX_BLANK_LINES

        public static final DataKey<java.lang.Integer> MAX_BLANK_LINES
      • MAX_TRAILING_BLANK_LINES

        public static final DataKey<java.lang.Integer> MAX_TRAILING_BLANK_LINES
      • RIGHT_MARGIN

        public static final DataKey<java.lang.Integer> RIGHT_MARGIN
      • APPLY_SPECIAL_LEAD_IN_HANDLERS

        public static final DataKey<java.lang.Boolean> APPLY_SPECIAL_LEAD_IN_HANDLERS
      • ESCAPE_SPECIAL_CHARS

        public static final DataKey<java.lang.Boolean> ESCAPE_SPECIAL_CHARS
      • ESCAPE_NUMBERED_LEAD_IN

        public static final DataKey<java.lang.Boolean> ESCAPE_NUMBERED_LEAD_IN
      • UNESCAPE_SPECIAL_CHARS

        public static final DataKey<java.lang.Boolean> UNESCAPE_SPECIAL_CHARS
      • SETEXT_HEADING_EQUALIZE_MARKER

        public static final DataKey<java.lang.Boolean> SETEXT_HEADING_EQUALIZE_MARKER
      • THEMATIC_BREAK

        public static final NullableDataKey<java.lang.String> THEMATIC_BREAK
      • BLOCK_QUOTE_BLANK_LINES

        public static final DataKey<java.lang.Boolean> BLOCK_QUOTE_BLANK_LINES
      • INDENTED_CODE_MINIMIZE_INDENT

        public static final DataKey<java.lang.Boolean> INDENTED_CODE_MINIMIZE_INDENT
      • FENCED_CODE_MINIMIZE_INDENT

        public static final DataKey<java.lang.Boolean> FENCED_CODE_MINIMIZE_INDENT
      • FENCED_CODE_MATCH_CLOSING_MARKER

        public static final DataKey<java.lang.Boolean> FENCED_CODE_MATCH_CLOSING_MARKER
      • FENCED_CODE_SPACE_BEFORE_INFO

        public static final DataKey<java.lang.Boolean> FENCED_CODE_SPACE_BEFORE_INFO
      • FENCED_CODE_MARKER_LENGTH

        public static final DataKey<java.lang.Integer> FENCED_CODE_MARKER_LENGTH
      • LIST_ADD_BLANK_LINE_BEFORE

        public static final DataKey<java.lang.Boolean> LIST_ADD_BLANK_LINE_BEFORE
      • LIST_RENUMBER_ITEMS

        public static final DataKey<java.lang.Boolean> LIST_RENUMBER_ITEMS
      • LIST_REMOVE_EMPTY_ITEMS

        public static final DataKey<java.lang.Boolean> LIST_REMOVE_EMPTY_ITEMS
      • LIST_RESET_FIRST_ITEM_NUMBER

        public static final DataKey<java.lang.Boolean> LIST_RESET_FIRST_ITEM_NUMBER
      • LISTS_ITEM_CONTENT_AFTER_SUFFIX

        public static final DataKey<java.lang.Boolean> LISTS_ITEM_CONTENT_AFTER_SUFFIX
      • KEEP_IMAGE_LINKS_AT_START

        public static final DataKey<java.lang.Boolean> KEEP_IMAGE_LINKS_AT_START
      • KEEP_EXPLICIT_LINKS_AT_START

        public static final DataKey<java.lang.Boolean> KEEP_EXPLICIT_LINKS_AT_START
      • OPTIMIZED_INLINE_RENDERING

        public static final DataKey<java.lang.Boolean> OPTIMIZED_INLINE_RENDERING
      • KEEP_HARD_LINE_BREAKS

        public static final DataKey<java.lang.Boolean> KEEP_HARD_LINE_BREAKS
      • KEEP_SOFT_LINE_BREAKS

        public static final DataKey<java.lang.Boolean> KEEP_SOFT_LINE_BREAKS
      • FORMATTER_ON_TAG

        public static final DataKey<java.lang.String> FORMATTER_ON_TAG
      • FORMATTER_OFF_TAG

        public static final DataKey<java.lang.String> FORMATTER_OFF_TAG
      • FORMATTER_TAGS_ENABLED

        public static final DataKey<java.lang.Boolean> FORMATTER_TAGS_ENABLED
      • FORMATTER_TAGS_ACCEPT_REGEXP

        public static final DataKey<java.lang.Boolean> FORMATTER_TAGS_ACCEPT_REGEXP
      • LINK_MARKER_COMMENT_PATTERN

        public static final NullableDataKey<java.util.regex.Pattern> LINK_MARKER_COMMENT_PATTERN
      • APPEND_TRANSFERRED_REFERENCES

        public static final DataKey<java.lang.Boolean> APPEND_TRANSFERRED_REFERENCES
      • TRANSLATION_ID_FORMAT

        public static final DataKey<java.lang.String> TRANSLATION_ID_FORMAT
      • TRANSLATION_HTML_BLOCK_PREFIX

        public static final DataKey<java.lang.String> TRANSLATION_HTML_BLOCK_PREFIX
      • TRANSLATION_HTML_INLINE_PREFIX

        public static final DataKey<java.lang.String> TRANSLATION_HTML_INLINE_PREFIX
      • TRANSLATION_AUTOLINK_PREFIX

        public static final DataKey<java.lang.String> TRANSLATION_AUTOLINK_PREFIX
      • TRANSLATION_EXCLUDE_PATTERN

        public static final DataKey<java.lang.String> TRANSLATION_EXCLUDE_PATTERN
      • TRANSLATION_HTML_BLOCK_TAG_PATTERN

        public static final DataKey<java.lang.String> TRANSLATION_HTML_BLOCK_TAG_PATTERN
      • TRANSLATION_HTML_INLINE_TAG_PATTERN

        public static final DataKey<java.lang.String> TRANSLATION_HTML_INLINE_TAG_PATTERN
      • DOC_RELATIVE_URL

        public static final DataKey<java.lang.String> DOC_RELATIVE_URL
      • DOC_ROOT_URL

        public static final DataKey<java.lang.String> DOC_ROOT_URL
      • DEFAULT_LINK_RESOLVER

        public static final DataKey<java.lang.Boolean> DEFAULT_LINK_RESOLVER
      • RESTORE_TRACKED_SPACES

        public static final DataKey<java.lang.Boolean> RESTORE_TRACKED_SPACES
      • DOCUMENT_FIRST_PREFIX

        public static final DataKey<java.lang.CharSequence> DOCUMENT_FIRST_PREFIX
      • DOCUMENT_PREFIX

        public static final DataKey<java.lang.CharSequence> DOCUMENT_PREFIX
      • SETEXT_HEADER_EQUALIZE_MARKER

        @Deprecated
        public static final DataKey<java.lang.Boolean> SETEXT_HEADER_EQUALIZE_MARKER
        Deprecated.
        use corrected name
      • ATX_HEADER_TRAILING_MARKER

        @Deprecated
        public static final DataKey<EqualizeTrailingMarker> ATX_HEADER_TRAILING_MARKER
        Deprecated.
        use corrected name
      • FORMAT_TABLE_CAPTION

        @Deprecated
        public static final DataKey<TableCaptionHandling> FORMAT_TABLE_CAPTION
        Deprecated.
        use TableFormatOptions instead
      • FORMAT_TABLE_CAPTION_SPACES

        @Deprecated
        public static final DataKey<DiscretionaryText> FORMAT_TABLE_CAPTION_SPACES
        Deprecated.
        use TableFormatOptions instead
      • FORMAT_TABLE_INDENT_PREFIX

        @Deprecated
        public static final DataKey<java.lang.String> FORMAT_TABLE_INDENT_PREFIX
        Deprecated.
        use TableFormatOptions instead
      • UNIQUIFICATION_MAP

        public static final DataKey<java.util.Map<java.lang.String,​java.lang.String>> UNIQUIFICATION_MAP
      • ATTRIBUTE_UNIQUIFICATION_ID_MAP

        public static final DataKey<java.util.Map<java.lang.String,​java.lang.String>> ATTRIBUTE_UNIQUIFICATION_ID_MAP
      • NULL_ITERABLE

        public static final java.lang.Iterable<Node> NULL_ITERABLE
    • Method Detail

      • getOptions

        @NotNull
        public DataHolder getOptions()
        Description copied from interface: IRender
        Get Options for parsing
        Specified by:
        getOptions in interface IRender
        Returns:
        DataHolder for options
      • builder

        public static Formatter.Builder builder​(DataHolder options)
        Create a new builder for configuring an Formatter.
        Parameters:
        options - initialization options
        Returns:
        a builder.
      • render

        public void render​(@NotNull
                           Node node,
                           @NotNull
                           java.lang.Appendable output)
        Render a node to the appendable

        NOTE: if Appendable is LineAppendable then its builder will be used as builder for the markdown text, else string sequence builder will be used

        Specified by:
        render in interface IRender
        Parameters:
        node - node to render
        output - appendable to use for the output
      • render

        public void render​(@NotNull
                           Node node,
                           @NotNull
                           java.lang.Appendable output,
                           int maxTrailingBlankLines)
        Render node

        NOTE: if Appendable is LineAppendable then its builder will be used as builder for the markdown text, else string sequence builder will be used

        Parameters:
        node - node to render
        output - appendable to which to render the resulting text
        maxTrailingBlankLines - max trailing blank lines in output, -1 means no last line EOL
      • render

        @NotNull
        public java.lang.String render​(@NotNull
                                       Node document)
        Render the tree of nodes to markdown
        Specified by:
        render in interface IRender
        Parameters:
        document - the root node
        Returns:
        the formatted markdown
      • translationRender

        public void translationRender​(Node document,
                                      java.lang.Appendable output,
                                      TranslationHandler translationHandler,
                                      RenderPurpose renderPurpose)
        Render a node to the appendable
        Parameters:
        document - node to render
        output - appendable to use for the output
      • translationRender

        public java.lang.String translationRender​(Node document,
                                                  TranslationHandler translationHandler,
                                                  RenderPurpose renderPurpose)
        Render the tree of nodes to markdown
        Parameters:
        document - the root node
        Returns:
        the formatted markdown
      • translationRender

        public void translationRender​(Node document,
                                      java.lang.Appendable output,
                                      int maxTrailingBlankLines,
                                      TranslationHandler translationHandler,
                                      RenderPurpose renderPurpose)
        Render a node to the appendable
        Parameters:
        document - node to render
        output - appendable to use for the output
      • mergeRender

        public void mergeRender​(Document[] documents,
                                java.lang.Appendable output)
        Render a node to the appendable
        Parameters:
        documents - node to render
        output - appendable to use for the output
      • mergeRender

        public void mergeRender​(java.util.List<Document> documents,
                                java.lang.Appendable output)
      • mergeRender

        public java.lang.String mergeRender​(Document[] documents,
                                            int maxTrailingBlankLines)
        Render the tree of nodes to markdown
        Parameters:
        documents - the root node
        Returns:
        the formatted markdown
      • mergeRender

        public java.lang.String mergeRender​(java.util.List<Document> documents,
                                            int maxTrailingBlankLines)
      • mergeRender

        public void mergeRender​(java.util.List<Document> documents,
                                java.lang.Appendable output,
                                int maxTrailingBlankLines)
        Render a node to the appendable
        Parameters:
        documents - nodes to merge render
        output - appendable to use for the output
      • mergeRender

        public void mergeRender​(Document[] documents,
                                java.lang.Appendable output,
                                int maxTrailingBlankLines)