Class: Stepmod::Utils::Cleaner

Inherits:
Coradoc::Input::HTML::Cleaner
  • Object
show all
Defined in:
lib/stepmod/utils/cleaner.rb

Instance Method Summary collapse

Instance Method Details

#clean_tag_borders(string) ⇒ Object

Find non-asterisk content that is enclosed by two or more asterisks. Ensure that only one whitespace occurs in the border area. Same for underscores and brackets.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/stepmod/utils/cleaner.rb', line 16

def clean_tag_borders(string)
  patterns = {
    /\s?\*{2,}.*?\*{2,}\s?/ => "**",
    /\s?_{2,}.*?_{2,}\s?/   => "__",
    /\s?~{2,}.*?~{2,}\s?/   => "~~",
  }

  result = string.dup
  patterns.each do |pattern, value|
    result = result.gsub(pattern) do |match|
      preserve_border_whitespaces(match, default_border: Coradoc::Input::HTML.config.tag_border) do
        match.strip.sub(" #{value}", value).sub("#{value} ", value)
      end
    end
  end

  result = result.gsub(/\s?\[.*?\]\s?/) do |match|
    preserve_border_whitespaces(match) do
      match.strip.sub("[ ", "[").sub(" ]", "[")
    end
  end
  result
end

#tidy(string) ⇒ Object



6
7
8
9
10
# File 'lib/stepmod/utils/cleaner.rb', line 6

def tidy(string)
  super
    .gsub(/^ +/, "")
    .gsub(/\*\s([,.])/, '*\1') # remove space between * and comma or dot.
end