Class: Murdoc::Paragraph

Inherits:
Object
  • Object
show all
Includes:
Languages::Javascript::CommentSymbols, Languages::Ruby::CommentSymbols
Defined in:
lib/murdoc/paragraph.rb,
lib/murdoc/languages/ruby.rb,
lib/murdoc/languages/javascript.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, annotation, starting_line = 0, source_type = nil, options = {}) ⇒ Paragraph

Returns a new instance of Paragraph.



18
19
20
21
22
23
24
# File 'lib/murdoc/paragraph.rb', line 18

def initialize(source, annotation, starting_line = 0, source_type = nil, options ={})
  self.source = source
  self.annotation = annotation
  self.starting_line = starting_line
  self.source_type = source_type
  self.options = options
end

Instance Attribute Details

#annotationObject

Returns the value of attribute annotation.



13
14
15
# File 'lib/murdoc/paragraph.rb', line 13

def annotation
  @annotation
end

#optionsObject

Returns the value of attribute options.



16
17
18
# File 'lib/murdoc/paragraph.rb', line 16

def options
  @options
end

#sourceObject

Returns the value of attribute source.



12
13
14
# File 'lib/murdoc/paragraph.rb', line 12

def source
  @source
end

#source_typeObject

Returns the value of attribute source_type.



14
15
16
# File 'lib/murdoc/paragraph.rb', line 14

def source_type
  @source_type
end

#starting_lineObject

Returns the value of attribute starting_line.



15
16
17
# File 'lib/murdoc/paragraph.rb', line 15

def starting_line
  @starting_line
end

Instance Method Details

#formatted_annotationObject



35
36
37
38
39
40
41
# File 'lib/murdoc/paragraph.rb', line 35

def formatted_annotation
  if defined?(Markdown)
    Markdown.new(annotation, :smart).to_html
  else
    Kramdown.new(annotation, :input => :markdown).to_html
  end
end

#formatted_sourceObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/murdoc/paragraph.rb', line 43

def formatted_source
  @formatted_source ||= if pygments_installed? && options[:highlight_source]
    IO.popen("pygmentize -l #{source_type} -O encoding=UTF8 -f html -O nowrap", "w+") do |pipe|
      pipe.puts source
      pipe.close_write
      pipe.read
    end
  else
    CGI.escapeHTML(source)
  end
end