Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/markup_parser/markdown/string_extensions.rb
Overview
Adds classes to String class…
Instance Method Summary collapse
-
#convert_tabs_to_spaces! ⇒ Object
Converts tabs (t) to 2 spaces.
-
#correct_gh_code_syntax! ⇒ Object
Corrects the gh code block syntax mistake where one would write ‘~~~ .ruby’ and the correct code should be ‘~~~ruby’.
-
#correct_ol_list_parenth! ⇒ Object
Corrects the ol list elements: which only except the syntax: ‘1.
-
#standardize_newlines! ⇒ Object
Standardize line endings.
-
#sub_newlines! ⇒ Object
Corrects the newlines by stripping the leading whitespace.
Instance Method Details
#convert_tabs_to_spaces! ⇒ Object
Converts tabs (t) to 2 spaces
17 18 19 |
# File 'lib/markup_parser/markdown/string_extensions.rb', line 17 def convert_tabs_to_spaces! self.gsub!(/\t/, " ") end |
#correct_gh_code_syntax! ⇒ Object
Corrects the gh code block syntax mistake where one would write ‘~~~ .ruby’ and the correct code should be ‘~~~ruby’
6 7 8 |
# File 'lib/markup_parser/markdown/string_extensions.rb', line 6 def correct_gh_code_syntax! self.gsub!(/~~~\s\.([a-zA-Z]*)/, '~~~\1') end |
#correct_ol_list_parenth! ⇒ Object
Corrects the ol list elements: which only except the syntax: ‘1. …’. Corrected syntaxes: ‘1)’
12 13 14 |
# File 'lib/markup_parser/markdown/string_extensions.rb', line 12 def correct_ol_list_parenth! self.gsub!(/(\s*)(\d)\)/,'\1\2.') end |
#standardize_newlines! ⇒ Object
Standardize line endings
22 23 24 25 |
# File 'lib/markup_parser/markdown/string_extensions.rb', line 22 def standardize_newlines! self.gsub!("\r\n", "\n") self.gsub!("\r", "\n") end |
#sub_newlines! ⇒ Object
Corrects the newlines by stripping the leading whitespace. NOTE: this is a hack to workaround the strange Gollum editor indentation behavior
29 30 31 |
# File 'lib/markup_parser/markdown/string_extensions.rb', line 29 def sub_newlines! self.gsub!(/([\r\n|\n])[\ ]*(.)/,'\1\2') end |