Curtail (Curtail v3.0.0)
View SourceAn HTML-safe string truncator
Usage
Curtail.truncate("<p>Truncate me</p>", options)
Summary
Functions
Safely truncates a string that contains HTML tags.
Functions
Safely truncates a string that contains HTML tags.
Options
- length (default: 100)
- omission (default: "...")
- word_boundary (default: "~r/S/")
- break_token (default: nil)
Examples
iex> Curtail.truncate("<p>Truncate me!</p>")
"<p>Truncate me!</p>"
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>", length: 49, break_token: "<break_here>")
"<p>This should be truncated here</p>"