Module: Redcarpet::Render::HTMLAbbreviations

Defined in:
lib/redcarpet/render/html_abbreviations.rb

Constant Summary collapse

REGEXP =
/^\*\[([-A-Z0-9]+)\]: (.+)$/

Instance Method Summary collapse

Instance Method Details

#acronym_regexp(acronym) ⇒ Object



27
28
29
# File 'lib/redcarpet/render/html_abbreviations.rb', line 27

def acronym_regexp(acronym)
  /\b#{acronym}\b/
end

#preprocess(document) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/redcarpet/render/html_abbreviations.rb', line 7

def preprocess(document)
  abbreviations = document.scan(REGEXP)
  abbreviations = Hash[*abbreviations.flatten]

  if abbreviations.any?
    document.gsub!(REGEXP, "")
    document.rstrip!

    abbreviations.each do |key, value|
      html = <<-EOS.strip
        <abbr title="#{value}">#{key}</abbr>
      EOS

      document.gsub!(acronym_regexp(key), html)
    end
  end

  document
end