Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/codnar/string_extensions.rb
Overview
Extend the core String class.
Instance Method Summary collapse
-
#clean_markup_html ⇒ Object
Clean HTML generated by markup formatters.
-
#to_id ⇒ Object
Convert this String to an identifier.
Instance Method Details
#clean_markup_html ⇒ Object
Clean HTML generated by markup formatters. Such HTML tends to have extra empty lines for no apparent reason. Cleaning it up seems to be safe enough, and eliminates the ugly additional vertical space in the final HTML.
15 16 17 18 19 20 21 22 |
# File 'lib/codnar/string_extensions.rb', line 15 def clean_markup_html return gsub("\r\n", "\n") \ .gsub(/\n*<p>\n*/, "\n<p>\n") \ .gsub(/\n*<\/p>\n*/, "\n</p>\n") \ .gsub(/\n*<pre>\n+/, "\n<pre>\n") \ .gsub(/\n+<\/pre>\n*/, "\n</pre>\n") \ .sub(/^\n*/, "") end |
#to_id ⇒ Object
Convert this String to an identifier. This is a stable operation, so anything that accept a name will also accept an identifier as well.
6 7 8 |
# File 'lib/codnar/string_extensions.rb', line 6 def to_id return self.strip.gsub(/[^a-zA-Z0-9]+/, "-").downcase end |