Class: Murdoc::FormattedParagraph

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/murdoc/formatted_paragraph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paragraph, highlight = true) ⇒ FormattedParagraph

Returns a new instance of FormattedParagraph.



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

def initialize(paragraph, highlight = true)
  @paragraph = paragraph
  @highlight = highlight
end

Instance Attribute Details

#highlightObject (readonly)

Returns the value of attribute highlight.



9
10
11
# File 'lib/murdoc/formatted_paragraph.rb', line 9

def highlight
  @highlight
end

#paragraphObject (readonly)

Returns the value of attribute paragraph.



8
9
10
# File 'lib/murdoc/formatted_paragraph.rb', line 8

def paragraph
  @paragraph
end

Instance Method Details

#formatted_annotationObject



16
17
18
19
20
21
22
# File 'lib/murdoc/formatted_paragraph.rb', line 16

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

#formatted_sourceObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/murdoc/formatted_paragraph.rb', line 24

def formatted_source
  @formatted_source ||= if pygments_installed? && highlight && source_type != :base
    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