diff --git a/README.rdoc b/README.rdoc index ae7b8902b..aafe93841 100644 --- a/README.rdoc +++ b/README.rdoc @@ -447,6 +447,42 @@ You'll then need to install a version of wkhtmltopdf available at the {wkhtmltop Then restart showoff, and navigate to /pdf (e.g. http://localhost/pdf) of your presentation and a PDF will be generated with the browser. += Misc + +== Markdown Engine + +It is possible to configure the markdown engine of your choice to use +with showoff. This allows you to use special features of the different +engines. + +=== Maruku + +When you prefer using Maruku as the markdown engine of choice for your +presentation, you can use the Latex Math Mode features of +maruku. First you need +{BlahTex}[http://www.mediawiki.org/wiki/Extension:Blahtex] and then +you need to configure your presentation as following: + + { /* other config */, + "markdown" : "maruku", + "maruku" : { + "use_tex" : true, + "png_dir" : "images", /*optional*/ + "html_png_url" : "/file/images/" /*optional*/ + } + } + + +=== Other Engines + +The following engines are preconfigured + +* redcarpet (default) +* bluecloth +* maruku +* rdiscount + + = Completion == ZSH completion diff --git a/lib/showoff.rb b/lib/showoff.rb index f7d199ddc..d1024e646 100644 --- a/lib/showoff.rb +++ b/lib/showoff.rb @@ -58,6 +58,9 @@ def initialize(app=nil) # Default asset path @asset_path = "./" + + # Initialize Markdown Configuration + MarkdownConfig::setup( settings.pres_dir ) end def self.pres_dir_current diff --git a/lib/showoff_utils.rb b/lib/showoff_utils.rb index bd251c2ad..bbaedcc6d 100644 --- a/lib/showoff_utils.rb +++ b/lib/showoff_utils.rb @@ -282,13 +282,17 @@ def self.showoff_pdf_options(dir = '.') Hash[opts.map {|k, v| [k.to_sym, v]}] # keys must be symbols end + def self.showoff_markdown(dir = ".") + get_config_option(dir, "markdown", "redcarpet") + end + def self.get_config_option(dir, option, default = nil) index = File.join(dir, ShowOffUtils.presentation_config_file) if File.exists?(index) data = JSON.parse(File.read(index)) if data.is_a?(Hash) if default.is_a?(Hash) - default.merge(data[option]) + default.merge(data[option] || {}) else data[option] || default end @@ -358,3 +362,45 @@ def self.create_file_if_needed(filename,force) end end end + +# Load the configuration for the markdown engine form the showoff.json +# file +module MarkdownConfig + + def self.setup( dir_name ) + + # Load markdown configuration + case ShowOffUtils.showoff_markdown(dir_name) + when 'rdiscount' + Tilt.prefer Tilt::RDiscountTemplate, "markdown" + when 'maruku' + + Tilt.prefer Tilt::MarukuTemplate, "markdown" + # Now check if we can go for latex mode + require 'maruku' + require 'maruku/ext/math' + + # Load maruku options + opts = ShowOffUtils.get_config_option(dir_name, 'maruku', + {'use_tex' => false, + 'png_dir' => 'images', + 'html_png_url' => '/file/images/'}) + + if opts['use_tex'] + + MaRuKu::Globals[:html_math_output_mathml] = false + MaRuKu::Globals[:html_math_engine] = 'none' + + MaRuKu::Globals[:html_math_output_png] = true + MaRuKu::Globals[:html_png_engine] = 'blahtex' + MaRuKu::Globals[:html_png_dir] = opts['png_dir'] + MaRuKu::Globals[:html_png_url] = opts['html_png_url'] + end + + when 'bluecloth' + Tilt.prefer Tilt::BlueClothTemplate, "markdown" + else + Tilt.prefer Tilt::RedcarpetTemplate, "markdown" + end + end +end diff --git a/test/fixtures/maruku/one/01_slide.md b/test/fixtures/maruku/one/01_slide.md new file mode 100644 index 000000000..a076f7075 --- /dev/null +++ b/test/fixtures/maruku/one/01_slide.md @@ -0,0 +1,16 @@ +!SLIDE +# My Presentation # + +!SLIDE bullets incremental +# Bullet Points # + +* first point +* second point +* third point + + +!SLIDE + +# Math Mode # + +$\forall x \in X; \sum_i=x^i$ diff --git a/test/fixtures/maruku/showoff.json b/test/fixtures/maruku/showoff.json new file mode 100644 index 000000000..a09361379 --- /dev/null +++ b/test/fixtures/maruku/showoff.json @@ -0,0 +1,7 @@ +{ "name": "My Preso", + "sections": [ {"section":"one"} ], + "markdown" : "maruku", + "maruku" : { + "use_tex" : true + } +} diff --git a/test/markdown_test.rb b/test/markdown_test.rb new file mode 100644 index 000000000..c60bcd2a7 --- /dev/null +++ b/test/markdown_test.rb @@ -0,0 +1,43 @@ +require File.expand_path "../test_helper", __FILE__ + +begin + require 'maruku' + do_maruku = true +rescue LoadError + do_maruku = false +end + +context "ShowOff Maruku tests" do + + def app + opt = {:verbose => false, :pres_dir => "test/fixtures/maruku", :pres_file => 'showoff.json'} + ShowOff.set opt + ShowOff.new + end + + setup do + end + + test "maruku can get the index page" do + get '/' + assert last_response.ok? + assert_match '
', last_response.body + end + + test "maruku can get basic slides" do + get '/slides' + assert last_response.ok? + assert_match /My Presentation<\/h1>/, last_response.body + end + + test "maruku transforms equation to math mode" do + get '/slides' + assert_match /