markdown 0.2.0.beta1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,6 +10,7 @@ lib/markdown/engines/kramdown.rb
10
10
  lib/markdown/engines/maruku.rb
11
11
  lib/markdown/engines/pandoc_ruby.rb
12
12
  lib/markdown/engines/rdiscount.rb
13
+ lib/markdown/engines/redcarpet.rb
13
14
  lib/markdown/engines/rpeg_markdown.rb
14
15
  lib/markdown/gen.rb
15
16
  lib/markdown/wrapper.rb
@@ -12,8 +12,6 @@
12
12
  # % chmod a+x bin/markdown
13
13
  #
14
14
 
15
-
16
- require 'rubygems'
17
15
  require 'markdown'
18
16
 
19
17
  Markdown.main
@@ -32,6 +32,7 @@ require 'markdown/engines/kramdown'
32
32
  require 'markdown/engines/maruku'
33
33
  require 'markdown/engines/pandoc_ruby'
34
34
  require 'markdown/engines/rdiscount'
35
+ require 'markdown/engines/redcarpet'
35
36
  require 'markdown/engines/rpeg_markdown'
36
37
  require 'markdown/wrapper'
37
38
  require 'markdown/gen'
@@ -39,7 +40,7 @@ require 'markdown/gen'
39
40
 
40
41
  module Markdown
41
42
 
42
- VERSION = '0.2.0.beta1'
43
+ VERSION = '0.2.0'
43
44
 
44
45
  # version string for generator meta tag (includes ruby version)
45
46
  def self.banner
@@ -30,8 +30,15 @@ DEFAULTS = { 'libs' => [
30
30
  '.mdown',
31
31
  '.markdn',
32
32
  '.txt',
33
- '.text' ] # todo: check - add .wiki??? ext
34
- }
33
+ '.text' ], # todo: check - add .wiki??? ext
34
+ 'redcarpet' => {
35
+ 'extensions' => [
36
+ 'no_intra_emphasis',
37
+ 'fenced_code_blocks',
38
+ 'tables',
39
+ 'strikethrough' ] # todo/fix: merge nested hash??
40
+ },
41
+ }
35
42
 
36
43
 
37
44
  def initialize
