Sha256: 7f61609d17f55623cd898d8d42cccf4b999f4785efbd04df4ccc6317a768b2cc
Contents?: true
Size: 1.22 KB
Versions: 5
Compression:
Stored size: 1.22 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} -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 def pygments_installed? @@pygments_installed ||= ENV['PATH'].split(':').any? { |dir| File.exist?("#{dir}/pygmentize") } end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
murdoc-0.1.9 | lib/murdoc/paragraph.rb |
murdoc-0.1.8 | lib/murdoc/paragraph.rb |
murdoc-0.1.7 | lib/murdoc/paragraph.rb |
murdoc-0.1.6 | lib/murdoc/paragraph.rb |
murdoc-0.1.5 | lib/murdoc/paragraph.rb |