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
35 36 37 |
# File 'lib/source2md/text_helper.rb', line 35 def data_block_exclude(text) text.sub(/^__END__\R.*/m, "") end |
#eol_enter(text) ⇒ Object
26 27 28 |
# File 'lib/source2md/text_helper.rb', line 26 def eol_enter(text) text.rstrip + "\n" end |
#hankaku_kana(text) ⇒ Object
18 19 20 |
# File 'lib/source2md/text_helper.rb', line 18 def hankaku_kana(text) NKF.nkf("-wxZ4", text) end |
#indent(text, size = 2) ⇒ Object
22 23 24 |
# File 'lib/source2md/text_helper.rb', line 22 def indent(text, size = 2) text.gsub(/^/, " " * size) end |
#oneline(text) ⇒ Object
9 10 11 12 |
# File 'lib/source2md/text_helper.rb', line 9 def oneline(text) text = text.gsub(/?\R/, "? ") text = text.remove(/\R+/) end |
#space_prefix_remove(text) ⇒ Object
30 31 32 33 |
# File 'lib/source2md/text_helper.rb', line 30 def space_prefix_remove(text) min = text.lines.reject(&:blank?).collect { |e| e.slice(/^\s*/).size }.min text.remove(/^ {#{min}}/) end |
#squish(text) ⇒ Object
14 15 16 |
# File 'lib/source2md/text_helper.rb', line 14 def squish(text) text.gsub(/[[:space:]]+/, " ").strip end |