Markwon/docs/docs/factory.md
2018-08-21 18:06:42 +03:00

1.3 KiB

Factory

SpannableFactory is used to create Span implementations.

SpannableConfiguration.builder(context)
        .factory(SpannableFactory)
        .build();

Markwon provides default SpannableFactoryDef implementation that is used by default.

Spans:

  • strongEmphasis
  • emphasis
  • blockQuote
  • code
  • orderedListItem
  • bulletListItem
  • thematicBreak
  • heading
  • strikethrough
  • taskListItem
  • tableRow
  • paragraph
  • image
  • link
  • superScript (HTML content only)
  • subScript (HTML content only)
  • underline (HTML content only)

:::tip SpannableFactory can be used to ignore some kinds of text markup. If, for example, you do not wish to apply emphasis styling to your final result, just return null from emphasis factory method:

@Nullable
@Override
public Object emphasis() {
    return null;
}

:::

:::tip All factory methods in SpannableFactory return an Object, but you can actually return an array of Objects if you wish to apply multiple Spans to a single styling node. For example, let's make all emphasis also red:

@Nullable
@Override
public Object emphasis() {
    return new Object[] {
            super.emphasis(),
            new ForegroundColorSpan(Color.RED)
    };
}

:::