scrivener_html_semi v2.0.0 Scrivener.HTML.Parse View Source

Link to this section Summary

Functions

Return default options.

Returns the raw data in order to generate the proper HTML for pagination.

Link to this section Functions

Return default options.

Link to this function

parse(page, options \\ [])

View Source

Returns the raw data in order to generate the proper HTML for pagination.

Default options

Default options are supplied as following:

[distance: 5, previous: "<<", next: ">>", first: true, last: true, ellipsis: {:safe, "&hellip;"}]
  • distance declares how many pages are shown. It is a positive integer.
  • previous and next declares text for previous and next buttons. Generally, they are string. Falsy values will remove them from output.
  • first and last declares whether show first or last page. Genrally, they are boolean values, but they can be strings, too.

Return value

Return value is a list of tuples. The tuple is in a {text, page_number} format where text is intended to be the text of the link and page_number is the page number it should go to.

Examples

iex> parse(%Scrivener.Page{total_pages: 10, page_number: 5}, [])
[
  {"<<", 4},
  {1, 1},
  {2, 2},
  {3, 3},
  {4, 4},
  {5, 5},
  {6, 6},
  {7, 7},
  {8, 8},
  {9, 9},
  {10, 10},
  {">>", 6}
]

iex> parse(%Scrivener.Page{total_pages: 15, page_number: 8}, first: "←", last: "→")
[
  {"<<", 7},
  {"←", 1},
  {:ellipsis, {:safe, "&hellip;"}},
  {3, 3},
  {4, 4},
  {5, 5},
  {6, 6},
  {7, 7},
  {8, 8},
  {9, 9},
  {10, 10},
  {11, 11},
  {12, 12},
  {13, 13},
  {:ellipsis, {:safe, "&hellip;"}},
  {"→", 15},
  {">>", 9}
]