markdown_meta 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,5 @@
1
+ markdown - a meta-gem for markdown parsing and content generation
2
+ =================================================================
3
+
4
+ There are many markdown libraries for Ruby. Some are pure-Ruby and some have C
5
+ or Java extensions. This gem aims to unify them in a common API.
@@ -0,0 +1,24 @@
1
+ # Backend for the Kramdown pure-ruby markdown parser
2
+ require 'kramdown'
3
+
4
+ module MarkdownMeta
5
+ module Backend
6
+ module Kramdown
7
+ def self.to_html(content)
8
+ html = ::Kramdown::Document.new(content).to_html
9
+ if content.respond_to? :encoding
10
+ html.force_encoding content.encoding
11
+ end
12
+ html
13
+ end
14
+
15
+ def self.to_toc(content)
16
+ html = ::Kramdown::Document.new(content).to_toc
17
+ if content.respond_to? :encoding
18
+ html.force_encoding content.encoding
19
+ end
20
+ html
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ # Backend for the rdiscount C ext markdown parser
2
+ require 'rdiscount'
3
+
4
+ module MarkdownMeta
5
+ module Backend
6
+ module RDiscount
7
+ def self.to_html(content)
8
+ ::RDiscount.new(content).to_html
9
+ end
10
+
11
+ def self.to_toc(content)
12
+ ::RDiscount.new(content).toc_content
13
+ end
14
+ end
15
+
16
+ # for impl= capitalization compat
17
+ Rdiscount = RDiscount
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ module MarkdownMeta
2
+ module Backend
3
+ def self.impl=(backend)
4
+ @impl = load_impl(backend)
5
+ end
6
+
7
+ def self.impl
8
+ @impl ||= default_impl
9
+ end
10
+
11
+ private
12
+
13
+ def self.load_impl(impl_name)
14
+ begin
15
+ require "markdown_meta/backend/#{impl_name}"
16
+ cls_name = impl_name.split('_').map(&:capitalize).join
17
+ MarkdownMeta::Backend.const_get(cls_name)
18
+ rescue LoadError => e
19
+ raise LoadError, "failed to load markdown backend `#{impl_name}`: " + e.message, e.backtrace
20
+ rescue NameError => e
21
+ raise NameError, "failed to load markdown backend `#{impl_name}`: " + e.message, e.backtrace
22
+ end
23
+ end
24
+
25
+ def self.default_impl
26
+ return MarkdownMeta::Backend::RDiscount if defined? RDiscount
27
+ return load_impl('kramdown')
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ require 'markdown_meta/backend'
2
+
3
+ module MarkdownMeta
4
+ def self.to_html(content)
5
+ MarkdownMeta::Backend.impl.to_html(content)
6
+ end
7
+
8
+ def self.to_toc(content)
9
+ MarkdownMeta::Backend.impl.to_html(content)
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'markdown_meta'
3
+ s.version = '0.0.1'
4
+ s.summary = "Meta-gem for markdown parsing"
5
+ s.date = '2012-03-09'
6
+ s.email = 'headius@headius.com'
7
+ s.homepage = 'https://github.com/headius/markdown_meta'
8
+ s.authors = ["Charles Oliver Nutter"]
9
+ # = MANIFEST =
10
+ s.files = %w[
11
+ README.md
12
+ markdown_meta.gemspec
13
+ lib/markdown_meta.rb
14
+ lib/markdown_meta/backend.rb
15
+ lib/markdown_meta/backend/rdiscount.rb
16
+ lib/markdown_meta/backend/kramdown.rb
17
+ markdown_meta.gemspec
18
+ ]
19
+ # = MANIFEST =
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown_meta
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Charles Oliver Nutter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: headius@headius.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - markdown_meta.gemspec
22
+ - lib/markdown_meta.rb
23
+ - lib/markdown_meta/backend.rb
24
+ - lib/markdown_meta/backend/rdiscount.rb
25
+ - lib/markdown_meta/backend/kramdown.rb
26
+ homepage: https://github.com/headius/markdown_meta
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: !binary |-
37
+ MA==
38
+ none: false
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: !binary |-
44
+ MA==
45
+ none: false
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 1.8.15
49
+ signing_key:
50
+ specification_version: 3
51
+ summary: Meta-gem for markdown parsing
52
+ test_files: []
53
+ ...