markdown-highlight-extended-filter 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: e88313f99954a78e53e1f65616998b2e3792e22e
4
+ data.tar.gz: a7415ff36c3382cd06e25a668dd71292c7b7ea17
5
+ SHA512:
6
+ metadata.gz: 537a2d2c1e3138716b9b046e289d005252427179fe0da4177f038f0efa48c59806db871178b14cbc4496dbfade8bd771ccb07289d285f4948152916700a0c195
7
+ data.tar.gz: eaee3434f304cf1325b7c35d3a431d5e9054801f602868a07d98d4a5137b0a3a0392b3f1e064e77096ac2cecac646949e3048628bdc0166e166b0916842db2ef
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in markdown-highlight-extended-filter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Yu-Cheng Chuang
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,88 @@
1
+ # Markdown Highlight Extended Filter for HTML::Pipeline
2
+
3
+ An HTML::Pipeline filter to convert Octopress-flavored syntax highlighting, like this:
4
+
5
+ ``` [language] [title] [url] [link text]
6
+ code snippet
7
+ ```
8
+
9
+ See: http://octopress.org/docs/blogging/code/
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'markdown-highlight-extended-filter'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it without Gemfile (like, Jekyll project):
24
+
25
+ $ gem install markdown-highlight-extended-filter
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ pipeline = HTML::Pipeline.new [
31
+ MarkdownHighlightExtendedFilter,
32
+ HTML::Pipeline::MarkdownFilter
33
+ ]
34
+
35
+ pipeline.call(File.read("example.md"))[:output]
36
+ ```
37
+
38
+ example.md:
39
+
40
+ Here is a sample:
41
+
42
+ ```ruby test.rb
43
+ def abc
44
+ 123
45
+ end
46
+ ```
47
+
48
+ ### Jekyll site usage
49
+
50
+ This filter is for HTML::Pipeline, so you must use HTML::Pipeline to
51
+ generate your content from Markdown. See [gjtorikian/jekyll-html-pipeline](https://github.com/gjtorikian/jekyll-html-pipeline) for more details.
52
+
53
+ Edit `_config.yml` and configure the pieline like this:
54
+
55
+ ```yml
56
+ gems:
57
+ - jekyll-html-pipeline
58
+ - markdown-highlight-extended-filter
59
+
60
+ markdown: HTMLPipeline
61
+
62
+ html_pipeline:
63
+ filters:
64
+ - "MarkdownHighlightExtendedFilter" # Must put before markdownfilter
65
+ - "markdownfilter"
66
+ ```
67
+
68
+ ## Known Issues
69
+
70
+ Unsupported features:
71
+
72
+ * Line Numbers
73
+ * Line Highlights
74
+
75
+ These were defined in [Octopress's document](http://octopress.org/docs/blogging/code/) as additional options. (PR welcome!)
76
+
77
+ ## Special Thanks
78
+
79
+ The code to convert complex syntax highlighting was stolen from [Octopress Project](https://github.com/imathis/octopress/).
80
+ See [imathis/octopress:plugins/backtick_code_block.rb@73e5404](https://github.com/imathis/octopress/blob/73e540409ceb8bc18048b6a96a4b815fc303ea28/plugins/backtick_code_block.rb) for the original source code. Also thanks contributers: @imathis, @fhemberger and @liangsun. I hope you don't mind :D
81
+
82
+ ## Contributing
83
+
84
+ 1. Fork it ( https://github.com/chitsaou/markdown-highlight-extended-filter/fork )
85
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
86
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
87
+ 4. Push to the branch (`git push origin my-new-feature`)
88
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,53 @@
1
+ require "html/pipeline"
2
+ require "pygments.rb"
3
+
4
+ # Stolen from https://github.com/imathis/octopress/blob/master/plugins/backtick_code_block.rb
5
+ # (MIT License)
6
+ class MarkdownHighlightExtendedFilter < HTML::Pipeline::TextFilter
7
+ AllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
8
+ LangCaption = /([^\s]+)\s*(.+)?/i
9
+
10
+ PIPELINE = HTML::Pipeline.new [
11
+ HTML::Pipeline::SyntaxHighlightFilter
12
+ ]
13
+
14
+ def call
15
+ format_syntax(@text)
16
+ end
17
+
18
+ def format_syntax(text)
19
+ text.gsub(/^`{3} *([^\n]+)?\n(.+?)\n`{3}/m) do
20
+ options = $1 || ''
21
+ str = $2
22
+
23
+ if options =~ AllOptions
24
+ lang = $1
25
+ caption = "<figcaption><span>#{$2}</span><a href='#{$3}'>#{$4 || 'link'}</a></figcaption>"
26
+ elsif options =~ LangCaption
27
+ lang = $1
28
+ caption = "<figcaption><span>#{$2}</span></figcaption>"
29
+ end
30
+
31
+ if str.match(/\A( {4}|\t)/)
32
+ str = str.gsub(/^( {4}|\t)/, '')
33
+ end
34
+ if lang.nil? || lang == 'plain'
35
+ code = highlight_code(str.gsub('<','&lt;').gsub('>','&gt;'), "plain")
36
+ "<figure class='code'>#{caption}#{code}</figure>"
37
+ else
38
+ if lang.include? "-raw"
39
+ raw = "``` #{options.sub('-raw', '')}\n"
40
+ raw += str
41
+ raw += "\n```\n"
42
+ else
43
+ code = highlight_code(str, lang)
44
+ "<figure class='code'>#{caption}#{code}</figure>"
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ def highlight_code(code, lang)
51
+ PIPELINE.call("<pre lang='#{lang}'>#{code}</pre>")[:output].to_s
52
+ end
53
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "markdown-highlight-extended-filter"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Yu-Cheng Chuang"]
9
+ spec.email = ["ducksteven@gmail.com"]
10
+ spec.summary = %q{HTML::Pipeline filter for Octopress-flavored syntax highlighting}
11
+ spec.description = %q{HTML::Pipeline filter for Octopress-flavored syntax highlighting}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "html-pipeline"
21
+ spec.add_dependency "pygments.rb"
22
+ spec.add_dependency "github-linguist"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.1.0"
27
+ end
@@ -0,0 +1,110 @@
1
+ require 'markdown-highlight-extended-filter'
2
+
3
+ RSpec.describe "MarkdownHighlightExtendedFilter" do
4
+ let(:pipeline) {
5
+ HTML::Pipeline.new [MarkdownHighlightExtendedFilter]
6
+ }
7
+
8
+ let(:rendered) {
9
+ pipeline.call(text)[:output]
10
+ }
11
+
12
+ describe "no args" do
13
+ let(:text) { <<-TEXT
14
+ ```
15
+ def abc
16
+ 123
17
+ end
18
+ ```
19
+ TEXT
20
+ }
21
+
22
+ it "renders correctly" do
23
+ expect(rendered).to eq <<-HTML
24
+ <figure class='code'><pre lang="plain">def abc
25
+ 123
26
+ end</pre></figure>
27
+ HTML
28
+ end
29
+ end
30
+
31
+ describe "lang arg only" do
32
+ let(:text) { <<-TEXT
33
+ ```ruby
34
+ def abc
35
+ 123
36
+ end
37
+ ```
38
+ TEXT
39
+ }
40
+
41
+ it "renders correctly" do
42
+ expect(rendered).to eq <<-HTML
43
+ <figure class='code'><figcaption><span></span></figcaption><div class="highlight highlight-ruby"><pre><span class="k">def</span> <span class="nf">abc</span>
44
+ <span class="mi">123</span>
45
+ <span class="k">end</span>
46
+ </pre></div></figure>
47
+ HTML
48
+ end
49
+ end
50
+
51
+ describe "lang and title args" do
52
+ let(:text) { <<-TEXT
53
+ ```ruby Hello World
54
+ def abc
55
+ 123
56
+ end
57
+ ```
58
+ TEXT
59
+ }
60
+
61
+ it "renders correctly" do
62
+ expect(rendered).to eq <<-HTML
63
+ <figure class='code'><figcaption><span>Hello World</span></figcaption><div class="highlight highlight-ruby"><pre><span class="k">def</span> <span class="nf">abc</span>
64
+ <span class="mi">123</span>
65
+ <span class="k">end</span>
66
+ </pre></div></figure>
67
+ HTML
68
+ end
69
+ end
70
+
71
+ describe "lang, title, url args" do
72
+ let(:text) { <<-TEXT
73
+ ```ruby Hello World http://www.example.com
74
+ def abc
75
+ 123
76
+ end
77
+ ```
78
+ TEXT
79
+ }
80
+
81
+ it "renders correctly" do
82
+ expect(rendered).to eq <<-HTML
83
+ <figure class='code'><figcaption><span>Hello World</span><a href='http://www.example.com'>link</a></figcaption><div class="highlight highlight-ruby"><pre><span class="k">def</span> <span class="nf">abc</span>
84
+ <span class="mi">123</span>
85
+ <span class="k">end</span>
86
+ </pre></div></figure>
87
+ HTML
88
+ end
89
+ end
90
+
91
+ describe "lang, title, url, link-title args" do
92
+ let(:text) { <<-TEXT
93
+ ```ruby Hello World http://www.example.com Example
94
+ def abc
95
+ 123
96
+ end
97
+ ```
98
+ TEXT
99
+ }
100
+
101
+ it "renders correctly" do
102
+ expect(rendered).to eq <<-HTML
103
+ <figure class='code'><figcaption><span>Hello World</span><a href='http://www.example.com'>Example</a></figcaption><div class="highlight highlight-ruby"><pre><span class="k">def</span> <span class="nf">abc</span>
104
+ <span class="mi">123</span>
105
+ <span class="k">end</span>
106
+ </pre></div></figure>
107
+ HTML
108
+ end
109
+ end
110
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown-highlight-extended-filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yu-Cheng Chuang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-14 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pygments.rb
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: github-linguist
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
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
97
+ description: HTML::Pipeline filter for Octopress-flavored syntax highlighting
98
+ email:
99
+ - ducksteven@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/markdown-highlight-extended-filter.rb
110
+ - markdown-highlight-extended-filter.gemspec
111
+ - spec/markdown-highlight-extended-filter_spec.rb
112
+ homepage: ''
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.2.2
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: HTML::Pipeline filter for Octopress-flavored syntax highlighting
136
+ test_files:
137
+ - spec/markdown-highlight-extended-filter_spec.rb