markdpwn 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.project ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>markdpwn</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>com.aptana.ruby.core.rubynature</nature>
16
+ <nature>com.aptana.projects.webnature</nature>
17
+ </natures>
18
+ </projectDescription>
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source :rubygems
2
+
3
+ # Code formatting.
4
+ gem 'pygments.rb', '>= 0.2.4'
5
+
6
+ # Github formatting.
7
+ gem 'github-markup', '>= 0.7.1', :require => 'github/markup'
8
+ gem 'redcarpet', '>= 2.1.0'
9
+ gem 'RedCloth', '>= 4.2.9'
10
+ gem 'rdoc', '>= 3.12'
11
+ gem 'org-ruby', '>= 0.6.0', :platform => :mri_18
12
+ gem 'creole', '>= 0.4.2'
13
+ gem 'wikicloth', '>= 0.7.1'
14
+
15
+ group :development do
16
+ gem 'minitest', '>= 2.11'
17
+ gem 'yard', '>= 0.7'
18
+ gem 'bundler', '>= 1.0.22'
19
+ gem 'jeweler', '>= 1.8.3'
20
+ gem 'rcov', '>= 0', :platform => :mri_18
21
+ gem 'simplecov', '>= 0', :platform => :mri_19
22
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ RedCloth (4.2.9)
5
+ blankslate (2.1.2.4)
6
+ builder (3.0.0)
7
+ creole (0.4.2)
8
+ expression_parser (0.9.0)
9
+ ffi (1.0.11)
10
+ git (1.2.5)
11
+ github-markup (0.7.1)
12
+ jeweler (1.8.3)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ rdoc
17
+ json (1.6.5)
18
+ minitest (2.11.2)
19
+ org-ruby (0.6.0)
20
+ rubypants (>= 0.2.0)
21
+ pygments.rb (0.2.4)
22
+ rubypython (~> 0.5.3)
23
+ rake (0.9.2.2)
24
+ rcov (1.0.0)
25
+ rdoc (3.12)
26
+ json (~> 1.4)
27
+ redcarpet (2.1.0)
28
+ rubypants (0.2.0)
29
+ rubypython (0.5.3)
30
+ blankslate (>= 2.1.2.3)
31
+ ffi (~> 1.0.7)
32
+ simplecov (0.4.2)
33
+ simplecov-html (~> 0.4.4)
34
+ simplecov-html (0.4.5)
35
+ wikicloth (0.7.1)
36
+ builder
37
+ expression_parser
38
+ yard (0.7.5)
39
+
40
+ PLATFORMS
41
+ ruby
42
+
43
+ DEPENDENCIES
44
+ RedCloth (>= 4.2.9)
45
+ bundler (>= 1.0.22)
46
+ creole (>= 0.4.2)
47
+ github-markup (>= 0.7.1)
48
+ jeweler (>= 1.8.3)
49
+ minitest (>= 2.11)
50
+ org-ruby (>= 0.6.0)
51
+ pygments.rb (>= 0.2.4)
52
+ rcov
53
+ rdoc (>= 3.12)
54
+ redcarpet (>= 2.1.0)
55
+ simplecov
56
+ wikicloth (>= 0.7.1)
57
+ yard (>= 0.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Victor Costan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,76 @@
1
+ # markdpwn
2
+
3
+ Rails engine providing a clone of Git-flavored Markdown.
4
+
5
+
6
+ ## Usage
7
+
8
+ **Disclaimer**: this gem uses semantic versioning, so its API is not guaranteed
9
+ to be stable until it reaches version 1.0. Use integration tests to avoid
10
+ surprises.
11
+
12
+ ```ruby
13
+ require 'markdpwn'
14
+ code = "puts {:key => nil}.inspect\n"
15
+ Markdpwn.markup code, :file_name => 'code.rb', :mime_type => 'text/x-ruby'
16
+ ```
17
+
18
+ The `markup` call above outputs the HTML code below.
19
+
20
+ ```html
21
+ <div class="markdpwn-parsed-code">
22
+ <span class="nb">puts</span> <span class="p">{</span><span class="ss">:key</span> <span class="o">=&gt;</span> <span class="kp">nil</span><span class="p">}</span><span class="o">.</span><span class="n">inspect</span>
23
+ </div>
24
+ ```
25
+
26
+ You can pass `:file_name` and/or `:mime_type` to help `markup` figure out
27
+ which formatter to use. If no option is present, pygments is asked to guess the
28
+ text document's language.
29
+
30
+ If you know the contents is _markdpwn_ (close to Github-Flavored Markup), use
31
+ the `markdpwn` method directly.
32
+
33
+ ```ruby
34
+ require 'markdpwn'
35
+ comment = "I like what you did to `markdpwn`."
36
+ Markdpwn.markdpwn comment
37
+ # => "<p>I like what you did to <code>markdpwn</code>.</p>\n"
38
+ ```
39
+
40
+ ## Dependencies
41
+
42
+ The `pygments.rb` gem requires the Python VM library and the `pygments` package.
43
+ They are installed by default on OSX and Ubuntu. The following command installs
44
+ them on Fedora.
45
+
46
+ ```bash
47
+ sudo yum install -y python-devel python-pygments
48
+ ```
49
+
50
+ The `github-markup` gem requires `asciidoc`, PERL together with the
51
+ `Pod::Simple` library, and Python together with the `rst2html` tool. The
52
+ following command installs them on Fedora.
53
+
54
+ ```bash
55
+ sudo yum install -y asciidoc perl-Pod-Simple python-docutils
56
+ ```
57
+
58
+
59
+ ## Contributing to markdpwn
60
+
61
+ * Check out the latest master to make sure the feature hasn't been implemented
62
+ or the bug hasn't been fixed yet.
63
+ * Check out the issue tracker to make sure someone already hasn't requested it
64
+ and/or contributed it.
65
+ * Fork the project.
66
+ * Start a feature/bugfix branch.
67
+ * Commit and push until you are happy with your contribution.
68
+ * Make sure to add tests for it. This is important so I don't break it in a
69
+ future version unintentionally.
70
+ * Please try not to mess with the Rakefile, version, or history. If you want to
71
+ have your own version, or is otherwise necessary, that is fine, but please
72
+ isolate to its own commit so I can cherry-pick around it.
73
+
74
+ ## Copyright
75
+
76
+ Copyright (c) 2012 Victor Costan. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "markdpwn"
18
+ gem.homepage = "http://github.com/pwnall/markdpwn"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{HTML-formats text documents such as Markdown, textile, and source code}
21
+ gem.description = %Q{HTML-formats text documents such as Markdown, textile, and source code}
22
+ gem.email = "victor@costan.us"
23
+ gem.authors = ["Victor Costan"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ task :default => :test
36
+
37
+ require 'yard'
38
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,83 @@
1
+ require 'pygments.rb'
2
+
3
+ module Markdpwn
4
+
5
+ # Code formatting.
6
+ module Code
7
+ # Marks up code.
8
+ #
9
+ # @param [String] code the code to be formatted
10
+ # @param [Hash] options code properties that help choose the formatter
11
+ # @option options [String] :mime_type the MIME type of the code file; e-mail
12
+ # attachments and git blobs have MIME types
13
+ # @option options [String] :file_name the name of the file containing the
14
+ # piece of code; meaningful for files in version control repositories,
15
+ # e-mail attachments, and code fetched from links
16
+ # @option options [String] :language the name of the code's language; GFM code
17
+ # blocks can include a language name
18
+ # @return [String] a HTML fragment containing the formatted code
19
+ def self.render(code, options = {})
20
+ [
21
+ %Q|<div class="markdpwn-parsed-code">\n|,
22
+ pygment(code, options),
23
+ "\n</div>"
24
+ ].join ''
25
+ end
26
+
27
+ # The raw Pygments output for parsing some code.
28
+ #
29
+ def self.pygment(code, options = {})
30
+ lexer = pygments_lexer options
31
+ Pygments.highlight code, :lexer => lexer, :formatter => 'html',
32
+ :options => { :encoding => 'utf-8', :nowrap => true }
33
+ end
34
+
35
+ # The name of the Python lexer that is most suitable for some code.
36
+ #
37
+ # @param [Hash] options code properties that help choose the formatter
38
+ # @option options [String] :code the code to be parsed, or a sample of the
39
+ # code; if code is provided, a language will always be returned
40
+ # @see Markdpwn::Code#render for other available options
41
+ # @return [String] the name of a Pygments lexer that can parse the code
42
+ def self.pygments_lexer(options = {})
43
+ if language = options[:language]
44
+ lexer = begin
45
+ Pygments.lexer_name_for :lexer => language
46
+ rescue RubyPython::PythonError
47
+ nil
48
+ end
49
+ return lexer if lexer
50
+ end
51
+
52
+ if mime_type = options[:mime_type]
53
+ lexer = begin
54
+ Pygments.lexer_name_for :mimetype => mime_type
55
+ rescue RubyPython::PythonError
56
+ nil
57
+ end
58
+ return lexer if lexer
59
+ end
60
+
61
+ if file_name = options[:file_name]
62
+ lexer = begin
63
+ Pygments.lexer_name_for :filename => file_name
64
+ rescue RubyPython::PythonError
65
+ nil
66
+ end
67
+ return lexer if lexer
68
+ end
69
+
70
+ if code = options[:code]
71
+ lexer = begin
72
+ Pygments.lexer_name_for code
73
+ rescue RubyPython::PythonError
74
+ nil
75
+ end
76
+ return lexer if lexer
77
+ end
78
+
79
+ nil
80
+ end
81
+ end # namespace Markdpwn::Code
82
+
83
+ end # namespace Markdpwn
@@ -0,0 +1,35 @@
1
+ require 'redcarpet'
2
+ require 'RedCloth'
3
+ require 'rdoc'
4
+ require 'creole'
5
+ require 'wikicloth'
6
+
7
+ require 'github/markup'
8
+
9
+ module Markdpwn
10
+
11
+ # Document (e.g. textile, markdown) formatting.
12
+ module Docs
13
+ # The raw GitHub::Markup output for parsing a text document.
14
+ #
15
+ # @param [Hash] options code properties that help choose the formatter
16
+ # @option options [String] :mime_type the MIME type of the code file; e-mail
17
+ # attachments and git blobs have MIME types
18
+ # @option options [String] :file_name the name of the file containing the
19
+ # piece of code; meaningful for files in version control repositories,
20
+ # e-mail attachments, and code fetched from links
21
+ # @return [String] the GitHub::Markup output, or nil if the file cannot be
22
+ # rendered by GitHub::Markup
23
+ def self.gh_markup(text, options = {})
24
+ # NOTE: the MIME type is specified in the API so clients won't need to
25
+ # change if/when MIME-based detection is added
26
+ file_name = options[:file_name]
27
+ if file_name && GitHub::Markup.can_render?(file_name)
28
+ GitHub::Markup.render file_name, text
29
+ else
30
+ nil
31
+ end
32
+ end
33
+ end # namespace Markdpwn::Docs
34
+
35
+ end # namespace Markdpwn
@@ -0,0 +1,43 @@
1
+ require 'redcarpet'
2
+
3
+ module Markdpwn
4
+
5
+ # markdpwn is a clone of gfm (Git-Flavored Markdown).
6
+ module Dpwn
7
+ # Marks up text using markdpwn.
8
+ #
9
+ # The caller is responsible for making sure that the text can be rendered
10
+ # using markdpwn.
11
+ #
12
+ # @param [String] text the text to be formatted using Markdpwn
13
+ # @param [Hash] options rendering options (currently ignored)
14
+ # @return [String] a HTML fragment containing the formatted text
15
+ def self.render(text, options = {})
16
+ renderer = Markdpwn::RedCarpetRenderer.new
17
+ md = Redcarpet::Markdown.new renderer,
18
+ :autolink => true,
19
+ :no_intra_emphasis => true,
20
+ :tables => true,
21
+ :fenced_code_blocks => true,
22
+ :strikethrough => true,
23
+ :space_after_headers => true
24
+ md.render text
25
+ end
26
+
27
+ # Checks if some file should be formatted using Markdpwn.
28
+ # @param [Hash] options file properties considered in the decision process
29
+ # @option options [String] :mime_type the MIME type of the code file; e-mail
30
+ # attachments and git blobs have MIME types
31
+ # @option options [String] :file_name the name of the file containing the
32
+ # piece of code; meaningful for files in version control repositories,
33
+ # e-mail attachments, and code fetched from links
34
+ # @return [Boolean] true if the given file is suitable for Markdpwn, false
35
+ # otherwise
36
+ def self.accepts?(options)
37
+ return unless file_name = options[:file_name]
38
+ ext = File.extname file_name
39
+ ['.markdown', '.md'].include? ext
40
+ end
41
+ end # namespace MarkDpwn::Dpwn
42
+
43
+ end # namespace MarkDpwn
@@ -0,0 +1,31 @@
1
+ module Markdpwn
2
+ # Marks up a text document.
3
+ #
4
+ # @param [String] text the text to be formatted
5
+ # @param [Hash] options text file properties that help choose the formatter
6
+ # @option options [String] :mime_type the MIME type of the code file; e-mail
7
+ # attachments and git blobs have MIME types
8
+ # @option options [String] :file_name the name of the file containing the
9
+ # piece of code; meaningful for files in version control repositories,
10
+ # e-mail attachments, and code fetched from links
11
+ # @option options [String] :language the name of the text's language; GFM code
12
+ # blocks can include a language name
13
+ # @return [String] a HTML fragment containing the formatted text
14
+ def self.markup(text, options = {})
15
+ if Markdpwn::Dpwn.accepts? options
16
+ Markdpwn::Dpwn.render text, options
17
+ elsif html = Markdpwn::Docs.gh_markup(text, options)
18
+ html
19
+ else
20
+ Markdpwn::Code.render text, options
21
+ end
22
+ end
23
+
24
+ # Marks up a markdpwn text document.
25
+ #
26
+ # The caller is responsible for ensuring that the text uses markdpwn, otherwise
27
+ # extreme ugliness might ensue. Use Markdpwn.markup when unsure.
28
+ def self.markdpwn(text, options = {})
29
+ Markdpwn::Dpwn.render text, options
30
+ end
31
+ end # namespace MarkDpwn
@@ -0,0 +1,21 @@
1
+ module Markdpwn
2
+
3
+ # RedCarpet HTML renderer, augmented to parse code blocks.
4
+ # @private
5
+ class RedCarpetRenderer < Redcarpet::Render::HTML
6
+ DEFAULT_OPTIONS = {
7
+ :filter_html => true,
8
+ :no_styles => true,
9
+ :safe_links_only => true
10
+ }.freeze
11
+
12
+ def initialize(options = {})
13
+ super DEFAULT_OPTIONS.merge options
14
+ end
15
+
16
+ def block_code(code, language)
17
+ Markdpwn::Code.render code, :language => language
18
+ end
19
+ end # class MarkdDpwn::RedCarpetRenderer
20
+
21
+ end # namespace MarkDpwn
data/lib/markdpwn.rb ADDED
@@ -0,0 +1,10 @@
1
+ # HTML-formats text documents such as Markdown, textile, and source code.
2
+ module Markdpwn
3
+
4
+ end
5
+
6
+ require 'markdpwn/code.rb'
7
+ require 'markdpwn/docs.rb'
8
+ require 'markdpwn/dpwn.rb'
9
+ require 'markdpwn/glue.rb'
10
+ require 'markdpwn/red_carpet_renderer.rb'
data/markdpwn.gemspec ADDED
@@ -0,0 +1,106 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "markdpwn"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Victor Costan"]
12
+ s.date = "2012-02-22"
13
+ s.description = "HTML-formats text documents such as Markdown, textile, and source code"
14
+ s.email = "victor@costan.us"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".project",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.markdown",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/markdpwn.rb",
29
+ "lib/markdpwn/code.rb",
30
+ "lib/markdpwn/docs.rb",
31
+ "lib/markdpwn/dpwn.rb",
32
+ "lib/markdpwn/glue.rb",
33
+ "lib/markdpwn/red_carpet_renderer.rb",
34
+ "markdpwn.gemspec",
35
+ "test/fixtures/readme.asciidoc",
36
+ "test/fixtures/readme.md",
37
+ "test/fixtures/readme.pod",
38
+ "test/fixtures/readme.rdoc",
39
+ "test/fixtures/readme.rst",
40
+ "test/fixtures/readme.textile",
41
+ "test/fixtures/readme.wiki",
42
+ "test/fixtures/view.html.erb",
43
+ "test/helper.rb",
44
+ "test/markdpwn/code_test.rb",
45
+ "test/markdpwn/docs_test.rb",
46
+ "test/markdpwn/dpwn_test.rb",
47
+ "test/markdpwn_test.rb"
48
+ ]
49
+ s.homepage = "http://github.com/pwnall/markdpwn"
50
+ s.licenses = ["MIT"]
51
+ s.require_paths = ["lib"]
52
+ s.rubygems_version = "1.8.16"
53
+ s.summary = "HTML-formats text documents such as Markdown, textile, and source code"
54
+
55
+ if s.respond_to? :specification_version then
56
+ s.specification_version = 3
57
+
58
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
59
+ s.add_runtime_dependency(%q<pygments.rb>, [">= 0.2.4"])
60
+ s.add_runtime_dependency(%q<github-markup>, [">= 0.7.1"])
61
+ s.add_runtime_dependency(%q<redcarpet>, [">= 2.1.0"])
62
+ s.add_runtime_dependency(%q<RedCloth>, [">= 4.2.9"])
63
+ s.add_runtime_dependency(%q<rdoc>, [">= 3.12"])
64
+ s.add_runtime_dependency(%q<org-ruby>, [">= 0.6.0"])
65
+ s.add_runtime_dependency(%q<creole>, [">= 0.4.2"])
66
+ s.add_runtime_dependency(%q<wikicloth>, [">= 0.7.1"])
67
+ s.add_development_dependency(%q<minitest>, [">= 2.11"])
68
+ s.add_development_dependency(%q<yard>, [">= 0.7"])
69
+ s.add_development_dependency(%q<bundler>, [">= 1.0.22"])
70
+ s.add_development_dependency(%q<jeweler>, [">= 1.8.3"])
71
+ s.add_development_dependency(%q<rcov>, [">= 0"])
72
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
73
+ else
74
+ s.add_dependency(%q<pygments.rb>, [">= 0.2.4"])
75
+ s.add_dependency(%q<github-markup>, [">= 0.7.1"])
76
+ s.add_dependency(%q<redcarpet>, [">= 2.1.0"])
77
+ s.add_dependency(%q<RedCloth>, [">= 4.2.9"])
78
+ s.add_dependency(%q<rdoc>, [">= 3.12"])
79
+ s.add_dependency(%q<org-ruby>, [">= 0.6.0"])
80
+ s.add_dependency(%q<creole>, [">= 0.4.2"])
81
+ s.add_dependency(%q<wikicloth>, [">= 0.7.1"])
82
+ s.add_dependency(%q<minitest>, [">= 2.11"])
83
+ s.add_dependency(%q<yard>, [">= 0.7"])
84
+ s.add_dependency(%q<bundler>, [">= 1.0.22"])
85
+ s.add_dependency(%q<jeweler>, [">= 1.8.3"])
86
+ s.add_dependency(%q<rcov>, [">= 0"])
87
+ s.add_dependency(%q<simplecov>, [">= 0"])
88
+ end
89
+ else
90
+ s.add_dependency(%q<pygments.rb>, [">= 0.2.4"])
91
+ s.add_dependency(%q<github-markup>, [">= 0.7.1"])
92
+ s.add_dependency(%q<redcarpet>, [">= 2.1.0"])
93
+ s.add_dependency(%q<RedCloth>, [">= 4.2.9"])
94
+ s.add_dependency(%q<rdoc>, [">= 3.12"])
95
+ s.add_dependency(%q<org-ruby>, [">= 0.6.0"])
96
+ s.add_dependency(%q<creole>, [">= 0.4.2"])
97
+ s.add_dependency(%q<wikicloth>, [">= 0.7.1"])
98
+ s.add_dependency(%q<minitest>, [">= 2.11"])
99
+ s.add_dependency(%q<yard>, [">= 0.7"])
100
+ s.add_dependency(%q<bundler>, [">= 1.0.22"])
101
+ s.add_dependency(%q<jeweler>, [">= 1.8.3"])
102
+ s.add_dependency(%q<rcov>, [">= 0"])
103
+ s.add_dependency(%q<simplecov>, [">= 0"])
104
+ end
105
+ end
106
+
@@ -0,0 +1,4 @@
1
+ == List ==
2
+
3
+ - Eggs
4
+ - Ham
@@ -0,0 +1,14 @@
1
+ ## List
2
+
3
+ * Eggs
4
+ * Ham
5
+
6
+ ```ruby
7
+ p { :symbol => nil }
8
+ ```
9
+
10
+ ```
11
+ <h1>Heading 1</h1>
12
+
13
+ <%= render :partial => 'partial_name' %>
14
+ ```
@@ -0,0 +1,11 @@
1
+ =head2 List
2
+
3
+ =over 4
4
+
5
+ =item * Eggs
6
+
7
+ =item * Ham
8
+
9
+ =back
10
+
11
+ =cut
@@ -0,0 +1,4 @@
1
+ == List
2
+
3
+ * Eggs
4
+ * Ham
@@ -0,0 +1,9 @@
1
+ Title
2
+ =====
3
+
4
+ List
5
+ ----
6
+
7
+ * Eggs
8
+
9
+ * Ham
@@ -0,0 +1,4 @@
1
+ h2. List
2
+
3
+ * Eggs
4
+ * Ham
@@ -0,0 +1,4 @@
1
+ == List ==
2
+
3
+ * Eggs
4
+ * Ham
@@ -0,0 +1,5 @@
1
+ <!DOCTYPE html>
2
+
3
+ <h1>Heading 1</h1>
4
+
5
+ <%= render :partial => 'partial_name' %>
data/test/helper.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'minitest/unit'
11
+ require 'minitest/spec'
12
+
13
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ require 'markdpwn'
16
+
17
+ class MiniTest::Unit::TestCase
18
+ # The contents at test/fixtures/name.
19
+ def code_fixture(name)
20
+ File.read File.join(File.dirname(__FILE__), 'fixtures', name)
21
+ end
22
+ end
23
+
24
+ MiniTest::Unit.autorun
@@ -0,0 +1,104 @@
1
+ require File.expand_path('../helper', File.dirname(__FILE__))
2
+
3
+ describe Markdpwn::Code do
4
+ describe '#render return value' do
5
+ describe 'with view.html.erb' do
6
+ let :result do
7
+ Markdpwn::Code.render code_fixture('view.html.erb'),
8
+ :file_name => 'view.html.erb'
9
+ end
10
+
11
+ it 'is wrapped in a <div> with the markdpwn-parsed-code class' do
12
+ result.must_match /\A<div class="markdpwn-parsed-code">.*<\/div>\Z/m
13
+ end
14
+
15
+ it 'includes a parsed <h1> tag' do
16
+ result.must_match '<span class="nt">&lt;h1&gt;</span>'
17
+ end
18
+
19
+ it 'includes a parsed :partial symbol' do
20
+ result.must_match '<span class="ss">:partial</span>'
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '#pygment return value' do
26
+ describe 'with ruby code' do
27
+ let :result do
28
+ Markdpwn::Code.pygment ":symbol => 'string'", :language => 'ruby'
29
+ end
30
+
31
+ it 'includes a parsed symbol' do
32
+ result.must_match '<span class="ss">:symbol</span>'
33
+ end
34
+
35
+ it 'does not contain a <div>' do
36
+ result.wont_match '<div'
37
+ end
38
+
39
+ it 'does not contain a <pre>' do
40
+ result.wont_match '<pre'
41
+ end
42
+ end
43
+
44
+ describe 'with view.html.erb' do
45
+ let :result do
46
+ Markdpwn::Code.pygment code_fixture('view.html.erb'),
47
+ :file_name => 'view.html.erb'
48
+ end
49
+
50
+ it 'includes a parsed <h1> tag' do
51
+ result.must_match '<span class="nt">&lt;h1&gt;</span>'
52
+ end
53
+
54
+ it 'includes a parsed :partial symbol' do
55
+ result.must_match '<span class="ss">:partial</span>'
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#pygments_lexer' do
61
+ describe 'with :mime_type' do
62
+ it 'returns rb for text/x-ruby' do
63
+ Markdpwn::Code.pygments_lexer(:mime_type => 'text/x-ruby').
64
+ must_equal 'rb'
65
+ end
66
+
67
+ it 'returns nil for application/random-mime' do
68
+ Markdpwn::Code.pygments_lexer(:mime_type => 'application/random-mime').
69
+ must_equal nil
70
+ end
71
+ end
72
+
73
+ describe 'with :file_name' do
74
+ it 'returns rb for x.rb' do
75
+ Markdpwn::Code.pygments_lexer(:file_name => 'x.rb').
76
+ must_equal 'rb'
77
+ end
78
+
79
+ it 'returns nil for x.random-ext' do
80
+ Markdpwn::Code.pygments_lexer(:file_name => 'x.random-ext').
81
+ must_equal nil
82
+ end
83
+ end
84
+
85
+ describe 'with :language' do
86
+ it 'returns rb for ruby' do
87
+ Markdpwn::Code.pygments_lexer(:language => 'ruby').
88
+ must_equal 'rb'
89
+ end
90
+
91
+ it 'returns nil for random-lang' do
92
+ Markdpwn::Code.pygments_lexer(:language => 'random-lang').
93
+ must_equal nil
94
+ end
95
+ end
96
+
97
+ describe 'with :code' do
98
+ it 'returns html+erb or xml+erb for view.html.erb' do
99
+ Markdpwn::Code.pygments_lexer(:code => code_fixture('view.html.erb')).
100
+ must_match /^(ht|x)ml\+erb$/
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path('../helper', File.dirname(__FILE__))
2
+
3
+ describe Markdpwn::Docs do
4
+ describe "#render return value" do
5
+ [
6
+ '.asciidoc', '.md', '.pod', '.rdoc', '.rst', '.textile', '.wiki'
7
+ ].each do |ext|
8
+ describe "with a #{ext} document" do
9
+ let :result do
10
+ Markdpwn::Docs.gh_markup code_fixture("readme#{ext}"),
11
+ :file_name => "readme#{ext}"
12
+ end
13
+
14
+ it 'includes a heading' do
15
+ result.must_match /<h2[^>]*>.*List.*<\/h2>/m
16
+ end
17
+
18
+ it 'includes a list item' do
19
+ result.must_match /<li>.*Eggs.*<\/li>/m
20
+ end
21
+
22
+ it 'is not wrapped in a <div>' do
23
+ result.wont_match '<pre'
24
+ end
25
+
26
+ it 'does not contain a <pre>' do
27
+ result.wont_match '<pre'
28
+ end
29
+ end
30
+ end
31
+
32
+ describe 'with view.html.erb' do
33
+ let :result do
34
+ Markdpwn::Docs.gh_markup code_fixture('view.html.erb'),
35
+ :file_name => 'view.html.erb'
36
+ end
37
+
38
+ it 'is nil' do
39
+ result.must_equal nil
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path('../helper', File.dirname(__FILE__))
2
+
3
+ describe Markdpwn::Dpwn do
4
+ describe "#render return value" do
5
+ describe "with the readme.md fixture" do
6
+ let :result do
7
+ Markdpwn::Dpwn.render code_fixture("readme.md")
8
+ end
9
+
10
+ it 'includes a heading' do
11
+ result.must_match /<h2[^>]*>.*List.*<\/h2>/m
12
+ end
13
+
14
+ it 'includes a list item' do
15
+ result.must_match /<li>.*Eggs.*<\/li>/m
16
+ end
17
+
18
+ it 'includes a parsed symbol' do
19
+ result.must_match '<span class="ss">:symbol</span>'
20
+ end
21
+
22
+ it 'includes a parsed <h1> tag' do
23
+ result.must_match '<span class="nt">&lt;h1&gt;</span>'
24
+ end
25
+
26
+ it 'includes a parsed :partial symbol' do
27
+ result.must_match '<span class="ss">:partial</span>'
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#accepts?" do
33
+ ['readme.markdown', 'README.md'].each do |file|
34
+ it "is true for #{file}" do
35
+ Markdpwn::Dpwn.accepts?(:file_name => file).must_equal true
36
+ end
37
+ end
38
+
39
+ ['readme.textile', 'readme.txt', 'readme.rb'].each do |file|
40
+ it "is false for #{file}" do
41
+ Markdpwn::Dpwn.accepts?(:file_name => file).must_equal false
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path('./helper', File.dirname(__FILE__))
2
+
3
+ describe Markdpwn do
4
+ describe "#markup" do
5
+ describe "with the readme.md fixture" do
6
+ let :result do
7
+ Markdpwn.markup code_fixture("readme.md"), :file_name => 'readme.md'
8
+ end
9
+
10
+ it 'includes a parsed <h1> tag' do
11
+ result.must_match '<span class="nt">&lt;h1&gt;</span>'
12
+ end
13
+
14
+ it 'includes a parsed :partial symbol' do
15
+ result.must_match '<span class="ss">:partial</span>'
16
+ end
17
+ end
18
+
19
+ describe "with the readme.textile fixture" do
20
+ let :result do
21
+ Markdpwn.markup code_fixture("readme.textile"),
22
+ :file_name => 'readme.textile'
23
+ end
24
+
25
+ it 'includes a heading' do
26
+ result.must_match /<h2[^>]*>.*List.*<\/h2>/m
27
+ end
28
+
29
+ it 'includes a list item' do
30
+ result.must_match /<li>.*Eggs.*<\/li>/m
31
+ end
32
+
33
+ it 'is not wrapped in a <div>' do
34
+ result.wont_match '<pre'
35
+ end
36
+ end
37
+
38
+ describe "with the view.html.erb fixture" do
39
+ let :result do
40
+ Markdpwn.markup code_fixture("view.html.erb"),
41
+ :file_name => 'view.html.erb'
42
+ end
43
+
44
+ it 'is wrapped in a <div> with the markdpwn-parsed-code class' do
45
+ result.must_match /\A<div class="markdpwn-parsed-code">.*<\/div>\Z/m
46
+ end
47
+
48
+ it 'includes a parsed <h1> tag' do
49
+ result.must_match '<span class="nt">&lt;h1&gt;</span>'
50
+ end
51
+
52
+ it 'includes a parsed :partial symbol' do
53
+ result.must_match '<span class="ss">:partial</span>'
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#markdpwn" do
59
+ describe "with the readme.md fixture" do
60
+ let :result do
61
+ Markdpwn.markdpwn code_fixture("readme.md")
62
+ end
63
+
64
+ it 'includes a parsed <h1> tag' do
65
+ result.must_match '<span class="nt">&lt;h1&gt;</span>'
66
+ end
67
+
68
+ it 'includes a parsed :partial symbol' do
69
+ result.must_match '<span class="ss">:partial</span>'
70
+ end
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,232 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdpwn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Victor Costan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pygments.rb
16
+ requirement: &25063540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.4
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *25063540
25
+ - !ruby/object:Gem::Dependency
26
+ name: github-markup
27
+ requirement: &25063000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *25063000
36
+ - !ruby/object:Gem::Dependency
37
+ name: redcarpet
38
+ requirement: &25062340 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 2.1.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *25062340
47
+ - !ruby/object:Gem::Dependency
48
+ name: RedCloth
49
+ requirement: &25061120 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 4.2.9
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *25061120
58
+ - !ruby/object:Gem::Dependency
59
+ name: rdoc
60
+ requirement: &25075760 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '3.12'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *25075760
69
+ - !ruby/object:Gem::Dependency
70
+ name: org-ruby
71
+ requirement: &25074340 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 0.6.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *25074340
80
+ - !ruby/object:Gem::Dependency
81
+ name: creole
82
+ requirement: &25073600 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 0.4.2
88
+ type: :runtime
89
+ prerelease: false
90
+ version_requirements: *25073600
91
+ - !ruby/object:Gem::Dependency
92
+ name: wikicloth
93
+ requirement: &25072760 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 0.7.1
99
+ type: :runtime
100
+ prerelease: false
101
+ version_requirements: *25072760
102
+ - !ruby/object:Gem::Dependency
103
+ name: minitest
104
+ requirement: &25071060 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '2.11'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *25071060
113
+ - !ruby/object:Gem::Dependency
114
+ name: yard
115
+ requirement: &25069480 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0.7'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *25069480
124
+ - !ruby/object:Gem::Dependency
125
+ name: bundler
126
+ requirement: &25068380 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: 1.0.22
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *25068380
135
+ - !ruby/object:Gem::Dependency
136
+ name: jeweler
137
+ requirement: &26467200 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: 1.8.3
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: *26467200
146
+ - !ruby/object:Gem::Dependency
147
+ name: rcov
148
+ requirement: &26466600 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: *26466600
157
+ - !ruby/object:Gem::Dependency
158
+ name: simplecov
159
+ requirement: &26465860 !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ! '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ type: :development
166
+ prerelease: false
167
+ version_requirements: *26465860
168
+ description: HTML-formats text documents such as Markdown, textile, and source code
169
+ email: victor@costan.us
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files:
173
+ - LICENSE.txt
174
+ - README.markdown
175
+ files:
176
+ - .document
177
+ - .project
178
+ - Gemfile
179
+ - Gemfile.lock
180
+ - LICENSE.txt
181
+ - README.markdown
182
+ - Rakefile
183
+ - VERSION
184
+ - lib/markdpwn.rb
185
+ - lib/markdpwn/code.rb
186
+ - lib/markdpwn/docs.rb
187
+ - lib/markdpwn/dpwn.rb
188
+ - lib/markdpwn/glue.rb
189
+ - lib/markdpwn/red_carpet_renderer.rb
190
+ - markdpwn.gemspec
191
+ - test/fixtures/readme.asciidoc
192
+ - test/fixtures/readme.md
193
+ - test/fixtures/readme.pod
194
+ - test/fixtures/readme.rdoc
195
+ - test/fixtures/readme.rst
196
+ - test/fixtures/readme.textile
197
+ - test/fixtures/readme.wiki
198
+ - test/fixtures/view.html.erb
199
+ - test/helper.rb
200
+ - test/markdpwn/code_test.rb
201
+ - test/markdpwn/docs_test.rb
202
+ - test/markdpwn/dpwn_test.rb
203
+ - test/markdpwn_test.rb
204
+ homepage: http://github.com/pwnall/markdpwn
205
+ licenses:
206
+ - MIT
207
+ post_install_message:
208
+ rdoc_options: []
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ! '>='
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ segments:
218
+ - 0
219
+ hash: 3057414624301840921
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ none: false
222
+ requirements:
223
+ - - ! '>='
224
+ - !ruby/object:Gem::Version
225
+ version: '0'
226
+ requirements: []
227
+ rubyforge_project:
228
+ rubygems_version: 1.8.16
229
+ signing_key:
230
+ specification_version: 3
231
+ summary: HTML-formats text documents such as Markdown, textile, and source code
232
+ test_files: []