2007-01-22 14:43:50 +01:00
|
|
|
$: << File.dirname(__FILE__) + "../../lib"
|
|
|
|
|
|
|
|
require_dependency 'chunks/chunk'
|
2008-05-21 00:02:10 +02:00
|
|
|
require 'stringsupport'
|
2008-05-22 16:36:23 +02:00
|
|
|
require 'maruku'
|
|
|
|
require 'maruku/ext/math'
|
|
|
|
require_dependency 'rdocsupport'
|
|
|
|
require 'redcloth'
|
2007-01-22 14:43:50 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
redcloth = RedCloth.new(@content, [:hard_breaks] + @content.options[:engine_opts])
|
|
|
|
redcloth.filter_html = false
|
|
|
|
redcloth.no_span_caps = false
|
2007-02-20 06:15:39 +01:00
|
|
|
html = redcloth.to_html(:textile)
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Markdown < AbstractEngine
|
|
|
|
def mask
|
2007-09-14 17:43:03 +02:00
|
|
|
# If the request is for S5, call Maruku accordingly (without math)
|
|
|
|
if @content.options[:mode] == :s5
|
2008-05-17 08:43:11 +02:00
|
|
|
my_content = Maruku.new(@content.delete("\r").to_utf8,
|
|
|
|
{:math_enabled => false, :content_only => true,
|
2007-09-14 17:43:03 +02:00
|
|
|
:author => @content.options[:engine_opts][:author],
|
|
|
|
:title => @content.options[:engine_opts][:title]})
|
|
|
|
@content.options[:renderer].s5_theme = my_content.s5_theme
|
|
|
|
else
|
2008-05-17 08:43:11 +02:00
|
|
|
html = Maruku.new(@content.delete("\r").to_utf8, {:math_enabled => false}).to_html
|
2007-09-15 01:09:24 +02:00
|
|
|
html.gsub(/\A<div class="maruku_wrapper_div">\n?(.*?)\n?<\/div>\Z/m, '\1')
|
2007-09-14 17:43:03 +02:00
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-22 15:36:51 +01:00
|
|
|
class MarkdownMML < AbstractEngine
|
|
|
|
def mask
|
2007-09-14 17:43:03 +02:00
|
|
|
# If the request is for S5, call Maruku accordingly
|
|
|
|
if @content.options[:mode] == :s5
|
2008-05-17 08:43:11 +02:00
|
|
|
my_content = Maruku.new(@content.delete("\r").to_utf8,
|
|
|
|
{:math_enabled => true,
|
2007-09-14 17:43:03 +02:00
|
|
|
:math_numbered => ['\\[','\\begin{equation}'],
|
|
|
|
:content_only => true,
|
|
|
|
:author => @content.options[:engine_opts][:author],
|
|
|
|
:title => @content.options[:engine_opts][:title]})
|
|
|
|
@content.options[:renderer].s5_theme = my_content.s5_theme
|
2008-05-15 08:22:13 +02:00
|
|
|
my_content.to_s5
|
2007-09-14 17:43:03 +02:00
|
|
|
else
|
2008-05-17 08:43:11 +02:00
|
|
|
html = Maruku.new(@content.delete("\r").to_utf8,
|
2007-09-14 17:43:03 +02:00
|
|
|
{:math_enabled => true,
|
2008-05-15 08:22:13 +02:00
|
|
|
:math_numbered => ['\\[','\\begin{equation}']}).to_html
|
2007-09-14 17:43:03 +02:00
|
|
|
html.gsub(/\A<div class="maruku_wrapper_div">\n?(.*?)\n?<\/div>\Z/m, '\1')
|
|
|
|
end
|
2007-01-22 15:36:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-26 11:14:41 +02:00
|
|
|
class MarkdownPNG < AbstractEngine
|
|
|
|
def mask
|
|
|
|
# If the request is for S5, call Maruku accordingly
|
|
|
|
if @content.options[:mode] == :s5
|
|
|
|
my_content = Maruku.new(@content.delete("\r").to_utf8,
|
|
|
|
{:math_enabled => true,
|
|
|
|
:math_numbered => ['\\[','\\begin{equation}'],
|
|
|
|
:html_math_output_mathml => false,
|
|
|
|
:html_math_output_png => true,
|
|
|
|
:html_png_engine => 'blahtex',
|
|
|
|
:html_png_dir => @content.web.files_path + '/pngs',
|
|
|
|
:html_png_url => '../files/pngs/',
|
|
|
|
:content_only => true,
|
|
|
|
:author => @content.options[:engine_opts][:author],
|
|
|
|
:title => @content.options[:engine_opts][:title]})
|
|
|
|
@content.options[:renderer].s5_theme = my_content.s5_theme
|
|
|
|
my_content.to_s5
|
|
|
|
else
|
|
|
|
html = Maruku.new(@content.delete("\r").to_utf8,
|
|
|
|
{:math_enabled => true,
|
|
|
|
:math_numbered => ['\\[','\\begin{equation}'],
|
|
|
|
:html_math_output_mathml => false,
|
|
|
|
:html_math_output_png => true,
|
|
|
|
:html_png_engine => 'blahtex',
|
|
|
|
:html_png_dir => @content.web.files_path + '/pngs',
|
|
|
|
:html_png_url => '../files/pngs/'}).to_html
|
|
|
|
html.gsub(/\A<div class="maruku_wrapper_div">\n?(.*?)\n?<\/div>\Z/m, '\1')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2007-01-22 14:43:50 +01:00
|
|
|
class Mixed < AbstractEngine
|
|
|
|
def mask
|
|
|
|
redcloth = RedCloth.new(@content, @content.options[:engine_opts])
|
|
|
|
redcloth.filter_html = false
|
|
|
|
redcloth.no_span_caps = false
|
2007-02-20 15:18:48 +01:00
|
|
|
html = redcloth.to_html
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RDoc < AbstractEngine
|
|
|
|
def mask
|
2007-02-20 15:18:48 +01:00
|
|
|
html = RDocSupport::RDocFormatter.new(@content).to_html
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-26 11:14:41 +02:00
|
|
|
MAP = { :textile => Textile, :markdown => Markdown, :markdownMML => MarkdownMML, :markdownPNG => MarkdownPNG, :mixed => Mixed, :rdoc => RDoc }
|
2008-05-22 16:36:23 +02:00
|
|
|
MAP.default = MarkdownMML
|
2007-01-22 14:43:50 +01:00
|
|
|
end
|