Skip to content

Commit

Permalink
Making markdown engine configurable per slideshow
Browse files Browse the repository at this point in the history
* allows to configure the markdown engine in the showoff.json
* allows to use math mode for slides if applicable
* documentation on how to use other markdown engines
  • Loading branch information
grundprinzip committed Nov 21, 2011
1 parent 0657b2d commit 14706b6
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 1 deletion.
36 changes: 36 additions & 0 deletions README.rdoc
Expand Up @@ -447,6 +447,42 @@ You'll then need to install a version of wkhtmltopdf available at the {wkhtmltop

Then restart showoff, and navigate to <tt>/pdf</tt> (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
Expand Down
3 changes: 3 additions & 0 deletions lib/showoff.rb
Expand Up @@ -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
Expand Down
48 changes: 47 additions & 1 deletion lib/showoff_utils.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions 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$
7 changes: 7 additions & 0 deletions test/fixtures/maruku/showoff.json
@@ -0,0 +1,7 @@
{ "name": "My Preso",
"sections": [ {"section":"one"} ],
"markdown" : "maruku",
"maruku" : {
"use_tex" : true
}
}
43 changes: 43 additions & 0 deletions 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 '<div id="preso">', last_response.body
end

test "maruku can get basic slides" do
get '/slides'
assert last_response.ok?
assert_match /<h1(.*?)>My Presentation<\/h1>/, last_response.body
end

test "maruku transforms equation to math mode" do
get '/slides'
assert_match /<span class="maruku-inline"><img alt="\$\\forall/, last_response.body
end

test "maruku can math mode" do
assert_equal "maruku", ShowOffUtils.showoff_markdown("test/fixtures/maruku")
end


end if do_maruku

0 comments on commit 14706b6

Please sign in to comment.