File: poem.rb

package info (click to toggle)
ruby-wikicloth 0.8.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 588 kB
  • ctags: 278
  • sloc: ruby: 2,548; makefile: 14
file content (15 lines) | stat: -rw-r--r-- 601 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module WikiCloth
  class PoemExtension < Extension

    # <poem>poem content (to preserve spacing)</poem>
    #
    element 'poem' do |buffer|
      buffer.element_content.gsub!(/\A\n/,"") # remove new line at beginning of string
      buffer.element_content.gsub!(/\n\z/,"") # remove new line at end of string
      buffer.element_content.gsub!(/^\s+/) { |m| "&nbsp;" * m.length } # replace all spaces at beginning of line with &nbsp;
      buffer.element_content.gsub!(/\n/,'<br />') # replace all new lines with <br />
      "<div class=\"poem\">#{buffer.element_content}</div>"
    end

  end
end