class Murdoc::FormattedParagraph

Attributes

highlight[R]
paragraph[R]

Public Class Methods

new(paragraph, highlight = true) click to toggle source
# File lib/murdoc/formatted_paragraph.rb, line 11
def initialize(paragraph, highlight = true)
  @paragraph = paragraph
  @highlight = highlight
end

Public Instance Methods

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

Protected Instance Methods

pygments_installed?() click to toggle source
# File lib/murdoc/formatted_paragraph.rb, line 37
def pygments_installed?
  @@pygments_installed ||= ENV['PATH'].split(':').any? { |dir| File.exist?("#{dir}/pygmentize") }
end