HtmlCompat

Added in 1.1.0

class HtmlCompat


Backwards compatible version of Html.

Summary

Constants

const Int

Flags for fromHtml: Separate block-level elements with line breaks (single newline character) in between.

const Int

Flags for fromHtml: Separate block-level elements with blank lines (two newline characters) in between.

const Int

Flag indicating that CSS color values should be used instead of those defined in Color.

const Int

Flag indicating that texts inside <blockquote> elements will be separated from other texts with one newline character by default.

const Int

Flag indicating that texts inside <div>elements will be separated from other texts with one newline character by default.

const Int

Flag indicating that texts inside <h1>~<h6> elements will be separated from other texts with one newline character by default.

const Int

Flag indicating that texts inside <ul> elements will be separated from other texts with one newline character by default.

const Int

Flag indicating that texts inside <li> elements will be separated from other texts with one newline character by default.

const Int

Flag indicating that texts inside <p> elements will be separated from other texts with one newline character by default.

const Int

Option for fromHtml: Wrap consecutive lines of text delimited by '\n' inside <p> elements.

const Int

Option for fromHtml: Wrap each line of text delimited by '\n' inside a <p> or a <li> element.

Public functions

java-static Spanned
fromHtml(source: String, flags: Int)

Invokes fromHtml on API 24 and newer, otherwise flags are ignored and fromHtml is used.

java-static Spanned
fromHtml(
    source: String,
    flags: Int,
    imageGetter: Html.ImageGetter?,
    tagHandler: Html.TagHandler?
)

Invokes fromHtml on API 24 or newer, otherwise flags are ignored and fromHtml is used.

java-static String
toHtml(text: Spanned, options: Int)

Invokes toHtml on API 24 or newer, otherwise options are ignored and toHtml is used.

Constants

FROM_HTML_MODE_COMPACT

Added in 1.1.0
const val FROM_HTML_MODE_COMPACT = 63: Int

Flags for fromHtml: Separate block-level elements with line breaks (single newline character) in between. This inverts the Spanned to HTML string conversion done with the option TO_HTML_PARAGRAPH_LINES_INDIVIDUAL.

FROM_HTML_MODE_LEGACY

Added in 1.1.0
const val FROM_HTML_MODE_LEGACY = 0: Int

Flags for fromHtml: Separate block-level elements with blank lines (two newline characters) in between. This is the legacy behavior prior to N.

FROM_HTML_OPTION_USE_CSS_COLORS

Added in 1.1.0
const val FROM_HTML_OPTION_USE_CSS_COLORS = 256: Int

Flag indicating that CSS color values should be used instead of those defined in Color.

FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE

Added in 1.1.0
const val FROM_HTML_SEPARATOR_LINE_BREAK_BLOCKQUOTE = 32: Int

Flag indicating that texts inside <blockquote> elements will be separated from other texts with one newline character by default.

FROM_HTML_SEPARATOR_LINE_BREAK_DIV

Added in 1.1.0
const val FROM_HTML_SEPARATOR_LINE_BREAK_DIV = 16: Int

Flag indicating that texts inside <div>elements will be separated from other texts with one newline character by default.

FROM_HTML_SEPARATOR_LINE_BREAK_HEADING

Added in 1.1.0
const val FROM_HTML_SEPARATOR_LINE_BREAK_HEADING = 2: Int

Flag indicating that texts inside <h1>~<h6> elements will be separated from other texts with one newline character by default.

FROM_HTML_SEPARATOR_LINE_BREAK_LIST

Added in 1.1.0
const val FROM_HTML_SEPARATOR_LINE_BREAK_LIST = 8: Int

Flag indicating that texts inside <ul> elements will be separated from other texts with one newline character by default.

FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM

Added in 1.1.0
const val FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM = 4: Int

Flag indicating that texts inside <li> elements will be separated from other texts with one newline character by default.

FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH

Added in 1.1.0
const val FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH = 1: Int

Flag indicating that texts inside <p> elements will be separated from other texts with one newline character by default.

TO_HTML_PARAGRAPH_LINES_CONSECUTIVE

Added in 1.1.0
const val TO_HTML_PARAGRAPH_LINES_CONSECUTIVE = 0: Int

Option for fromHtml: Wrap consecutive lines of text delimited by '\n' inside <p> elements. BulletSpans are ignored.

TO_HTML_PARAGRAPH_LINES_INDIVIDUAL

Added in 1.1.0
const val TO_HTML_PARAGRAPH_LINES_INDIVIDUAL = 1: Int

Option for fromHtml: Wrap each line of text delimited by '\n' inside a <p> or a <li> element. This allows ParagraphStyles attached to be encoded as CSS styles within the corresponding <p> or <li> element.

Public functions

fromHtml

Added in 1.1.0
java-static fun fromHtml(source: String, flags: Int): Spanned

Invokes fromHtml on API 24 and newer, otherwise flags are ignored and fromHtml is used.

fromHtml

Added in 1.1.0
java-static fun fromHtml(
    source: String,
    flags: Int,
    imageGetter: Html.ImageGetter?,
    tagHandler: Html.TagHandler?
): Spanned

Invokes fromHtml on API 24 or newer, otherwise flags are ignored and fromHtml is used.

toHtml

Added in 1.1.0
java-static fun toHtml(text: Spanned, options: Int): String

Invokes toHtml on API 24 or newer, otherwise options are ignored and toHtml is used.