Class: Middleman::Renderers::Markdown

Inherits:
Extension
  • Object
show all
Defined in:
middleman-core/lib/middleman-core/renderers/markdown.rb

Overview

Markdown renderer

Constant Summary

Constants included from Contracts

Contracts::ImmutableSortedSetOf, Contracts::PATH_MATCHER

Instance Attribute Summary

Attributes inherited from Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Extension

activated_extension, #add_exposed_to_context, #after_build, after_extension_activated, #after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, helpers, #initialize, #manipulate_resource_list, option, #ready, resources

Methods included from Contracts

#Contract

Constructor Details

This class inherits a constructor from Middleman::Extension

Instance Method Details

#after_configurationObject

Once configuration is parsed


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'middleman-core/lib/middleman-core/renderers/markdown.rb', line 11

def after_configuration
  markdown_exts = %w[markdown mdown md mkd mkdn]

  begin
    # Look for the user's preferred engine
    if app.config[:markdown_engine] == :redcarpet
      require 'middleman-core/renderers/redcarpet'
      ::Tilt.prefer(::Middleman::Renderers::RedcarpetTemplate, *markdown_exts)
    elsif app.config[:markdown_engine] == :kramdown
      require 'middleman-core/renderers/kramdown'
      ::Tilt.prefer(::Middleman::Renderers::KramdownTemplate, *markdown_exts)
    elsif app.config[:markdown_engine]
      # Map symbols to classes
      markdown_engine_klass = if app.config[:markdown_engine].is_a? Symbol
                                engine = app.config[:markdown_engine].to_s
                                engine = engine == 'rdiscount' ? 'RDiscount' : engine.camelize
                                app.config[:markdown_engine_prefix].const_get("#{engine}Template")
                              else
                                app.config[:markdown_engine_prefix]
                              end

      # Tell tilt to use that engine
      ::Tilt.prefer(markdown_engine_klass, *markdown_exts)
    end
  rescue LoadError
    # If they just left it at the default engine and don't happen to have it,
    # then they're using middleman-core bare and we shouldn't bother them.
    logger.warn "Requested Markdown engine (#{app.config[:markdown_engine]}) not found. Maybe the gem needs to be installed and required?" if app.config.setting(:markdown_engine).value_set?
  end
end