From 54aada824c538c2216f897cade41253756421a5b Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Fri, 14 Sep 2007 10:43:03 -0500 Subject: [PATCH] Use Standard PageRenderer for S5 Content From Jason Blevins: use the standard PageRenderer class to render S5 content. This way, WikiWords (etc) are processed in S5 slideshows. --- app/controllers/wiki_controller.rb | 16 ++++--------- lib/chunks/engines.rb | 37 +++++++++++++++++++++++++----- lib/page_renderer.rb | 12 ++++++++++ lib/wiki_content.rb | 2 +- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 8c71047c..39269e63 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -293,18 +293,10 @@ class WikiController < ApplicationController end def s5 - if @web.markup == :markdownMML - my_content = Maruku.new(@page.content.delete("\r"), - {:math_enabled => true, :math_numbered => ['\\[','\\begin{equation}'], :content_only => true, - :author => @page.author, :title => @page.plain_name}) - @s5_content = sanitize_xhtml(my_content.to_s5) - @s5_theme = my_content.s5_theme - elsif @web.markup == :markdown - my_content = Maruku.new(@page.content.delete("\r"), - {:math_enabled => false, :content_only => true, - :author => @page.author, :title => @page.plain_name}) - @s5_content = sanitize_xhtml(my_content.to_s5) - @s5_theme = my_content.s5_theme + if @web.markup == :markdownMML || @web.markup == :markdown + my_rendered = PageRenderer.new(@page.revisions.last) + @s5_content = my_rendered.display_s5 + @s5_theme = my_rendered.s5_theme else @s5_content = "S5 not supported with this text filter" @s5_theme = "default" diff --git a/lib/chunks/engines.rb b/lib/chunks/engines.rb index d4f583d2..5f07be45 100644 --- a/lib/chunks/engines.rb +++ b/lib/chunks/engines.rb @@ -42,9 +42,20 @@ module Engines def mask require 'maruku' require 'maruku/ext/math' - html = sanitize_rexml(Maruku.new(@content.delete("\r\x01-\x08\x0B\x0C\x0E-\x1F"), - {:math_enabled => false}).to_html_tree) - html.gsub(/\A
\n?(.*?)\n?<\/div>\Z/m, '\1') + + # If the request is for S5, call Maruku accordingly (without math) + if @content.options[:mode] == :s5 + my_content = Maruku.new(@content.delete("\r"), {:math_enabled => false, + :content_only => true, + :author => @content.options[:engine_opts][:author], + :title => @content.options[:engine_opts][:title]}) + @content.options[:renderer].s5_theme = my_content.s5_theme + sanitize_xhtml(my_content.to_s5) + else + sanitize_rexml(Maruku.new(@content.delete("\r"), + {:math_enabled => false}).to_html_tree) + end + end end @@ -54,9 +65,23 @@ module Engines def mask require 'maruku' require 'maruku/ext/math' - html = sanitize_rexml(Maruku.new(@content.delete("\r\x01-\x08\x0B\x0C\x0E-\x1F"), - {:math_enabled => true, :math_numbered => ['\\[','\\begin{equation}']}).to_html_tree) - html.gsub(/\A
\n?(.*?)\n?<\/div>\Z/m, '\1') + + # If the request is for S5, call Maruku accordingly + if @content.options[:mode] == :s5 + my_content = Maruku.new(@content.delete("\r"), {:math_enabled => true, + :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 + sanitize_xhtml(my_content.to_s5) + else + html = sanitize_rexml(Maruku.new(@content.delete("\r"), + {:math_enabled => true, + :math_numbered => ['\\[','\\begin{equation}']}).to_html_tree) + html.gsub(/\A
\n?(.*?)\n?<\/div>\Z/m, '\1') + end + end end diff --git a/lib/page_renderer.rb b/lib/page_renderer.rb index d1d44ffa..2291c818 100644 --- a/lib/page_renderer.rb +++ b/lib/page_renderer.rb @@ -63,6 +63,18 @@ class PageRenderer end end + attr :s5_theme + def s5_theme=(s) + @s5_theme = s + end + + # Renders an S5 slideshow + def display_s5 + @display_s5 ||= render(:mode => :s5, + :engine_opts => { :author => @revision.page.author, + :title => @revision.page.plain_name}, :renderer => self) + end + # Returns an array of all the WikiIncludes present in the content of this revision. def wiki_includes unless @wiki_includes_cache diff --git a/lib/wiki_content.rb b/lib/wiki_content.rb index 1a0f5ba4..88d9aee0 100644 --- a/lib/wiki_content.rb +++ b/lib/wiki_content.rb @@ -117,7 +117,7 @@ class WikiContent < String DEFAULT_OPTS = { :active_chunks => ACTIVE_CHUNKS, - :engine => Engines::Textile, + :engine => Engines::MarkdownMML, :engine_opts => [], :mode => :show }.freeze