markdown 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ ### 0.1 / 2012-05-26
2
+
3
+ * Everything is new. First release
@@ -0,0 +1,8 @@
1
+ History.markdown
2
+ Manifest.txt
3
+ README.markdown
4
+ Rakefile
5
+ lib/markdown_select.rb
6
+ lib/markdown_select/config.rb
7
+ lib/markdown_select/engine.rb
8
+ lib/markdown_select/markdown_select.rb
@@ -0,0 +1,42 @@
1
+ # Markdown Select - Use Your Markdown Library of Choice
2
+
3
+ * [geraldb.github.com/markdown_select](http://geraldb.github.com/markdown_select)
4
+
5
+ ## Description
6
+
7
+ The Markdown Select (`markdown_select`) Ruby gem lets you use your markdown library of choice.
8
+ Preconfigured markdown libraries include:
9
+
10
+ * `kramdown`
11
+ * `bluecloth`
12
+ * `maruku`
13
+ * `rpeg-markdown`
14
+ * `rdiscount`
15
+ * `pandoc-ruby`
16
+
17
+
18
+ ## Usage
19
+
20
+ require 'markdown_select'
21
+
22
+ MarkdownSelect.new( 'Hello World' ).to_html
23
+
24
+
25
+ ## Install
26
+
27
+ Just install the gem:
28
+
29
+ $ gem install markdown_select
30
+
31
+
32
+ ## Questions? Comments?
33
+
34
+ Send them along to the
35
+ [Free Web Slide Show Alternatives (S5, S6, S9, Slidy And Friends) Forum/Mailing List](http://groups.google.com/group/webslideshow).
36
+ Thanks!
37
+
38
+
39
+ ## License
40
+
41
+ The `markdown_select` scripts are dedicated to the public domain.
42
+ Use it as you please with no restrictions whatsoever.
@@ -0,0 +1,22 @@
1
+ require 'hoe'
2
+ require './lib/markdown_select.rb'
3
+
4
+ Hoe.spec 'markdown' do
5
+
6
+ self.version = MarkdownSelect::VERSION
7
+
8
+ self.summary = 'Markdown - Use Your Markdown Library of Choice'
9
+ self.url = 'http://geraldb.github.com/markdown_select'
10
+
11
+ self.author = 'Gerald Bauer'
12
+ self.email = 'webslideshow@googlegroups.com'
13
+
14
+ self.extra_deps = [
15
+ ['kramdown','>= 0.13.6']
16
+ ]
17
+
18
+ # switch extension to .markdown for gihub formatting
19
+ self.readme_file = 'README.markdown'
20
+ self.history_file = 'History.markdown'
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+
2
+ $LOAD_PATH.unshift( File.expand_path( File.dirname(__FILE__) ) )
3
+
4
+ # core and stlibs
5
+
6
+ require 'yaml'
7
+
8
+
9
+ # our own code
10
+
11
+ require 'markdown_select/config'
12
+ require 'markdown_select/engine'
13
+ require 'markdown_select/markdown_select'
14
+
15
+
16
+ ## todo: add main for bin (see slideshow)
17
+
18
+ module MarkdownSelect
19
+
20
+ VERSION = '0.0.1'
21
+
22
+ end
@@ -0,0 +1,64 @@
1
+ module MarkdownSelect
2
+
3
+ class Config
4
+
5
+ def initialize
6
+ @hash = {}
7
+ end
8
+
9
+
10
+ def load
11
+ # todo/fix: check more locations; merge config files
12
+
13
+ # check for user settings in working folder (check for slideshow.yml)
14
+
15
+ config_user_file = "./markdown.yml"
16
+ if File.exists?( config_user_file )
17
+ puts "Loading settings from '#{config_user_file}'..."
18
+ @hash[ 'user' ] = YAML.load_file( config_user_file )
19
+ end
20
+ end
21
+
22
+
23
+ def markdown_to_html_method( lib )
24
+ method = @hash.fetch( 'user', {} ).fetch( lib, {} ).fetch( 'converter', nil )
25
+
26
+ # use default name
27
+ if method.nil?
28
+ method = "#{lib.downcase}_to_html"
29
+ end
30
+
31
+ method.tr('-','_').to_sym
32
+ end
33
+
34
+
35
+ # note: only kramdown is listed as a dependency in gem specs (because it's Ruby only and, thus, easy to install)
36
+ # if you want to use other markdown libs install the required/desired lib e.g.
37
+ # use gem install rdiscount for rdiscount and so on
38
+ #
39
+ # also note for now the first present markdown library gets used
40
+ # the search order is first come, first serve, that is: rdiscount, rpeg-markdown, maruku, bluecloth, kramdown (fallback, always present)
41
+
42
+ BUILTIN_LIBS = [
43
+ 'pandoc-ruby',
44
+ 'rdiscount',
45
+ 'rpeg-markdown',
46
+ 'maruku',
47
+ 'bluecloth',
48
+ 'kramdown'
49
+ ]
50
+
51
+ def known_markdown_libs
52
+ # returns an array of known markdown engines e.g.
53
+ # [ pandoc-ruby, rdiscount, rpeg-markdown, maruku, bluecloth, kramdown ]
54
+
55
+ ## todo: allow single lib para instead of libs
56
+ ## todo: allow ENV setting markdown_[select]_lib=xxxx
57
+
58
+ user_libs = @hash.fetch( 'user', {} ).fetch( 'libs', [] )
59
+
60
+ user_libs.length > 0 ? user_libs : BUILTIN_LIBS
61
+ end
62
+
63
+ end # class Config
64
+ end # module MarkdownSelect
@@ -0,0 +1,59 @@
1
+ module MarkdownSelect
2
+ module Engine
3
+
4
+ def pandoc_ruby_to_html( content )
5
+ content = PandocRuby.new( content, :from => :markdown, :to => :html ).convert
6
+ end
7
+
8
+ def pandoc_ruby_to_html_incremental( content )
9
+ content = PandocRuby.new( content, :from => :markdown, :to => :html ).convert
10
+ content = content.gsub(/<(ul|ol)/) do |match|
11
+ "#{Regexp.last_match(0)} class='step'"
12
+ end
13
+ content
14
+ end
15
+
16
+ # sample how to use your own converter
17
+ # configure in markdown.yml
18
+ # pandoc-ruby:
19
+ # converter: pandoc-ruby-to-s5
20
+
21
+ def pandoc_ruby_to_s5( content )
22
+ content = PandocRuby.new( content, {:from => :markdown, :to => :s5}, :smart ).convert
23
+ content = content.gsub(/class="incremental"/,'class="step"')
24
+ content = content.to_a[13..-1].join # remove the layout div
25
+ end
26
+
27
+ def pandoc_ruby_to_s5_incremental( content )
28
+ content = PandocRuby.new( content, {:from => :markdown, :to => :s5 }, :incremental, :smart ).convert
29
+ content = content.gsub(/class="incremental"/,'class="step"')
30
+ content = content.to_a[13..-1].join # remove the layout div
31
+ end
32
+
33
+
34
+ def rdiscount_to_html( content )
35
+ RDiscount.new( content ).to_html
36
+ end
37
+
38
+
39
+ def rpeg_markdown_to_html( content )
40
+ PEGMarkdown.new( content ).to_html
41
+ end
42
+
43
+
44
+ def maruku_to_html( content )
45
+ Maruku.new( content, {:on_error => :raise} ).to_html
46
+ end
47
+
48
+
49
+ def bluecloth_to_html( content )
50
+ BlueCloth.new( content ).to_html
51
+ end
52
+
53
+
54
+ def kramdown_to_html( content )
55
+ Kramdown::Document.new( content ).to_html
56
+ end
57
+
58
+ end # module Engine
59
+ end # module MarkdownSelect
@@ -0,0 +1,80 @@
1
+ module MarkdownSelect
2
+
3
+ class Proxy
4
+
5
+ def initialize( lib, mn, content, options={} )
6
+ @lib = lib
7
+ @mn = mn
8
+ @content = content
9
+ @options = options
10
+ end
11
+
12
+ def to_html
13
+ # call markdown filter; turn markdown lib name into method_name (mn)
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 )
19
+ end
20
+
21
+ include Engine
22
+
23
+ end # class Proxy
24
+
25
+ @@markdown_config = nil
26
+ @@markdown_libs = []
27
+ @@markdown_mn = nil
28
+
29
+ def self.load_markdown_libs
30
+
31
+ # check for available markdown libs/gems
32
+ # try to require each lib and remove any not installed
33
+
34
+ @@markdown_config.known_markdown_libs.each do |lib|
35
+ begin
36
+ require lib
37
+ @@markdown_libs << lib
38
+ rescue LoadError => ex
39
+ ## todo: use logger.debug instead of puts
40
+ puts "Markdown library #{lib} not found. Use gem install #{lib} to install."
41
+ end
42
+ end
43
+
44
+ puts " Found #{@@markdown_libs.length} Markdown libraries: #{@@markdown_libs.join(', ')}"
45
+ end
46
+
47
+ def self.lib
48
+ if @@markdown_config.nil?
49
+ @@markdown_config = Config.new
50
+ @@markdown_config.load
51
+
52
+ load_markdown_libs
53
+
54
+ # lets you use differnt options/converters for a single markdown lib
55
+ @@markdown_mn = @@markdown_config.markdown_to_html_method( @@markdown_libs.first )
56
+ end
57
+
58
+ @@markdown_libs.first
59
+ end
60
+
61
+ def self.new( content, options={} )
62
+
63
+ ## todo: allow options to pass in
64
+ ## lets you change markdown engine/converter for every call
65
+ ## e.g. lets you add config properties (as headers) to your document (for example)
66
+
67
+ if @@markdown_config.nil?
68
+ @@markdown_config = Config.new
69
+ @@markdown_config.load
70
+
71
+ load_markdown_libs
72
+
73
+ # lets you use differnt options/converters for a single markdown lib
74
+ @@markdown_mn = @@markdown_config.markdown_to_html_method( @@markdown_libs.first )
75
+ end
76
+
77
+ Proxy.new( @@markdown_libs.first, @@markdown_mn, content, options )
78
+ end
79
+
80
+ end # module MarkdownSelect
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Gerald Bauer
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: kramdown
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 39
29
+ segments:
30
+ - 0
31
+ - 13
32
+ - 6
33
+ version: 0.13.6
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: rdoc
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 19
45
+ segments:
46
+ - 3
47
+ - 10
48
+ version: "3.10"
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: hoe
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 29
60
+ segments:
61
+ - 2
62
+ - 15
63
+ version: "2.15"
64
+ type: :development
65
+ version_requirements: *id003
66
+ description: |-
67
+ The Markdown Select (`markdown_select`) Ruby gem lets you use your markdown library of choice.
68
+ Preconfigured markdown libraries include:
69
+
70
+ * `kramdown`
71
+ * `bluecloth`
72
+ * `maruku`
73
+ * `rpeg-markdown`
74
+ * `rdiscount`
75
+ * `pandoc-ruby`
76
+ email: webslideshow@googlegroups.com
77
+ executables: []
78
+
79
+ extensions: []
80
+
81
+ extra_rdoc_files:
82
+ - Manifest.txt
83
+ files:
84
+ - History.markdown
85
+ - Manifest.txt
86
+ - README.markdown
87
+ - Rakefile
88
+ - lib/markdown_select.rb
89
+ - lib/markdown_select/config.rb
90
+ - lib/markdown_select/engine.rb
91
+ - lib/markdown_select/markdown_select.rb
92
+ homepage: http://geraldb.github.com/markdown_select
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --main
98
+ - README.markdown
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ hash: 3
107
+ segments:
108
+ - 0
109
+ version: "0"
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ hash: 3
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project: markdown
122
+ rubygems_version: 1.8.17
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Markdown - Use Your Markdown Library of Choice
126
+ test_files: []
127
+