@@ -39,9 +46,8 @@ DEFAULTS = { 'libs' => [
39
46
 
40
47
  # check for user settings (markdown.yml) in home folder
41
48
 
42
- ## todo/fix: use join path???
43
49
  ## todo: use .markdown.yml?? or differnt name ??
44
- props_home_file = "#{Env.home}/markdown.yml"
50
+ props_home_file = File.join( Env.home, 'markdown.yml' )
45
51
  if File.exists?( props_home_file )
46
52
  puts "Loading settings from '#{props_home_file}'..."
47
53
  @props = @props_home = Props.load_file( props_home_file, @props )
@@ -49,14 +55,13 @@ DEFAULTS = { 'libs' => [
49
55
 
50
56
  # check for user settings (markdown.yml) in working folder
51
57
 
52
- props_work_file = "./markdown.yml"
58
+ props_work_file = File.join( '.', 'markdown.yml' )
53
59
  if File.exists?( props_work_file )
54
60
  puts "Loading settings from '#{props_work_file}'..."
55
61
  @props = @props_work = Props.load_file( props_work_file, @props )
56
62
  end
57
63
 
58
64
  @libs = []
59
- @mn = nil # markdown converter method name (mn) e.g. kramdown_to_html
60
65
 
61
66
  require_markdown_libs()
62
67
  end
@@ -105,13 +110,17 @@ DEFAULTS = { 'libs' => [
105
110
  end
106
111
  end
107
112
 
108
- puts " Found #{@libs.length} Markdown libraries: #{@libs.join(', ')}"
113
+ puts " Found #{@libs.length} Markdown #{(@libs.length == 1) ? 'library' : 'libraries'}: #{@libs.join(', ')}"
109
114
  end
110
115
 
111
116
  def markdown_lib
112
117
  @libs.first
113
118
  end
114
119
 
120
+ def markdown_lib_defaults
121
+ opts = @props.fetch( @libs.first, {} )
122
+ end
123
+
115
124
  def markdown_to_html_method
116
125
  lib = @libs.first
117
126
  opts = @props.fetch( lib, {} )
@@ -1,7 +1,9 @@
1
1
  module Markdown
2
2
  module Engine
3
3
 
4
- def bluecloth_to_html( content )
4
+ def bluecloth_to_html( content, options={} )
5
+ puts " Converting Markdown-text (#{@content.length} bytes) to HTML using library bluecloth..."
6
+
5
7
  BlueCloth.new( content ).to_html
6
8
  end
7
9
 
@@ -1,9 +1,51 @@
1
1
  module Markdown
2
2
  module Engine
3
3
 
4
- def kramdown_to_html( content )
5
- Kramdown::Document.new( content ).to_html
6
- end
4
+ def kramdown_to_html( content, options={} )
5
+
6
+ h = {}
7
+
8
+ # todo: find an easier (more generic?) way to setup hash - possible?
9
+ h[ :auto_ids ] = options.fetch( 'auto_ids', nil ) if options.fetch( 'auto_ids', nil )
10
+ h[ :footnote_nr ] = options.fetch( 'footnote_nr',nil ) if options.fetch( 'footnote_nr', nil )
11
+ h[ :entity_output ] = options.fetch( 'entity_output',nil ) if options.fetch( 'entity_output', nil )
12
+ h[ :toc_levels ] = options.fetch( 'toc_levels',nil ) if options.fetch( 'toc_levels', nil )
13
+ h[ :smart_quotes ] = options.fetch( 'smart_quotes',nil ) if options.fetch( 'smart_quotes', nil )
14
+
15
+ puts " Converting Markdown-text (#{@content.length} bytes) to HTML using library kramdown (#{Kramdown::VERSION})"
16
+ puts " using options:"
17
+ pp h # todo: use inspect? or to_json?
18
+
19
+ ## allow fenced blocks a la github flavored markup
20
+ # -- thanks zenweb for inspiration:
21
+ # https://github.com/seattlerb/zenweb/blob/master/lib/zenweb/plugins/markdown.rb
22
+
23
+ content = content.
24
+ gsub(/^``` *(\w+)/) { "{:lang=\"#$1\"}\n~~~" }.
25
+ gsub(/^```/, '~~~')
26
+
27
+ content = Kramdown::Document.new( content, h ).to_html
28
+
29
+ # todo: check content size and newlines
30
+ # check banner option?
31
+ # only add banner if some newlines and size > treshold?
32
+
33
+ banner_begin =<<EOS
34
+ <!-- === begin markdown block =====================================================
35
+
36
+ generated by #{Markdown.banner}
37
+ on #{Time.now} with Markdown engine kramdown (#{Kramdown::VERSION})
38
+ using options { !to be done! }
39
+ -->
40
+ EOS
41
+
42
+ banner_end =<<EOS
43
+ <!-- === end markdown block ===================================================== -->
44
+ EOS
45
+
46
+ content = banner_begin + content + banner_end
47
+
48
+ end
7
49
 
8
50
  end # module Engine
9
- end # module Markdown
51
+ end # module Markdown
@@ -1,7 +1,9 @@
1
1
  module Markdown
2
2
  module Engine
3
3
 
4
- def maruku_to_html( content )
4
+ def maruku_to_html( content, options={} )
5
+ puts " Converting Markdown-text (#{@content.length} bytes) to HTML using library maruku..."
6
+
5
7
  Maruku.new( content, {:on_error => :raise} ).to_html
6
8
  end
7
9
 
@@ -1,11 +1,13 @@
1
1
  module Markdown
2
2
  module Engine
3
3
 
4
- def pandoc_ruby_to_html( content )
4
+ def pandoc_ruby_to_html( content, options={} )
5
+ puts " Converting Markdown-text (#{@content.length} bytes) to HTML using library pandoc_ruby..."
6
+
5
7
  content = PandocRuby.new( content, :from => :markdown, :to => :html ).convert
6
8
  end
7
9
 
8
- def pandoc_ruby_to_html_incremental( content )
10
+ def pandoc_ruby_to_html_incremental( content, options={} )
9
11
  content = PandocRuby.new( content, :from => :markdown, :to => :html ).convert
10
12
  content = content.gsub(/<(ul|ol)/) do |match|
11
13
  "#{Regexp.last_match(0)} class='step'"
@@ -18,13 +20,13 @@ module Markdown
18
20
  # pandoc-ruby:
19
21
  # converter: pandoc-ruby-to-s5
20
22
 
21
- def pandoc_ruby_to_s5( content )
23
+ def pandoc_ruby_to_s5( content, options={} )
22
24
  content = PandocRuby.new( content, {:from => :markdown, :to => :s5}, :smart ).convert
23
25
  content = content.gsub(/class="incremental"/,'class="step"')
24
26
  content = content.to_a[13..-1].join # remove the layout div
25
27
  end
26
28
 
27
- def pandoc_ruby_to_s5_incremental( content )
29
+ def pandoc_ruby_to_s5_incremental( content, options={} )
28
30
  content = PandocRuby.new( content, {:from => :markdown, :to => :s5 }, :incremental, :smart ).convert
29
31
  content = content.gsub(/class="incremental"/,'class="step"')
30
32
  content = content.to_a[13..-1].join # remove the layout div
@@ -1,7 +1,9 @@
1
1
  module Markdown
2
2
  module Engine
3
3
 
4
- def rdiscount_to_html( content )
4
+ def rdiscount_to_html( content, options={} )
5
+ puts " Converting Markdown-text (#{@content.length} bytes) to HTML using library rdiscount..."
6
+
5
7
  RDiscount.new( content ).to_html
6
8
  end
7
9
 
@@ -0,0 +1,46 @@
1
+ module Markdown
2
+ module Engine
3
+
4
+ def redcarpet_to_html( content, options={} )
5
+
6
+ ## NB: uses redcarpet2
7
+ #
8
+ # see https://github.com/tanoku/redcarpet
9
+
10
+ extensions_ary = options.fetch( 'extensions', [] )
11
+
12
+ extensions_hash = {}
13
+ extensions_ary.each do |e|
14
+ extensions_hash[ e.to_sym ] = true
15
+ end
16
+
17
+ puts " Converting Markdown-text (#{@content.length} bytes) to HTML using library redcarpet (#{Redcarpet::VERSION}) w/ HTML render"
18
+ puts " using extensions: [#{extensions_ary.join(', ')}]"
19
+
20
+ redcarpet = Redcarpet::Markdown.new( Redcarpet::Render::HTML, extensions_hash )
21
+ content = redcarpet.render( content )
22
+
23
+ # todo: check content size and newlines
24
+ # check banner option?
25
+ # only add banner if some newlines and size > treshold?
26
+
27
+ banner_begin =<<EOS
28
+ <!-- === begin markdown block =====================================================
29
+
30
+ generated by #{Markdown.banner}
31
+ on #{Time.now} with Markdown engine redcarpet (#{Redcarpet::VERSION}) w/ HTML render
32
+ using extensions: [#{extensions_ary.join(', ')}]
33
+ -->
34
+ EOS
35
+
36
+ banner_end =<<EOS
37
+ <!-- === end markdown block ===================================================== -->
38
+ EOS
39
+
40
+ content = banner_begin + content + banner_end
41
+
42
+
43
+ end
44
+
45
+ end # module Engine
46
+ end # module Markdown
@@ -1,7 +1,9 @@
1
1
  module Markdown
2
2
  module Engine
3
3
 
4
- def rpeg_markdown_to_html( content )
4
+ def rpeg_markdown_to_html( content, options={} )
5
+ puts " Converting Markdown-text (#{@content.length} bytes) to HTML using library rpeg_markdown..."
6
+
5
7
  PEGMarkdown.new( content ).to_html
6
8
  end
7
9
 
@@ -25,67 +25,67 @@ module Markdown
25
25
  @opts = Opts.new
26
26
  end
27
27
 
28
-
29
- def with_output_path( dest, output_path )
30
- dest_full = File.expand_path( dest, output_path )
31
- logger.debug "dest_full=#{dest_full}"
32
-
33
- # make sure dest path exists
34
- dest_path = File.dirname( dest_full )
35
- logger.debug "dest_path=#{dest_path}"
36
- FileUtils.makedirs( dest_path ) unless File.directory? dest_path
37
- dest_full
38
- end
39
-
40
28
  def create_doc( fn )
41
-
42
- # expand output path in current dir and make sure output path exists
43
- outpath = File.expand_path( opts.output_path )
44
- logger.debug "outpath=#{outpath}"
45
- FileUtils.makedirs( outpath ) unless File.directory? outpath
46
-
47
- dirname = File.dirname( fn )
29
+ dirname = File.dirname( fn )
48
30
  basename = File.basename( fn, '.*' )
49
- extname = File.extname( fn )
31
+ extname = File.extname( fn )
32
+
50
33
  logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}"
51
34
 
52
- # change working dir to sourcefile dir
35
+ if opts.output_path == '.'
36
+ # expand output path in current dir
37
+ outpath = File.expand_path( dirname )
38
+ else
39
+ # expand output path in user supplied dir and make sure output path exists
40
+ outpath = File.expand_path( opts.output_path )
41
+ FileUtils.makedirs( outpath ) unless File.directory? outpath
42
+ end
43
+ logger.debug "outpath=#{outpath}"
44
+
53
45
  # todo: add a -c option to commandline? to let you set cwd?
54
-
46
+
47
+
48
+ # change working dir to sourcefile dir (that is, dirname); push working folder/dir
55
49
  newcwd = File.expand_path( dirname )
56
50
  oldcwd = File.expand_path( Dir.pwd )
57
51
 
58
- unless newcwd == oldcwd then
59
- logger.debug "oldcwd=#{oldcwd}"
60
- logger.debug "newcwd=#{newcwd}"
61
- Dir.chdir newcwd
52
+ unless newcwd == oldcwd
53
+ logger.debug "oldcwd=>#{oldcwd}<, newcwd=>#{newcwd}<"
54
+ Dir.chdir( newcwd )
62
55
  end
63
56
 
64
- inname = "#{dirname}/#{basename}#{extname}"
65
-
66
- puts "Reading document '#{basename}#{extname} (in folder #{dirname})'..."
57
+ inname = "#{basename}#{extname}"
58
+ outname = "#{basename}.html"
67
59
 
60
+ logger.debug "inname=#{inname}, outname=#{outname}"
61
+
62
+ puts "*** #{inname} (#{dirname}) => #{outname} (#{(opts.output_path == '.') ? dirname : opts.output_path})..."
68
63
 
69
- logger.debug "inname=#{inname}"
70
-
71
64
  content = File.read( inname )
65
+ content = Markdown.new( content ).to_html # convert light-weight markup to hypertext
72
66
 
73
- # convert light-weight markup to hypertext
74
67
 
75
- content = Markdown.new( content ).to_html
76
-
77
- outname = "#{basename}.html"
78
- puts "Preparing #{outname} (in folder #{outpath})..."
79
-
80
- out = File.new( with_output_path( outname, outpath ), "w+" )
81
- out << "<!-- ======================================================================\n"
82
- out << " generated by #{Markdown.banner}\n"
83
- out << " on #{Time.now} with Markdown engine '#{Markdown.lib}'\n"
84
- out << " ====================================================================== -->\n"
68
+ ## todo: add Markdown.lib_options inspect/dump to banner
69
+
70
+ banner =<<EOS
71
+ <!-- ======================================================================
72
+ generated by #{Markdown.banner}
73
+ on #{Time.now} with Markdown engine '#{Markdown.lib}'
74
+ ====================================================================== -->
75
+ EOS
76
+
77
+ out = File.new( File.join( outpath, outname ), "w+" )
78
+ #### out << banner
85
79
  out << content
86
80
  out.flush
87
81
  out.close
88
82
 
83
+ ## pop/restore working folder/dir
84
+ unless newcwd == oldcwd
85
+ logger.debug "oldcwd=>#{oldcwd}<, newcwd=>#{newcwd}<"
86
+ Dir.chdir( oldcwd )
87
+ end
88
+
89
89
  end # method create_doc
90
90
 
91
91
 
@@ -107,8 +107,9 @@ module Markdown
107
107
  logger.debug "dirname=#{dirname}, basename=#{basename}, extname=#{extname}"
108
108
 
109
109
  Markdown.extnames.each do |e|
110
- logger.debug "File.exists? #{dirname}/#{basename}#{e}"
111
- return "#{dirname}/#{basename}#{e}" if File.exists?( "#{dirname}/#{basename}#{e}" )
110
+ newname = File.join( dirname, "#{basename}#{e}" )
111
+ logger.debug "File.exists? #{newname}"
112
+ return newname if File.exists?( newname )
112
113
  end # each extension (e)
113
114
 
114
115
  nil # not found; return nil
@@ -184,7 +185,7 @@ module Markdown
184
185
  def run( args )
185
186
  opt=OptionParser.new do |cmd|
186
187
 
187
- cmd.banner = "Usage: markdown [options] name"
188
+ cmd.banner = "Usage: markdown [options] files_or_dirs"
188
189
 
189
190
  cmd.on( '-o', '--output PATH', 'Output Path' ) { |path| opts.output_path = path }
190
191
 
@@ -203,9 +204,9 @@ markdown - Lets you convert plain text documents (#{Markdown.extnames.join(', ')
203
204
 
204
205
  Examples:
205
206
  markdown # Process all documents in working folder (that is, .)
206
- markdown ruby_tut # Process document or folder using Markdown
207
- markdown ruby_tut.text # Process document using Markdown
208
- markdown -o site ruby_tut # Output documents to site folder
207
+ markdown quickref # Process document or folder using Markdown
208
+ markdown quickref.text # Process document using Markdown
209
+ markdown -o site quickref # Output documents to site folder
209
210
 
210
211
  Further information:
211
212
  http://geraldb.github.com/markdown
@@ -3,19 +3,16 @@ module Markdown
3
3
  class Wrapper
4
4
 
5
5
  def initialize( lib, mn, content, options={} )
6
- @lib = lib
7
- @mn = mn
8
- @content = content
9
- @options = options
6
+ @lib = lib
7
+ @mn = mn
8
+ @content = content
9
+ @options = options
10
10
  end
11
11
 
12
12
  def to_html
13
13
  # call markdown filter; turn markdown lib name into method_name (mn)
14
14
  # eg. rpeg-markdown => rpeg_markdown_to_html
15
-
16
- puts " Converting Markdown-text (#{@content.length} bytes) to HTML using library '#{@lib}' calling '#{@mn}'..."
17
-
18
- send( @mn, @content ) # call 1st configured markdown engine e.g. kramdown_to_html( content )
15
+ send( @mn, @content, @options ) # call 1st configured markdown engine e.g. kramdown_to_html( content )
19
16
  end
20
17
 
21
18
  include Engine
@@ -54,9 +51,13 @@ module Markdown
54
51
  @@config = Config.new
55
52
  end
56
53
 
57
- lib = @@config.markdown_lib
58
- mn = @@config.markdown_to_html_method # lets you use differnt options/converters for a single markdown lib
59
- Wrapper.new( lib, mn, content, options )
54
+ lib = @@config.markdown_lib
55
+ mn = @@config.markdown_to_html_method # lets you use differnt options/converters for a single markdown lib
56
+ defaults = @@config.markdown_lib_defaults ## todo/fix: use mn / converter from defaults hash?? mn no longer needed??
57
+
58
+ props = Props.new( options, 'USER', Props.new( defaults, 'SYSTEM' ))
59
+
60
+ Wrapper.new( lib, mn, content, props )
60
61
  end
61
62
 
62
63
  end # module Markdown
metadata CHANGED
@@ -1,15 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown
3
3
  version: !ruby/object:Gem::Version
4
- hash: 792793622
5
- prerelease: 6
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
9
  - 0
10
- - beta
11
- - 1
12
- version: 0.2.0.beta1
10
+ version: 0.2.0
13
11
  platform: ruby
14
12
  authors:
15
13
  - Gerald Bauer
@@ -17,7 +15,7 @@ autorequire:
17
15
  bindir: bin
18
16
  cert_chain: []
19
17
 
20
- date: 2012-06-03 00:00:00 Z
18
+ date: 2012-06-06 00:00:00 Z
21
19
  dependencies:
22
20
  - !ruby/object:Gem::Dependency
23
21
  name: props
@@ -102,6 +100,7 @@ files:
102
100
  - lib/markdown/engines/maruku.rb
103
101
  - lib/markdown/engines/pandoc_ruby.rb
104
102
  - lib/markdown/engines/rdiscount.rb
103
+ - lib/markdown/engines/redcarpet.rb
105
104
  - lib/markdown/engines/rpeg_markdown.rb
106
105
  - lib/markdown/gen.rb
107
106
  - lib/markdown/wrapper.rb
@@ -128,14 +127,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
127
  required_rubygems_version: !ruby/object:Gem::Requirement
129
128
  none: false
130
129
  requirements:
131
- - - ">"
130
+ - - ">="
132
131
  - !ruby/object:Gem::Version
133
- hash: 25
132
+ hash: 3
134
133
  segments:
135
- - 1
136
- - 3
137
- - 1
138
- version: 1.3.1
134
+ - 0
135
+ version: "0"
139
136
  requirements: []
140
137
 
141
138
  rubyforge_project: markdown