html-pipeline-rouge_filter 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +14 -0
- data/LICENSE +22 -0
- data/README.md +60 -0
- data/Rakefile +10 -0
- data/html-pipeline-rouge_filter.gemspec +23 -0
- data/lib/html/pipeline/rouge_filter.rb +53 -0
- data/lib/html/pipeline/rouge_filter/version.rb +7 -0
- data/test/rouge_filter_test.rb +30 -0
- data/test/test_helper.rb +8 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6fbe6d6bed5f26e774cbec97e4c4f3daf0f8fb78
|
4
|
+
data.tar.gz: 4ef0190ac74ee92841a5ff7a07ec37aac417e6ba
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ed19d6d77dbffa08f7a4ce7a3d25a17e9def14172379b9c6bba8fd25c0f681fc1bf866195de8371cc358ff882e73d5aa77eaebdb29029a132d5403f409268b8
|
7
|
+
data.tar.gz: 0107b840f5c002b3e802aee73a02e6eb8c35cab95868f9f7f7e623291ab306aaced04f4f7e416de3b918af0afb7c2f0eeee07ee63e7aa22593bb9a985e4d9b95
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Juanito Fatas
|
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,60 @@
|
|
1
|
+
# HTML::Pipeline::RougeFilter
|
2
|
+
|
3
|
+
[Rouge](https://github.com/jneen/rouge) integration for [HTML::Pipeline](https://github.com/jch/html-pipeline).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'html-pipeline-rouge_filter'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install html-pipeline-rouge_filter
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
pipeline = HTML::Pipeline.new [
|
25
|
+
HTML::Pipeline::MarkdownFilter,
|
26
|
+
HTML::Pipeline::RougeFilter
|
27
|
+
]
|
28
|
+
|
29
|
+
result = pipeline.call <<-CODE
|
30
|
+
```ruby
|
31
|
+
def foo
|
32
|
+
puts "foo"
|
33
|
+
end
|
34
|
+
```
|
35
|
+
CODE
|
36
|
+
|
37
|
+
result[:output].to_s
|
38
|
+
```
|
39
|
+
|
40
|
+
Prints
|
41
|
+
|
42
|
+
```html
|
43
|
+
<pre class="highlight highlight-ruby">
|
44
|
+
<code>
|
45
|
+
<span class="k">def</span>
|
46
|
+
<span class="nf">foo</span>
|
47
|
+
<span class="nb">puts</span>
|
48
|
+
<span class="s2">"foo"</span>
|
49
|
+
<span class="k">end</span>
|
50
|
+
</code>
|
51
|
+
</pre>
|
52
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it ( https://github.com/[my-github-username]/html-pipeline-rouge_filter/fork )
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'html/pipeline/rouge_filter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "html-pipeline-rouge_filter"
|
8
|
+
spec.version = HTML_Pipeline::RougeFilter::VERSION
|
9
|
+
spec.authors = ["Juanito Fatas"]
|
10
|
+
spec.email = ["katehuang0320@gmail.com"]
|
11
|
+
spec.summary = %q{Rouge integration with html-pipeline.}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = "https://github.com/juanitofatas/html-pipeline-rouge_filter"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "html-pipeline", "~> 1.11"
|
21
|
+
spec.add_dependency "rouge", "~> 1.8"
|
22
|
+
spec.add_dependency "activesupport"
|
23
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "html/pipeline/rouge_filter/version"
|
2
|
+
require "html/pipeline/filter"
|
3
|
+
|
4
|
+
require "rouge"
|
5
|
+
|
6
|
+
require "active_support/core_ext/string/inflections"
|
7
|
+
|
8
|
+
module HTML
|
9
|
+
class Pipeline
|
10
|
+
class RougeFilter < Filter
|
11
|
+
def call
|
12
|
+
doc.search("pre").each do |node|
|
13
|
+
default = must_str(context[:highlight])
|
14
|
+
next unless lang = node["lang"] || default
|
15
|
+
next unless lexer = lexer_for(lang)
|
16
|
+
text = node.inner_text
|
17
|
+
html = highlight_with(lexer, text)
|
18
|
+
next if html.nil?
|
19
|
+
|
20
|
+
if (node = node.replace(html).first)
|
21
|
+
klass = node["class"]
|
22
|
+
klass = [klass, "#{default_css_class}-#{lang}"].compact.join(" ")
|
23
|
+
node["class"] = klass
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
doc
|
28
|
+
end
|
29
|
+
|
30
|
+
def must_str(text)
|
31
|
+
text && text.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def highlight_with(lexer, text)
|
35
|
+
formatter.format(lexer.lex(text))
|
36
|
+
end
|
37
|
+
|
38
|
+
def default_css_class
|
39
|
+
must_str(context[:css_class]) || "highlight"
|
40
|
+
end
|
41
|
+
|
42
|
+
def formatter(css_class: default_css_class)
|
43
|
+
Rouge::Formatters::HTML.new(css_class: css_class)
|
44
|
+
end
|
45
|
+
|
46
|
+
def lexer_for(lang)
|
47
|
+
lexer = "Rouge::Lexers::#{lang.camelize}".constantize
|
48
|
+
lexer.new(parent: lang)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "html/pipeline/rouge_filter"
|
3
|
+
|
4
|
+
class HTML::Pipeline::RougeFilterTest < Minitest::Test
|
5
|
+
RougeFilter = HTML::Pipeline::RougeFilter
|
6
|
+
|
7
|
+
def setup
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_highlight_default
|
11
|
+
filter = RougeFilter.new \
|
12
|
+
"<pre>hello</pre>", highlight: "coffeescript"
|
13
|
+
|
14
|
+
doc = filter.call
|
15
|
+
assert !doc.css(".highlight-coffeescript").empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_highlight_default_will_not_override
|
19
|
+
filter = RougeFilter.new \
|
20
|
+
"<pre lang='ruby'>hello</pre>", highlight: "coffeescript"
|
21
|
+
|
22
|
+
doc = filter.call
|
23
|
+
assert doc.css(".highlight-coffeescript").empty?
|
24
|
+
assert !doc.css(".highlight-ruby").empty?
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_version
|
28
|
+
assert_equal HTML_Pipeline::RougeFilter::VERSION, "0.0.1"
|
29
|
+
end
|
30
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html-pipeline-rouge_filter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Juanito Fatas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: html-pipeline
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rouge
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Rouge integration with html-pipeline.
|
56
|
+
email:
|
57
|
+
- katehuang0320@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- CHANGELOG.md
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- html-pipeline-rouge_filter.gemspec
|
69
|
+
- lib/html/pipeline/rouge_filter.rb
|
70
|
+
- lib/html/pipeline/rouge_filter/version.rb
|
71
|
+
- test/rouge_filter_test.rb
|
72
|
+
- test/test_helper.rb
|
73
|
+
homepage: https://github.com/juanitofatas/html-pipeline-rouge_filter
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Rouge integration with html-pipeline.
|
97
|
+
test_files: []
|
98
|
+
has_rdoc:
|