### Smart Formatting for Text and HTML Source: https://github.com/pbhogan/sterile/blob/master/README.markdown Formats text with proper typographic punctuation like curly quotes and em-dashes. It also supports smart formatting of text within HTML tags, converting entities appropriately. ```Ruby q{"He said, 'Away with you, Drake!'"}.smart_format # => “He said, ‘Away with you, Drake!’” %q{"He said, 'Away with you, Drake!'"}.smart_format_tags # => "“He said, ‘Away with you, Drake!’“" ``` -------------------------------- ### Titlecase Formatting for Strings Source: https://github.com/pbhogan/sterile/blob/master/README.markdown Applies intelligent titlecasing to strings, adhering to rules for small words and handling various edge cases, similar to AP style guidelines. An alias 'titleize' is also available. ```Ruby "Q&A with Steve Jobs: 'That's what happens in technology'".titlecase # => "Q&A With Steve Jobs: 'That's What Happens in Technology'" "Small word at end is nothing to be afraid of".titleize # => "Small Word at End Is Nothing to Be Afraid Of" ``` -------------------------------- ### Generate URL Slugs and Sterilize Strings Source: https://github.com/pbhogan/sterile/blob/master/README.markdown Creates URL-friendly slugs by transliterating to ASCII, downcasing, and replacing non-alphanumeric characters and spaces with a delimiter. It can also sterilize strings by transliterating and stripping HTML tags. ```Ruby "Hello World!".sluggerize # => "hello-world" "Hello World!".to_slug # => "hello-world" "nåsty".sterilize # => "nasty" ``` -------------------------------- ### Trim Whitespace and Process Tag Content Source: https://github.com/pbhogan/sterile/blob/master/README.markdown Trims leading/trailing whitespace and collapses internal redundant whitespace. It also allows iteration over text within HTML/XML tags for modification or scanning. ```Ruby " Hello world! ".transliterate # => "Hello world!" "Only uppercase the text in this".gsub_tags { |t| t.upcase } # => "Only UPPERCASE the TEXT in this" "Only output the text in this".scan_tags { |t| puts t } ``` -------------------------------- ### Strip HTML/XML Tags and Comments Source: https://github.com/pbhogan/sterile/blob/master/README.markdown Removes HTML/XML tags, comments, and PHP/ERB style tags from a given string, leaving only the plain text content. ```Ruby 'Visit our website!'.strip_tags # => "Visit our website!" ``` -------------------------------- ### Transliterate Unicode Characters to ASCII Source: https://github.com/pbhogan/sterile/blob/master/README.markdown Converts Unicode and accented ASCII characters to their plain-text ASCII equivalents using a pedantic or optical mapping. This function is based on the stringex gem and can be used via class methods or String extensions. ```Ruby Sterile.transliterate("šţɽĩɳģ") # => "string" "šţɽĩɳģ".transliterate # => "string" "šţɽĩɳģ".transliterate(:optical => true) # => "string" ``` -------------------------------- ### Encode and Decode HTML Entities Source: https://github.com/pbhogan/sterile/blob/master/README.markdown Converts Unicode characters to their HTML entity equivalents, falling back to numeric entities if a named entity is not possible. It can also decode HTML entities back into Unicode characters. ```Ruby q{“Economy Hits Bottom,” ran the headline}.encode_entities # => "“Economy Hits Bottom,” ran the headline" "“Economy Hits Bottom,” ran the headline".decode_entities # => "“Economy Hits Bottom,” ran the headline" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.