md2ansi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 63d66e3b57190f33d29f08c1776ace04505a32c1
4
+ data.tar.gz: 3c9de92930fd4e1f9feec44820110aedcc65f0a6
5
+ SHA512:
6
+ metadata.gz: 5e3f997b074b61858cc0a4dea5967bde8559fc7042668cbde1361f5c3e1801761f8353a58bec91a5064162defe2b5fb28b7f59dc852e0056566fc9c93f2f4b09
7
+ data.tar.gz: 53c8b4d380ef596b29d9a4a2200abf1650baa52909d111474f50ff6bd91c97ec38c05588829800fb9b34233dcca6d21b10e2e268d1cc34096080f926a1408eb3
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea/workspace.xml
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jianwei Han
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Md2ansi
2
+
3
+ Md2ansi renders md files to ansi.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'md2ansi'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install md2ansi
18
+
19
+ ## Usage
20
+
21
+ ``` bash
22
+ md2ansi foo.md
23
+ ```
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/md2ansi ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'md2ansi'
6
+ require 'optparse'
7
+
8
+ begin
9
+ options = {}
10
+
11
+ opts = OptionParser.new do |opts|
12
+ opts.banner = "Usage md2ansi [FILE.md]"
13
+ opts.separator ""
14
+ opts.separator "Specific options."
15
+
16
+ opts.on('-h', '--help', 'Display help message') do
17
+ puts opts
18
+ exit
19
+ end
20
+ end
21
+
22
+ puts Md2Ansi::CLI.new.render(ARGF.read)
23
+
24
+ end
@@ -0,0 +1,17 @@
1
+ require 'redcarpet'
2
+
3
+ module Md2Ansi
4
+ class CLI
5
+ def initialize
6
+ @markdown = Redcarpet::Markdown.new(Ansi, :fenced_code_blocks => true)
7
+ end
8
+
9
+ def render(content)
10
+ if content =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
11
+ content = $'
12
+ end
13
+
14
+ @markdown.render(content)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,79 @@
1
+ require 'redcarpet'
2
+ require 'ansi'
3
+ require 'pygments'
4
+
5
+ module Md2Ansi
6
+ class Ansi < Redcarpet::Render::Base
7
+ def normal_text(text)
8
+ text.strip
9
+ end
10
+
11
+ def block_code(code, language)
12
+ Pygments.highlight(code, :lexer => language, :formatter => 'terminal') + "\n\n"
13
+ end
14
+
15
+ def codespan(code)
16
+ Pygments.highlight(code, :formatter => 'terminal')
17
+ end
18
+
19
+ def header(title, level)
20
+
21
+ case level
22
+ when 1
23
+ ansi(title, :red)
24
+ when 2
25
+ ansi(title, :black, :on_red)
26
+ when 3
27
+ ansi(title, :cyan)
28
+ end + "\n\n"
29
+ end
30
+
31
+ def double_emphasis(text)
32
+ " #{ansi(text, :yellow)} "
33
+ end
34
+
35
+ def emphasis(text)
36
+ " #{ansi(text, :white, :on_black)} "
37
+ end
38
+
39
+ def linebreak
40
+ ""
41
+ end
42
+
43
+ def autolink(link, link_type)
44
+ link
45
+ end
46
+
47
+ def link(link, title, content)
48
+ " #{content}(#{ansi(link, :underline)}) "
49
+ end
50
+
51
+ def image(link, title, alt_text)
52
+ " #{content}(#{ansi(link, :underline)}) "
53
+ end
54
+
55
+ def paragraph(text)
56
+ "#{text}\n\n"
57
+ end
58
+
59
+ def list(content, list_type)
60
+ case list_type
61
+ when :ordered
62
+ @order = 0
63
+ "#{content}\n"
64
+ when :unordered
65
+ "#{content}\n"
66
+ end
67
+ end
68
+
69
+ def list_item(content, list_type)
70
+ case list_type
71
+ when :ordered
72
+ @order =(@order or 0) + 1
73
+ "#{@order}. #{content.strip}\n"
74
+ when :unordered
75
+ "+ #{content.strip}\n"
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module Md2Ansi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/md2ansi.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'md2ansi/version'
2
+ require 'md2ansi/render'
3
+ require 'md2ansi/cli'
data/md2ansi.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'md2ansi/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "md2ansi"
8
+ gem.version = Md2Ansi::VERSION
9
+ gem.authors = ["Jianwei Han"]
10
+ gem.email = ["hanjianwei@gmail.com"]
11
+ gem.description = %q{Converts markdown to ansi.}
12
+ gem.summary = %q{markdown to ansi. }
13
+ gem.homepage = "https://github.com/hanjianwei/md2ansi"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency('redcarpet', "~> 2.2")
21
+ gem.add_runtime_dependency('ansi', "~> 1.4")
22
+ gem.add_runtime_dependency('pygments.rb', "~> 0.4")
23
+
24
+ gem.add_development_dependency "bundler", ">= 1.3"
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: md2ansi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jianwei Han
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ansi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pygments.rb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ description: Converts markdown to ansi.
70
+ email:
71
+ - hanjianwei@gmail.com
72
+ executables:
73
+ - md2ansi
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/md2ansi
83
+ - lib/md2ansi.rb
84
+ - lib/md2ansi/cli.rb
85
+ - lib/md2ansi/render.rb
86
+ - lib/md2ansi/version.rb
87
+ - md2ansi.gemspec
88
+ homepage: https://github.com/hanjianwei/md2ansi
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.0.0
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: markdown to ansi.
111
+ test_files: []