lib/markdown/config.rb in markdown-1.1.0 vs lib/markdown/config.rb in markdown-1.1.1
- old
+ new
@@ -7,63 +7,89 @@
# use gem install rdiscount for rdiscount and so on
#
# also note for now the first present markdown library gets used
# the search order is first come, first serve, that is: rdiscount, rpeg-markdown, maruku, bluecloth, kramdown (fallback, always present)
-# DEFAULTS = {
-# 'libs' => [ 'pandoc-ruby',
-# 'rdiscount',
-# 'rpeg-markdown',
-# 'maruku',
-# 'bluecloth',
-# 'kramdown' ] }
-# note: make kramdown default engine
+DEFAULT_EXTNAMES = [
+ '.markdown',
+ '.m',
+ '.mark',
+ '.mkdn',
+ '.md',
+ '.mdown',
+ '.markdn',
+ '.txt',
+ '.text' ] # todo: check - add .wiki??? ext
-DEFAULTS = { 'libs' => [
- 'kramdown' ],
- 'extnames' => [
- '.markdown',
- '.m',
- '.mark',
- '.mkdn',
- '.md',
- '.mdown',
- '.markdn',
- '.txt',
- '.text' ], # todo: check - add .wiki??? ext
- 'redcarpet' => {
- 'extensions' => [
- 'no_intra_emphasis',
- 'fenced_code_blocks',
- 'tables',
- 'strikethrough' ] }, # todo/fix: merge nested hash??
- 'filters' => [
- 'comments-percent-style' ] # optional (preprocessing) text filters: e.g. comments-percent-style, skip-end-directive, etc. (see textutils gem)
+DEFAULT_REDCARPET = {
+ 'extensions' => [
+ 'no_intra_emphasis',
+ 'fenced_code_blocks',
+ 'tables',
+ 'strikethrough' ] }
+
+DEFAULT_FILTERS = [
+ 'comments-percent-style' ] # optional (preprocessing) text filters: e.g. comments-percent-style, skip-end-directive, etc. (see textutils gem)
+
+
+DEFAULTS = { 'libs' => [ 'kramdown' ], # note: make kramdown default engine
+ 'extnames' => DEFAULT_EXTNAMES,
+ 'redcarpet' => DEFAULT_REDCARPET, # todo/fix: merge nested hash??
+ 'filters' => DEFAULT_FILTERS
}
-
- def initialize
+#
+# pandoc-ruby - how to include - gemfile cannot install binary ??
+# rpeg-markdown - build failure - still active, anyway?
+# rdiscount - # compilation error on heroku; sorry excluded for now
+
+DEFAULTS_SERVICE = { 'libs' => [
+ 'kramdown', # note: make kramdown default engine
+ 'maruku',
+ 'bluecloth',
+ 'redcarpet'
+ ],
+ 'extnames' => DEFAULT_EXTNAMES,
+ 'redcarpet' => DEFAULT_REDCARPET
+ }
+
+ def load_props
@props = @props_default = Props.new( DEFAULTS, 'DEFAULTS' )
# check for user settings (markdown.yml) in home folder
## todo: use .markdown.yml?? or differnt name ??
props_home_file = File.join( Env.home, 'markdown.yml' )
if File.exists?( props_home_file )
- puts "Loading settings from '#{props_home_file}'..."
+ puts "Loading home settings from '#{props_home_file}'..."
@props = @props_home = Props.load_file( props_home_file, @props )
end
# check for user settings (markdown.yml) in working folder
props_work_file = File.join( '.', 'markdown.yml' )
if File.exists?( props_work_file )
- puts "Loading settings from '#{props_work_file}'..."
+ puts "Loading work settings from '#{props_work_file}'..."
@props = @props_work = Props.load_file( props_work_file, @props )
end
+ end
+ def load_props_service
+ puts "Loading service settings..."
+ @props = @props_default = Props.new( DEFAULTS_SERVICE, 'DEFAULTS' )
+ end
+
+ def initialize
+
+ # for an example see ./boot.rb
+ if $MARKDOWN_USE_SERVICE_CONFIG == true
+ load_props_service
+ else
+ load_props
+ end
+
@libs = []
require_markdown_libs()
end
@@ -146,16 +172,27 @@
def markdown_lib
@libs.first
end
- def markdown_lib_defaults
- ## todo: return props ? that acts like a hash?? (lets us support section lookup without deep merge???)
- opts = @props.fetch( @libs.first, {} )
+ def markdown_libs
+ @libs # NB: return all libs - should we return a clone?
end
- def markdown_to_html_method
- lib = @libs.first
+ def markdown_lib_defaults( lib=nil )
+ lib = @libs.first if lib.nil?
+ ## todo: return props ? that acts like a hash?? (lets us support section lookup without deep merge???)
+ opts = @props.fetch( lib, {} )
+ end
+
+ def markdown_version_method( lib=nil )
+ lib = @libs.first if lib.nil?
+ method = "#{lib.downcase}_version" # default to <lib>_to_html if converter prop not found
+ method.tr('-','_').to_sym
+ end
+
+ def markdown_to_html_method( lib=nil )
+ lib = @libs.first if lib.nil?
method = @props.fetch_from_section( lib, 'converter', "#{lib.downcase}_to_html" ) # default to <lib>_to_html if converter prop not found
method.tr('-','_').to_sym
end
end # class Config
\ No newline at end of file