markdown-highlight-extended-filter 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e88313f99954a78e53e1f65616998b2e3792e22e
4
- data.tar.gz: a7415ff36c3382cd06e25a668dd71292c7b7ea17
3
+ metadata.gz: 7dfc3f9e711fe9a402d79542c5d48653ea8fdc66
4
+ data.tar.gz: 2939f157d44ef9b3d8f14adf5f67f05c41d778c2
5
5
  SHA512:
6
- metadata.gz: 537a2d2c1e3138716b9b046e289d005252427179fe0da4177f038f0efa48c59806db871178b14cbc4496dbfade8bd771ccb07289d285f4948152916700a0c195
7
- data.tar.gz: eaee3434f304cf1325b7c35d3a431d5e9054801f602868a07d98d4a5137b0a3a0392b3f1e064e77096ac2cecac646949e3048628bdc0166e166b0916842db2ef
6
+ metadata.gz: 1878404d04e588fe1e8dcf451aa5965cf804d4ee7748dd06e8c207f0501c72c2595ed6c62d06502d723fc4b42ed6820ae2ad17736ad86b257df129618c8c0916
7
+ data.tar.gz: 5c40dc8591e79150656c6c9745b72ff03e26521c6d48ada68e79bd44eb332cc3c28ae503f7cdcab8c1506741185c951fc502d3f1c11753f338e34177f4b1ce99
@@ -1,5 +1,6 @@
1
1
  require "html/pipeline"
2
2
  require "pygments.rb"
3
+ require "linguist"
3
4
 
4
5
  # Stolen from https://github.com/imathis/octopress/blob/master/plugins/backtick_code_block.rb
5
6
  # (MIT License)
@@ -7,10 +8,6 @@ class MarkdownHighlightExtendedFilter < HTML::Pipeline::TextFilter
7
8
  AllOptions = /([^\s]+)\s+(.+?)\s+(https?:\/\/\S+|\/\S+)\s*(.+)?/i
8
9
  LangCaption = /([^\s]+)\s*(.+)?/i
9
10
 
10
- PIPELINE = HTML::Pipeline.new [
11
- HTML::Pipeline::SyntaxHighlightFilter
12
- ]
13
-
14
11
  def call
15
12
  format_syntax(@text)
16
13
  end
@@ -48,6 +45,15 @@ class MarkdownHighlightExtendedFilter < HTML::Pipeline::TextFilter
48
45
  end
49
46
 
50
47
  def highlight_code(code, lang)
51
- PIPELINE.call("<pre lang='#{lang}'>#{code}</pre>")[:output].to_s
48
+ if lexer = lexer_for(lang)
49
+ lexer.highlight(code, :options => { :cssclass => "highlight highlight-#{lang}" })
50
+ else
51
+ "<pre>#{code}</pre>"
52
+ end
53
+ end
54
+
55
+ # https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/syntax_highlight_filter.rb#L38
56
+ def lexer_for(lang)
57
+ (Linguist::Language[lang] && Linguist::Language[lang].lexer) || Pygments::Lexer[lang]
52
58
  end
53
59
  end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "markdown-highlight-extended-filter"
7
- spec.version = "0.0.1"
7
+ spec.version = "1.0.0"
8
8
  spec.authors = ["Yu-Cheng Chuang"]
9
9
  spec.email = ["ducksteven@gmail.com"]
10
10
  spec.summary = %q{HTML::Pipeline filter for Octopress-flavored syntax highlighting}
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "rspec", "~> 3.1.0"
27
+ spec.add_development_dependency "pry-byebug"
28
+
27
29
  end
@@ -1,4 +1,5 @@
1
1
  require 'markdown-highlight-extended-filter'
2
+ require 'pry-byebug'
2
3
 
3
4
  RSpec.describe "MarkdownHighlightExtendedFilter" do
4
5
  let(:pipeline) {
@@ -21,7 +22,7 @@ TEXT
21
22
 
22
23
  it "renders correctly" do
23
24
  expect(rendered).to eq <<-HTML
24
- <figure class='code'><pre lang="plain">def abc
25
+ <figure class='code'><pre>def abc
25
26
  123
26
27
  end</pre></figure>
27
28
  HTML
@@ -104,6 +105,22 @@ TEXT
104
105
  <span class="mi">123</span>
105
106
  <span class="k">end</span>
106
107
  </pre></div></figure>
108
+ HTML
109
+ end
110
+ end
111
+
112
+ describe "no sanitization" do
113
+ let(:text) { <<-TEXT
114
+ ```html
115
+ <input name="test" value="hello" />
116
+ ```
117
+ TEXT
118
+ }
119
+
120
+ it "renders correctly" do
121
+ expect(rendered).to eq <<-HTML
122
+ <figure class='code'><figcaption><span></span></figcaption><div class="highlight highlight-html"><pre><span class="nt">&lt;input</span> <span class="na">name=</span><span class="s">&quot;test&quot;</span> <span class="na">value=</span><span class="s">&quot;hello&quot;</span> <span class="nt">/&gt;</span>
123
+ </pre></div></figure>
107
124
  HTML
108
125
  end
109
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown-highlight-extended-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yu-Cheng Chuang
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 3.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: HTML::Pipeline filter for Octopress-flavored syntax highlighting
98
112
  email:
99
113
  - ducksteven@gmail.com