MishkaDocument.ContentText (Mishka Document v0.0.1)

Copy Markdown View Source

The text a page's or a note's HTML content reads as, without its markup: what its card, its row and its drafts preview, what its words are counted in, and what its search description is cut from (MishkaDocument.Plugins.PageSeo).

Every tag reads as a space, so two paragraphs stay two words apart, and the entities the sanitizer writes are read back.

iex> MishkaDocument.ContentText.text(~s(<p dir="auto">Tom &amp; Jerry</p><p>ran</p>))
"Tom & Jerry ran"

Summary

Functions

The first length characters of text/1; nil when the content reads as nothing.

html without its tags, its entities read and its whitespace run into single spaces, on one line. "" for no content.

How many words text/1 holds.

Functions

preview(html, length)

@spec preview(term(), pos_integer()) :: String.t() | nil

The first length characters of text/1; nil when the content reads as nothing.

iex> MishkaDocument.ContentText.preview("<p>Getting started</p>", 7)
"Getting"

iex> MishkaDocument.ContentText.preview("<p> </p>", 7)
nil

text(html)

@spec text(term()) :: String.t()

html without its tags, its entities read and its whitespace run into single spaces, on one line. "" for no content.

iex> MishkaDocument.ContentText.text(nil)
""

word_count(html)

@spec word_count(term()) :: non_neg_integer()

How many words text/1 holds.

iex> MishkaDocument.ContentText.word_count(~s(<p dir="auto">One two</p><p>three</p>))
3