Module: Source2MD::TextHelper
Instance Method Summary collapse
- #blank_lines_squish(text) ⇒ Object
- #data_block_exclude(text) ⇒ Object
- #eol_enter(text) ⇒ Object
- #hankaku_kana(text) ⇒ Object
- #indent(text, size = 2) ⇒ Object
- #oneline(text) ⇒ Object
- #space_prefix_remove(text) ⇒ Object
- #squish(text) ⇒ Object
Instance Method Details
#blank_lines_squish(text) ⇒ Object
5 6 7 |
# File 'lib/source2md/text_helper.rb', line 5 def blank_lines_squish(text) text.gsub(/\n{3,}/, "\n\n") end |
#data_block_exclude(text) ⇒ Object
34 35 36 |
# File 'lib/source2md/text_helper.rb', line 34 def data_block_exclude(text) text.sub(/^__END__\R.*/m, "") end |
#eol_enter(text) ⇒ Object
25 26 27 |
# File 'lib/source2md/text_helper.rb', line 25 def eol_enter(text) text.rstrip + "\n" end |
#hankaku_kana(text) ⇒ Object
17 18 19 |
# File 'lib/source2md/text_helper.rb', line 17 def hankaku_kana(text) NKF.nkf("-wxZ4", text) end |
#indent(text, size = 2) ⇒ Object
21 22 23 |
# File 'lib/source2md/text_helper.rb', line 21 def indent(text, size = 2) text.gsub(/^/, " " * size) end |
#oneline(text) ⇒ Object
9 10 11 |
# File 'lib/source2md/text_helper.rb', line 9 def oneline(text) text.remove(/\R+/) end |
#space_prefix_remove(text) ⇒ Object
29 30 31 32 |
# File 'lib/source2md/text_helper.rb', line 29 def space_prefix_remove(text) min = text.lines.reject(&:blank?).collect { |e| e.slice(/^\s*/).size }.min text.remove(/^ {#{min}}/) end |
#squish(text) ⇒ Object
13 14 15 |
# File 'lib/source2md/text_helper.rb', line 13 def squish(text) text.gsub(/[[:space:]]+/, " ").strip end |