Skip to content

Loading…

Configure Markdown engine #194

Merged
merged 4 commits into from

4 participants

@MichaelHackett

The README says that the Markdown rendering engine can be selected in the configuration file, but the call to process this config option has been commented out in the current version. Going through the code and the commit that made the change, I cannot see why. So I reinstated it so that I could use Bluecloth/Discount, and it works fine. Except...

I wanted to change the default options that Bluecloth passes to Discount, and I figured that I could use the same mechanism as you used for configuring Maruku (adding a config key with the name of the Markdown engine).

However, Bluecloth expects the hash keys to be symbols, and I didn't see a way to generate those with the current JSON parser. But... I did find an suggestion for converting hash keys from strings to symbols, which seemed like a good way to go --- I can't think of a case where that wouldn't be as good or preferable. I updated the Maruku config code to use symbols instead, but I haven't got Maruku installed so I haven't tested that it still works.

MichaelHackett added some commits
@MichaelHackett MichaelHackett Restored disabled markup-engine configuration (ref: 616bf52).
It's not clear to me why this line was commented out, as the commit message says only "whitespace", referring to the removal of extraneous white space from another part of the file. Was it an accident? (e.g., commented out for testing and checked in unintentionally)
3d96631
@MichaelHackett MichaelHackett Added support for passing options hash from showoff config file to re…
…ndering engine via Tilt.

Previously, some options were handled manually for the Maruku engine, but not for any of the others. The markdown engine wrappers in Tilt allow the passing of options to the various libraries through a hash given with the renderer is instantiated. The special handling in Showoff for the Maruku engine have been left unchanged for now, but it might be possible to migrate the code to use the same mechanism in the future. (I haven't used Maruku yet myself, so I didn't want to mess with the config code.)
ed09534
@MichaelHackett MichaelHackett For the markup engine config settings, hash keys are converted from s…
…trings to symbols.

The Tilt markup engine wrappers expect hash keys that are symbols, and there is no way to specify hashes in that format in JSON. But there's no reason the existing Maruku engine settings code couldn't be tweaked to expect symbol keys and work the same way.
4725957
@MichaelHackett MichaelHackett Fixes exception when no renderer options specified.
(Oops! Forgot to test with example presentation.)
c7bf17d
@matthewmccullough matthewmccullough merged commit 1eae579 into schacon:master
@binford2k

Where did the default_options go?

Very good question! :-) I can't test at the moment, but it looks default_options should be added as the third arg to get_config_option. I guess I must have been using an actual config file, and didn't notice that the defaults were gone.

That's what I did when I incorporated your fixes into the Puppet Labs fork. We're now upstream, so you should take a look at our fork when you get a chance. I'd love it if you tested my integration with your existing use case, as well.

@b4d26f6fc7fc

I have the test believe me I do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 13, 2012
  1. @MichaelHackett

    Restored disabled markup-engine configuration (ref: 616bf52).

    MichaelHackett committed
    It's not clear to me why this line was commented out, as the commit message says only "whitespace", referring to the removal of extraneous white space from another part of the file. Was it an accident? (e.g., commented out for testing and checked in unintentionally)
  2. @MichaelHackett

    Added support for passing options hash from showoff config file to re…

    MichaelHackett committed
    …ndering engine via Tilt.
    
    Previously, some options were handled manually for the Maruku engine, but not for any of the others. The markdown engine wrappers in Tilt allow the passing of options to the various libraries through a hash given with the renderer is instantiated. The special handling in Showoff for the Maruku engine have been left unchanged for now, but it might be possible to migrate the code to use the same mechanism in the future. (I haven't used Maruku yet myself, so I didn't want to mess with the config code.)
  3. @MichaelHackett

    For the markup engine config settings, hash keys are converted from s…

    MichaelHackett committed
    …trings to symbols.
    
    The Tilt markup engine wrappers expect hash keys that are symbols, and there is no way to specify hashes in that format in JSON. But there's no reason the existing Maruku engine settings code couldn't be tweaked to expect symbol keys and work the same way.
Commits on Sep 15, 2012
  1. @MichaelHackett

    Fixes exception when no renderer options specified.

    MichaelHackett committed
    (Oops! Forgot to test with example presentation.)
Showing with 17 additions and 9 deletions.
  1. +5 −2 lib/showoff.rb
  2. +12 −7 lib/showoff_utils.rb
View
7 lib/showoff.rb
@@ -80,7 +80,7 @@ def initialize(app=nil)
@asset_path = "./"
# Initialize Markdown Configuration
- #MarkdownConfig::setup(settings.pres_dir)
+ MarkdownConfig::setup(settings.pres_dir)
end
def self.pres_dir_current
@@ -150,6 +150,9 @@ def process_markdown(name, content, static=false, pdf=false)
if settings.encoding and content.respond_to?(:force_encoding)
content.force_encoding(settings.encoding)
end
+ engine_options = ShowOffUtils.showoff_renderer_options(settings.pres_dir)
+ @logger.debug "renderer: #{Tilt[:markdown].name}"
+ @logger.debug "render options: #{engine_options.inspect}"
# if there are no !SLIDE markers, then make every H1 define a new slide
unless content =~ /^\<?!SLIDE/m
@@ -216,7 +219,7 @@ def process_markdown(name, content, static=false, pdf=false)
else
content += "<div class=\"#{content_classes.join(' ')}\" ref=\"#{name}\">\n"
end
- sl = Tilt[:markdown].new { slide.text }.render
+ sl = Tilt[:markdown].new(nil, nil, engine_options) { slide.text }.render
sl = update_image_paths(name, sl, static, pdf)
content += sl
content += "</div>\n"
View
19 lib/showoff_utils.rb
@@ -314,6 +314,11 @@ def self.showoff_markdown(dir = ".")
get_config_option(dir, "markdown", "redcarpet")
end
+ def self.showoff_renderer_options(dir = '.', default_options = {})
+ opts = get_config_option(dir, showoff_markdown(dir))
+ Hash[opts.map {|k, v| [k.to_sym, v]}] if opts # keys must be symbols
+ end
+
def self.get_config_option(dir, option, default = nil)
index = File.join(dir, ShowOffUtils.presentation_config_file)
if File.exists?(index)
@@ -408,18 +413,18 @@ def self.setup(dir_name)
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/'})
+ opts = ShowOffUtils.showoff_renderer_options(dir_name,
+ { :use_tex => false,
+ :png_dir => 'images',
+ :html_png_url => '/file/images/'})
- if opts['use_tex']
+ 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']
+ MaRuKu::Globals[:html_png_dir] = opts[:png_dir]
+ MaRuKu::Globals[:html_png_url] = opts[:html_png_url]
end
when 'bluecloth'
Something went wrong with that request. Please try again.