123456789_123456789_123456789_123456789_123456789_

Class: YARD::Templates::Helpers::Markup::RDocMarkup

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/yard/templates/helpers/markup/rdoc_markup.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(text) ⇒ RDocMarkup

[ GitHub ]

  
# File 'lib/yard/templates/helpers/markup/rdoc_markup.rb', line 41

def initialize(text)
  @text = text

  @@mutex.synchronize do
    @@formatter ||= RDocMarkupToHtml.new
    @@markup ||= MARKUP.new
  end
end

Instance Attribute Details

#from_path (rw)

[ GitHub ]

  
# File 'lib/yard/templates/helpers/markup/rdoc_markup.rb', line 35

attr_accessor :from_path

Instance Method Details

#fix_dash_dash(text) (private)

TODO:

Refactor into own SimpleMarkup subclass

Don't allow -- to turn into — element. The chances of this being some --option is far more likely than the typographical meaning.

[ GitHub ]

  
# File 'lib/yard/templates/helpers/markup/rdoc_markup.rb', line 87

def fix_dash_dash(text)
  text.gsub(/—(?=\S)/, '--')
end

#fix_typewriter(text) (private)

TODO:

Refactor into own SimpleMarkup subclass

Fixes RDoc behaviour with ++ only supporting alphanumeric text.

[ GitHub ]

  
# File 'lib/yard/templates/helpers/markup/rdoc_markup.rb', line 66

def fix_typewriter(text)
  code_tags = 0
  text.gsub(%r{<(/)?(pre|code|tt)|(\s|^|>)\+(?! )([^\n\+]{1,900})(?! )\+}) do |str|
    closed = $1
    tag = $2
    first_text = $3
    type_text = $4

    if tag
      code_tags += (closed ? -1 : 1)
      next str
    end
    next str unless code_tags == 0
    first_text + '<tt>' + type_text + '</tt>'
  end
end

#to_html

[ GitHub ]

  
# File 'lib/yard/templates/helpers/markup/rdoc_markup.rb', line 50

def to_html
  html = nil
  @@mutex.synchronize do
    @@formatter.from_path = from_path
    html = @@markup.convert(@text, @@formatter)
  end
  html = fix_dash_dash(html)
  html = fix_typewriter(html)
  html
end