class YARD::Templates::Helpers::Markup::RDocMarkup::RDocMarkup

Constants

MARKUP

Attributes

from_path[RW]

Public Class Methods

new(text) click to toggle source
# 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

Public Instance Methods

to_html() click to toggle source
# 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

Private Instance Methods

fix_dash_dash(text) click to toggle source

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

@todo Refactor into own SimpleMarkup subclass

# File lib/yard/templates/helpers/markup/rdoc_markup.rb, line 87
def fix_dash_dash(text)
  text.gsub(/—(?=\S)/, '--')
end
fix_typewriter(text) click to toggle source

Fixes RDoc behaviour with ++ only supporting alphanumeric text.

@todo Refactor into own SimpleMarkup subclass

# 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