Home

Awesome

Curtail

Build Status

HTML tag safe string truncation.

Installation

def deps do
  [ {:curtail, "~> 2.0"} ]
end

Usage

Options

* length (default: 100)
* omission (default: "...")
* word_boundary (default: "~r/\S/")
* break_token (default: nil)

Truncate using default options:

  iex> Curtail.truncate("<p>Truncate me!</p>")
  "<p>Truncate me!</p>"

Truncate with custom length:

  iex> Curtail.truncate("<p>Truncate me!</p>", length: 12)
  "<p>Truncate...</p>"

Truncate without omission string:

iex> Curtail.truncate("<p>Truncate me!</p>", omission: "", length: 8)
"<p>Truncate</p>"

Truncate with custom word_boundary:

iex> Curtail.truncate("<p>Truncate. Me!</p>", word_boundary: ~r/\S[\.]/, length: 12, omission: "")
"<p>Truncate.</p>"

Truncate without word boundary:

iex> Curtail.truncate("<p>Truncate me</p>", word_boundary: false, length: 7)
"<p>Trun...</p>"

Truncate with custom break_token:

iex> Curtail.truncate("<p>This should be truncated here<break_here>!!</p>", break_token: "<break_here>")
"<p>This should be truncated here</p>"

License

Released under MIT License.