Sha256: f64be8b6da8a3824cdc19d4cedb5b01bbf1c03cbb3d6321fb994900ce6e3f9ac
Contents?: true
Size: 1.21 KB
Versions: 3
Compression:
Stored size: 1.21 KB
Contents
require "rubygems" require "rdiscount" require "cgi" require "tempfile" module Murdoc class Paragraph attr_accessor :source attr_accessor :annotation attr_accessor :source_type attr_accessor :starting_line attr_accessor :options 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 def source_type @source_type end def source_type=(source_type) @source_type = source_type.to_s end def formatted_annotation Markdown.new(annotation, :smart).to_html end def formatted_source @formatted_source ||= if pygments_installed? && options[:highlight_source] IO.popen("pygmentize -l #{source_type} -f html", "w+") do |pipe| pipe.puts source pipe.close_write pipe.read end else "<pre>" + CGI.escapeHTML(source) + "</pre>" end end protected def pygments_installed? @@pygments_installed ||= ENV['PATH'].split(':').any? { |dir| File.exist?("#{dir}/pygmentize") } end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
murdoc-0.1.3 | lib/murdoc/paragraph.rb |
murdoc-0.1.2 | lib/murdoc/paragraph.rb |
murdoc-0.1.1 | lib/murdoc/paragraph.rb |