Class: Redcar::Html::ConvertToList
- Inherits:
-
EditTabCommand
- Object
- EditTabCommand
- Redcar::Html::ConvertToList
- Defined in:
- lib/html.rb
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/html.rb', line 21 def execute if doc.selection? text = doc.selected_text lines = text.split(/\n/) lines.collect! do |c| wrapped = wrap_text_in_white_space(c) { |t| "<li>#{t}</li>" } p "Wrapped: |#{wrapped}|" wrapped end doc.replace_selection(lines.join("\n")) end end |
#wrap_text_in_white_space(text, &wrap_with) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/html.rb', line 34 def wrap_text_in_white_space(text, &wrap_with) r = /^[\t\s]+/ if r =~ text partitions = text.partition(r) wrapped = yield(partitions[2]) "#{partitions[1]}#{wrapped}" else yield(text) end end |