instiki/app/models/chunks/engines.rb

62 lines
1.4 KiB
Ruby
Raw Normal View History

$: << File.dirname(__FILE__) + "../../lib"
require 'redcloth'
require 'bluecloth_tweaked'
require 'rdocsupport'
require 'chunks/chunk'
# The markup engines are Chunks that call the one of RedCloth
# or RDoc to convert text. This markup occurs when the chunk is required
# to mask itself.
module Engines
2005-08-02 02:59:12 +02:00
class AbstractEngine
2005-02-04 19:57:42 +01:00
2005-08-02 02:59:12 +02:00
# Convert content to HTML
2005-02-04 19:57:42 +01:00
def self.apply_to(content)
2005-08-02 02:59:12 +02:00
engine = self.new(content)
content.replace(engine.to_html)
2005-02-04 19:57:42 +01:00
end
private
# Never create engines by constructor - use apply_to instead
def initialize(content)
@content = content
2005-02-04 19:57:42 +01:00
end
end
class Textile < AbstractEngine
2005-08-02 02:59:12 +02:00
def to_html
redcloth = RedCloth.new(@content, [:hard_breaks] + @content.options[:engine_opts])
redcloth.filter_html = false
redcloth.no_span_caps = false
redcloth.to_html(:textile)
end
end
2005-02-04 19:57:42 +01:00
class Markdown < AbstractEngine
2005-08-02 02:59:12 +02:00
def to_html
2005-04-10 19:10:11 +02:00
BlueCloth.new(@content, @content.options[:engine_opts]).to_html
end
end
class Mixed < AbstractEngine
2005-08-02 02:59:12 +02:00
def to_html
redcloth = RedCloth.new(@content, @content.options[:engine_opts])
redcloth.filter_html = false
redcloth.no_span_caps = false
redcloth.to_html
end
end
2005-02-04 19:57:42 +01:00
class RDoc < AbstractEngine
2005-08-02 02:59:12 +02:00
def to_html
RDocSupport::RDocFormatter.new(@content).to_html
end
end
MAP = { :textile => Textile, :markdown => Markdown, :mixed => Mixed, :rdoc => RDoc }
MAP.default = Textile
end