Class Formatter

java.lang.Object
com.vladsch.flexmark.formatter.Formatter
All Implemented Interfaces:
IRender

public class Formatter extends 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 Details

    • EMPTY_DOCUMENTS

      public static final Document[] EMPTY_DOCUMENTS
    • FORMAT_FLAGS

      public static final DataKey<Integer> FORMAT_FLAGS
      output control for FormattingAppendable, see LineAppendable.setOptions(int)
    • 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<Boolean> GENERATE_HEADER_ID
    • MAX_BLANK_LINES

      public static final DataKey<Integer> MAX_BLANK_LINES
    • MAX_TRAILING_BLANK_LINES

      public static final DataKey<Integer> MAX_TRAILING_BLANK_LINES
    • RIGHT_MARGIN

      public static final DataKey<Integer> RIGHT_MARGIN
    • APPLY_SPECIAL_LEAD_IN_HANDLERS

      public static final DataKey<Boolean> APPLY_SPECIAL_LEAD_IN_HANDLERS
    • ESCAPE_SPECIAL_CHARS

      public static final DataKey<Boolean> ESCAPE_SPECIAL_CHARS
    • ESCAPE_NUMBERED_LEAD_IN

      public static final DataKey<Boolean> ESCAPE_NUMBERED_LEAD_IN
    • UNESCAPE_SPECIAL_CHARS

      public static final DataKey<Boolean> UNESCAPE_SPECIAL_CHARS
    • SPACE_AFTER_ATX_MARKER

      public static final DataKey<DiscretionaryText> SPACE_AFTER_ATX_MARKER
    • SETEXT_HEADING_EQUALIZE_MARKER

      public static final DataKey<Boolean> SETEXT_HEADING_EQUALIZE_MARKER
    • ATX_HEADING_TRAILING_MARKER

      public static final DataKey<EqualizeTrailingMarker> ATX_HEADING_TRAILING_MARKER
    • HEADING_STYLE

      public static final DataKey<HeadingStyle> HEADING_STYLE
    • THEMATIC_BREAK

      public static final NullableDataKey<String> THEMATIC_BREAK
    • BLOCK_QUOTE_BLANK_LINES

      public static final DataKey<Boolean> BLOCK_QUOTE_BLANK_LINES
    • BLOCK_QUOTE_MARKERS

      public static final DataKey<BlockQuoteMarker> BLOCK_QUOTE_MARKERS
    • INDENTED_CODE_MINIMIZE_INDENT

      public static final DataKey<Boolean> INDENTED_CODE_MINIMIZE_INDENT
    • FENCED_CODE_MINIMIZE_INDENT

      public static final DataKey<Boolean> FENCED_CODE_MINIMIZE_INDENT
    • FENCED_CODE_MATCH_CLOSING_MARKER

      public static final DataKey<Boolean> FENCED_CODE_MATCH_CLOSING_MARKER
    • FENCED_CODE_SPACE_BEFORE_INFO

      public static final DataKey<Boolean> FENCED_CODE_SPACE_BEFORE_INFO
    • FENCED_CODE_MARKER_LENGTH

      public static final DataKey<Integer> FENCED_CODE_MARKER_LENGTH
    • FENCED_CODE_MARKER_TYPE

      public static final DataKey<CodeFenceMarker> FENCED_CODE_MARKER_TYPE
    • LIST_ADD_BLANK_LINE_BEFORE

      public static final DataKey<Boolean> LIST_ADD_BLANK_LINE_BEFORE
    • LIST_RENUMBER_ITEMS

      public static final DataKey<Boolean> LIST_RENUMBER_ITEMS
    • LIST_REMOVE_EMPTY_ITEMS

      public static final DataKey<Boolean> LIST_REMOVE_EMPTY_ITEMS
    • LIST_ALIGN_NUMERIC

      public static final DataKey<ElementAlignment> LIST_ALIGN_NUMERIC
    • LIST_RESET_FIRST_ITEM_NUMBER

      public static final DataKey<Boolean> LIST_RESET_FIRST_ITEM_NUMBER
    • LIST_BULLET_MARKER

      public static final DataKey<ListBulletMarker> LIST_BULLET_MARKER
    • LIST_NUMBERED_MARKER

      public static final DataKey<ListNumberedMarker> LIST_NUMBERED_MARKER
    • LIST_SPACING

      public static final DataKey<ListSpacing> LIST_SPACING
    • LISTS_ITEM_CONTENT_AFTER_SUFFIX

      public static final DataKey<Boolean> LISTS_ITEM_CONTENT_AFTER_SUFFIX
    • REFERENCE_PLACEMENT

      public static final DataKey<ElementPlacement> REFERENCE_PLACEMENT
    • REFERENCE_SORT

      public static final DataKey<ElementPlacementSort> REFERENCE_SORT
    • OPTIMIZED_INLINE_RENDERING

      public static final DataKey<Boolean> OPTIMIZED_INLINE_RENDERING
    • FORMAT_CHAR_WIDTH_PROVIDER

      public static final DataKey<CharWidthProvider> FORMAT_CHAR_WIDTH_PROVIDER
    • KEEP_HARD_LINE_BREAKS

      public static final DataKey<Boolean> KEEP_HARD_LINE_BREAKS
    • KEEP_SOFT_LINE_BREAKS

      public static final DataKey<Boolean> KEEP_SOFT_LINE_BREAKS
    • FORMATTER_ON_TAG

      public static final DataKey<String> FORMATTER_ON_TAG
    • FORMATTER_OFF_TAG

      public static final DataKey<String> FORMATTER_OFF_TAG
    • FORMATTER_TAGS_ENABLED

      public static final DataKey<Boolean> FORMATTER_TAGS_ENABLED
    • FORMATTER_TAGS_ACCEPT_REGEXP

      public static final DataKey<Boolean> FORMATTER_TAGS_ACCEPT_REGEXP
    • APPEND_TRANSFERRED_REFERENCES

      public static final DataKey<Boolean> APPEND_TRANSFERRED_REFERENCES
    • TRANSLATION_ID_FORMAT

      public static final DataKey<String> TRANSLATION_ID_FORMAT
    • TRANSLATION_HTML_BLOCK_PREFIX

      public static final DataKey<String> TRANSLATION_HTML_BLOCK_PREFIX
    • TRANSLATION_HTML_INLINE_PREFIX

      public static final DataKey<String> TRANSLATION_HTML_INLINE_PREFIX
    • TRANSLATION_EXCLUDE_PATTERN

      public static final DataKey<String> TRANSLATION_EXCLUDE_PATTERN
    • TRANSLATION_HTML_BLOCK_TAG_PATTERN

      public static final DataKey<String> TRANSLATION_HTML_BLOCK_TAG_PATTERN
    • TRANSLATION_HTML_INLINE_TAG_PATTERN

      public static final DataKey<String> TRANSLATION_HTML_INLINE_TAG_PATTERN
    • DOC_RELATIVE_URL

      public static final DataKey<String> DOC_RELATIVE_URL
    • DOC_ROOT_URL

      public static final DataKey<String> DOC_ROOT_URL
    • FORMATTER_EMULATION_PROFILE

      public static final DataKey<ParserEmulationProfile> FORMATTER_EMULATION_PROFILE
    • TRACKED_OFFSETS

      public static final DataKey<List<TrackedOffset>> TRACKED_OFFSETS
    • TRACKED_SEQUENCE

      public static final DataKey<BasedSequence> TRACKED_SEQUENCE
    • RESTORE_TRACKED_SPACES

      public static final DataKey<Boolean> RESTORE_TRACKED_SPACES
    • DOCUMENT_FIRST_PREFIX

      public static final DataKey<CharSequence> DOCUMENT_FIRST_PREFIX
    • DOCUMENT_PREFIX

      public static final DataKey<CharSequence> DOCUMENT_PREFIX
    • SETEXT_HEADER_EQUALIZE_MARKER

      @Deprecated public static final DataKey<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<String> FORMAT_TABLE_INDENT_PREFIX
      Deprecated.
      use TableFormatOptions instead
    • UNIQUIFICATION_MAP

      public static final DataKey<Map<String,String>> UNIQUIFICATION_MAP
    • ATTRIBUTE_UNIQUIFICATION_ID_MAP

      public static final DataKey<Map<String,String>> ATTRIBUTE_UNIQUIFICATION_ID_MAP
    • options

      private final DataHolder options
    • linkResolverFactories

      final List<LinkResolverFactory> linkResolverFactories
    • nodeFormatterFactories

      final List<NodeFormatterFactory> nodeFormatterFactories
    • idGeneratorFactory

      final HeaderIdGeneratorFactory idGeneratorFactory
    • NULL_ITERATOR

      private static final Iterator<Node> NULL_ITERATOR
    • NULL_ITERABLE

      public static final Iterable<Node> NULL_ITERABLE
  • Constructor Details

  • Method Details

    • calculateNodeFormatterFactories

      private static List<NodeFormatterFactory> calculateNodeFormatterFactories(List<NodeFormatterFactory> formatterFactories)
    • getTranslationHandler

      public TranslationHandler getTranslationHandler(TranslationHandlerFactory translationHandlerFactory, HtmlIdGeneratorFactory idGeneratorFactory)
    • getTranslationHandler

      public TranslationHandler getTranslationHandler(HtmlIdGeneratorFactory idGeneratorFactory)
    • getTranslationHandler

      public TranslationHandler getTranslationHandler()
    • getOptions

      @NotNull public @NotNull 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()
      Create a new builder for configuring an Formatter.
      Returns:
      a builder
    • 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 @NotNull Node node, @NotNull @NotNull 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 @NotNull Node node, @NotNull @NotNull 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 @NotNull String render(@NotNull @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, 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 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, 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, Appendable output)
      Render a node to the appendable
      Parameters:
      documents - node to render
      output - appendable to use for the output
    • mergeRender

      public void mergeRender(List<Document> documents, Appendable output)
    • mergeRender

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

      public String mergeRender(List<Document> documents, int maxTrailingBlankLines)
    • mergeRender

      public void mergeRender(List<Document> documents, 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, Appendable output, int maxTrailingBlankLines)