string_markdown 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +48 -0
- data/Rakefile +2 -0
- data/lib/string_markdown/extention/string.rb +3 -0
- data/lib/string_markdown/version.rb +3 -0
- data/lib/string_markdown.rb +24 -0
- data/spec/extention/string_spec.rb +28 -0
- data/spec/spec_helper.rb +3 -0
- data/string_markdown.gemspec +21 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 koshikawa
|
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,48 @@
|
|
1
|
+
# StringMarkdown
|
2
|
+
|
3
|
+
Add Strning#to_md
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'string_markdown'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install string_markdown
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```
|
22
|
+
text = <<MARKDOWN
|
23
|
+
# level1 header
|
24
|
+
## level2 header
|
25
|
+
```
|
26
|
+
block code
|
27
|
+
```
|
28
|
+
|
29
|
+
* list
|
30
|
+
* list
|
31
|
+
|
32
|
+
http://example.com
|
33
|
+
MARKDOWN
|
34
|
+
|
35
|
+
text.to_md
|
36
|
+
```
|
37
|
+
|
38
|
+
```
|
39
|
+
<h1>level1 header</h1>\n\n<h2>level2 header</h2>\n<div class=\"highlight\"><pre><span class=\"n\">block</span> <span class=\"n\">code</span>\n</pre>\n</div>\n\n<ul>\n<li>list</li>\n<li>list</li>\n</ul>\n\n<p><a href=\"http://example.com\">http://example.com</a></p>\n
|
40
|
+
```
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
require 'pygments'
|
3
|
+
require 'string_markdown/version'
|
4
|
+
require 'string_markdown/extention/string'
|
5
|
+
|
6
|
+
module StringMarkdown
|
7
|
+
def to_md
|
8
|
+
html_render = StringMarkdown::PygmentizeHTML.new hard_wrap: true, filter_html: true
|
9
|
+
markdown = Redcarpet::Markdown.new html_render, autolink: true, fenced_code_blocks: true, space_after_headers: true
|
10
|
+
begin
|
11
|
+
text = self
|
12
|
+
return markdown.render text
|
13
|
+
rescue => e
|
14
|
+
return e.message
|
15
|
+
text
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class StringMarkdown::PygmentizeHTML < Redcarpet::Render::HTML
|
21
|
+
def block_code code, language
|
22
|
+
::Pygments.highlight code, lexer: language, options: {encoding: 'utf-8'}
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require File.expand_path(File.join('../', 'spec_helper'), File.dirname(__FILE__))
|
3
|
+
|
4
|
+
describe StringMarkdown do
|
5
|
+
let(:text) {
|
6
|
+
<<MARKDOWN
|
7
|
+
# level1 header
|
8
|
+
## level2 header
|
9
|
+
```
|
10
|
+
block code
|
11
|
+
```
|
12
|
+
|
13
|
+
* list
|
14
|
+
* list
|
15
|
+
|
16
|
+
http://example.com
|
17
|
+
MARKDOWN
|
18
|
+
}
|
19
|
+
describe 'to_markdown' do
|
20
|
+
before do
|
21
|
+
end
|
22
|
+
it { text.to_md.should =~ /<h1>level1 header<\/h1>/ }
|
23
|
+
it { text.to_md.should =~ /<h2>level2 header<\/h2>/ }
|
24
|
+
it { text.to_md.should =~ /<div class="highlight"><pre><span class="n">block<\/span> <span class="n">code<\/span>/ }
|
25
|
+
it { text.to_md.should =~ /<li>list<\/li>/ }
|
26
|
+
it { text.to_md.should =~ /<a href="http:\/\/example.com">http:\/\/example.com<\/a>/ }
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/string_markdown/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["ppworks"]
|
6
|
+
gem.email = ["koshikawa@ppworks.jp"]
|
7
|
+
gem.description = %q{Add String#to_md support}
|
8
|
+
gem.summary = %q{Add String#to_md}
|
9
|
+
gem.homepage = "https://github.com/ppworks/string-markdown"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "string_markdown"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = StringMarkdown::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'redcarpet'
|
19
|
+
gem.add_dependency 'pygments.rb'
|
20
|
+
gem.add_dependency 'rubypython', '0.5.1'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: string_markdown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ppworks
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redcarpet
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: pygments.rb
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rubypython
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.5.1
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.5.1
|
62
|
+
description: Add String#to_md support
|
63
|
+
email:
|
64
|
+
- koshikawa@ppworks.jp
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/string_markdown.rb
|
75
|
+
- lib/string_markdown/extention/string.rb
|
76
|
+
- lib/string_markdown/version.rb
|
77
|
+
- spec/extention/string_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
- string_markdown.gemspec
|
80
|
+
homepage: https://github.com/ppworks/string-markdown
|
81
|
+
licenses: []
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.24
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Add String#to_md
|
104
|
+
test_files:
|
105
|
+
- spec/extention/string_spec.rb
|
106
|
+
- spec/spec_helper.rb
|