Skip to content

Markdown Formatter

Vladimir Schneider edited this page Jan 28, 2017 · 19 revisions

The flexmark-formatter module renders the AST as markdown with various formatting options to clean up and make the source consistent. This also comes with an API to allow extensions to provide formatting options and and handle rendering of markdown for custom nodes.

The Formatter class is a renderer that outputs markdown and formats it to specified options. Use it in place of HtmlRenderer to get formatted markdown.

  • FORMATTER_EMULATION_PROFILE: default Parser.PARSER_EMULATION_PROFILE, emulation profile to use for formatting. Can be used to change indenting rules from the ones used by the parser.

  • MAX_BLANK_LINES: default 2, maximum number of blank lines to keep in the file

  • MAX_TRAILING_BLANK_LINES: default 1, maximum trailing blank lines in file

  • SPACE_AFTER_ATX_MARKER: default DiscretionaryText.ADD, handling of space after atx marker

  • SETEXT_HEADER_EQUALIZE_MARKER: default true, when true equalizes the setext marker to header text length

  • ATX_HEADER_TRAILING_MARKER: default EqualizeTrailingMarker.AS_IS, trailing atx # markers:

    • AS_IS: do nothing
    • ADD: add the same number of # as opening marker
    • EQUALIZE: add the same number of # as opening marker
    • REMOVE: remove
  • THEMATIC_BREAK: default (String)null, string to use for thematic break. null means leave as is.

  • BLOCK_QUOTE_MARKERS: default BlockQuoteMarker.AS_IS

    • AS_IS: no change, first line marker is propagated to full block quote content
    • ADD_COMPACT: use > and >>..>> for nested block quotes
    • ADD_COMPACT_WITH_SPACE: use > and >>..>> for nested block quotes
    • ADD_SPACED: use > and > > ..> > for nested block quotes
  • INDENTED_CODE_MINIMIZE_INDENT: default false, when true will remove extra indent common to all content lines

  • FENCED_CODE_MINIMIZE_INDENT: default false, when true will remove extra indent common to all content lines

  • FENCED_CODE_MATCH_CLOSING_MARKER: default false, when true opening marker will be used for closing marker

  • FENCED_CODE_SPACE_BEFORE_INFO: default false, when true a space will be added between open marker and info string

  • FENCED_CODE_MARKER_LENGTH: default 3, minimum code fence marker length

  • FENCED_CODE_MARKER_TYPE: default CodeFenceMarker.ANY,

    • ANY: no change, whatever is used
    • BACK_TICK: change to back ticks
    • TILDE: change to ~
  • LIST_ADD_BLANK_LINE_BEFORE: default false, when true will add a blank line before the first list item if it follows a paragraph

  • LIST_RENUMBER_ITEMS: default true, when true renumbers the ordered list items

  • LIST_BULLET_MARKER: default ListBulletMarker.ANY,

    • ANY: no change
    • DASH: change all to -
    • ASTERISK: change all to *
    • PLUS: change all to +
  • LIST_NUMBERED_MARKER: default ListNumberedMarker.ANY,

    • ANY: no change
    • DOT: change all to .
    • PAREN: change all to )
  • LIST_SPACING: default ListSpacing.AS_IS,

    • AS_IS: no change
    • LOOSEN: loose if has loose item
    • TIGHTEN: tight if has tight item
    • LOOSE: always loose
    • TIGHT: always tight
  • REFERENCE_PLACEMENT: default ElementPlacement.AS_IS,

    • AS_IS: no change
    • DOCUMENT_TOP: put all references at top of document
    • GROUP_WITH_FIRST: group all with first reference
    • GROUP_WITH_LAST: group all with last reference
    • DOCUMENT_BOTTOM: document bottom
  • REFERENCE_SORT: default ElementPlacementSort.AS_IS,

    • AS_IS: no change
    • SORT: sort in alphabetical order by reference text
    • SORT_UNUSED_LAST: sort in alphabetical order by reference text, put unreferenced ones last
  • KEEP_IMAGE_LINKS_AT_START: default false, when true image links will always be wrapped to be the first non space on the line

  • KEEP_EXPLICIT_LINKS_AT_START: default false, when true image links will always be wrapped to be the first non space on the line

Clone this wiki locally