2007-01-22 14:43:50 +01:00
|
|
|
$: << File.dirname(__FILE__) + "../../lib"
|
|
|
|
|
|
|
|
require_dependency '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
|
|
|
|
class AbstractEngine < Chunk::Abstract
|
|
|
|
|
|
|
|
# Create a new chunk for the whole content and replace it with its mask.
|
|
|
|
def self.apply_to(content)
|
|
|
|
new_chunk = self.new(content)
|
|
|
|
content.replace(new_chunk.mask)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Never create engines by constructor - use apply_to instead
|
|
|
|
def initialize(content)
|
|
|
|
@content = content
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class Textile < AbstractEngine
|
|
|
|
def mask
|
|
|
|
require_dependency 'redcloth'
|
|
|
|
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
|
|
|
|
|
|
|
|
class Markdown < AbstractEngine
|
|
|
|
def mask
|
2007-02-15 03:32:24 +01:00
|
|
|
require_dependency 'maruku'
|
|
|
|
Maruku.new(@content.delete("\r"), {:math_enabled => false}).to_html
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-22 15:36:51 +01:00
|
|
|
class MarkdownMML < AbstractEngine
|
|
|
|
def mask
|
|
|
|
require_dependency 'maruku'
|
|
|
|
require_dependency 'maruku/ext/math'
|
2007-02-15 05:19:37 +01:00
|
|
|
Maruku.new(@content.delete("\r"), {:math_enabled => true, :math_numbered => ['\\[','\\begin{equation}']}).to_html
|
2007-01-22 15:36:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
class Mixed < AbstractEngine
|
|
|
|
def mask
|
|
|
|
require_dependency 'redcloth'
|
|
|
|
redcloth = RedCloth.new(@content, @content.options[:engine_opts])
|
|
|
|
redcloth.filter_html = false
|
|
|
|
redcloth.no_span_caps = false
|
|
|
|
redcloth.to_html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RDoc < AbstractEngine
|
|
|
|
def mask
|
|
|
|
require_dependency 'rdocsupport'
|
|
|
|
RDocSupport::RDocFormatter.new(@content).to_html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-22 15:36:51 +01:00
|
|
|
MAP = { :textile => Textile, :markdown => Markdown, :markdownMML => MarkdownMML, :mixed => Mixed, :rdoc => RDoc }
|
2007-01-22 14:43:50 +01:00
|
|
|
MAP.default = Textile
|
|
|
|
end
|