html-pipeline-highlight 0.1.0 → 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
  SHA256:
3
- metadata.gz: 1686b4e2ea65ee6d254fe5fea91c9db9e5026db9ee23e07b078187cf962fb56c
4
- data.tar.gz: eea09fa61e8f1d2afac2285b97148c630b430e58be1cc9756d82436f1afa584f
3
+ metadata.gz: 4424f7176e0bfbba8176d9c4ab3cbe79969c63fc5d7471a9e689268450a78e3b
4
+ data.tar.gz: 1592c479e27a1e3b0b7ecafeeda8f752fb4add2307225d35d5d5eaadfe52970e
5
5
  SHA512:
6
- metadata.gz: c17dddb20d6138a81caaae5a8094a67c633e30b0f14dddd9cb18aa92480d014629ba45ecf5a934c887ba191637543b87cd1bc8d97a9b04f608e694e922e6ffa7
7
- data.tar.gz: ed2d87488a90db0a52112d3bbfb2bf3b0b097d2e19cd84462b9c53fe3f59b8f952f8a6da2d4a53d2069e89b03d05526894d2774024a49ddd8c8863d50dd7e53d
6
+ metadata.gz: 22b14a02438ef7d7352c495ca3ec7102a85578d7211920d44f4b8db331a0648b75dd11dc5b7e0f3efd08dcab25a56cdeb47e3b7d531fe19abdc14281aa0f226c
7
+ data.tar.gz: 6d8f77118c4f99eca2b12c318d3f0fd1f09e8b8a315981206390a382b9ceebb0ac340b4bdc3bb88653a49d946b53e3b9d1a0c2143f11a553eb9f05116e451d58
@@ -0,0 +1,5 @@
1
+ {
2
+ "cSpell.words": [
3
+ "Matz"
4
+ ]
5
+ }
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # HTML::Pipeline::Highlight
1
+ # HTMLPipeline::Highlight
2
2
 
3
- Highlight filter for [html\-pipeline](https://github.com/jch/html-pipeline).
3
+ Highlight NodeFilter for [html\-pipeline](https://github.com/gjtorikian/html-pipeline).
4
4
 
5
5
  ## Installation
6
6
 
@@ -21,8 +21,8 @@ Or install it yourself as:
21
21
  ## Usage
22
22
 
23
23
  ```ruby
24
- filter = HTML::Pipeline::HighlightFilter.new('Wondering why Ruby is so popular?', highlight_pattern: /ruby/i)
25
- filter.call.to_s # => 'Wondering why <span class="highlight">Ruby</span> is so popular?'
24
+ result = HTMLPipeline::HighlightFilter.call('<div>Wondering why Ruby is so popular?</div>', context: { highlight_pattern: /ruby/i })
25
+ result.to_s # => '<div>Wondering why <span class="highlight">Ruby</span> is so popular?</div>'
26
26
  ```
27
27
 
28
28
  ## Development
@@ -42,4 +42,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
42
42
 
43
43
  ## Code of Conduct
44
44
 
45
- Everyone interacting in the Html::Pipeline::Highlight project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/aki77/html-pipeline-highlight/blob/master/CODE_OF_CONDUCT.md).
45
+ Everyone interacting in the HTMLPipeline::Highlight project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/aki77/html-pipeline-highlight/blob/master/CODE_OF_CONDUCT.md).
@@ -2,7 +2,7 @@ require_relative 'lib/html/pipeline/highlight/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "html-pipeline-highlight"
5
- spec.version = HTML::Pipeline::Highlight::VERSION
5
+ spec.version = HTMLPipeline::Highlight::VERSION
6
6
  spec.authors = ["aki77"]
7
7
  spec.email = ["aki77@users.noreply.github.com"]
8
8
 
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
- spec.add_dependency "html-pipeline"
27
+ spec.add_dependency "html-pipeline", "~> 3.0"
28
28
  end
@@ -1,39 +1,40 @@
1
- require 'html/pipeline'
1
+ require 'html_pipeline'
2
2
 
3
- module HTML
4
- class Pipeline
5
- class HighlightFilter < Filter
6
- IGNORE_PARENTS = %w[pre code a style script].to_set
7
- DEFAULT_CLASS_NAME = 'highlight'
3
+ class HTMLPipeline
4
+ class HighlightFilter < NodeFilter
5
+ DEFAULT_IGNORED_ANCESTOR_TAGS = %w[pre code a style script].freeze
6
+ DEFAULT_CLASS_NAME = 'highlight'
8
7
 
9
- def call
10
- doc.xpath('.//text()').each do |node|
11
- next if has_ancestor?(node, IGNORE_PARENTS)
12
-
13
- content = node.to_html
14
- html = apply_filter(content)
15
- next if html == content
8
+ def selector
9
+ Selma::Selector.new(match_text_within: "*", ignore_text_within: DEFAULT_IGNORED_ANCESTOR_TAGS)
10
+ end
16
11
 
17
- node.replace(html)
18
- end
19
- doc
20
- end
12
+ def handle_text_chunk(text)
13
+ text.replace(apply_filter(text.to_s), as: :html)
14
+ end
21
15
 
22
- def apply_filter(content)
23
- content.gsub(@context[:highlight_pattern]) do |text|
16
+ def apply_filter(content)
17
+ content.gsub(context[:highlight_pattern]) do |text|
18
+ if converter
19
+ converter.call(Regexp.last_match)
20
+ else
24
21
  %(<span class="#{class_name}">#{ERB::Util.html_escape(text)}</span>)
25
22
  end
26
23
  end
24
+ end
27
25
 
28
- def validate
29
- needs(:highlight_pattern)
30
- end
26
+ def validate
27
+ needs(:highlight_pattern)
28
+ end
31
29
 
32
- private
30
+ private
33
31
 
34
- def class_name
35
- @context[:highlight_class_name] || DEFAULT_CLASS_NAME
36
- end
32
+ def class_name
33
+ context.fetch(:highlight_class_name, DEFAULT_CLASS_NAME)
34
+ end
35
+
36
+ def converter
37
+ context[:highlight_converter]
37
38
  end
38
39
  end
39
40
  end
@@ -1,7 +1,5 @@
1
- module HTML
2
- class Pipeline
3
- module Highlight
4
- VERSION = "0.1.0"
5
- end
1
+ class HTMLPipeline
2
+ module Highlight
3
+ VERSION = '1.0.0'
6
4
  end
7
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-pipeline-highlight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aki77
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2024-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-pipeline
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3.0'
27
27
  description: Highlight filter for html-pipeline.
28
28
  email:
29
29
  - aki77@users.noreply.github.com
@@ -34,6 +34,7 @@ files:
34
34
  - ".gitignore"
35
35
  - ".rspec"
36
36
  - ".travis.yml"
37
+ - ".vscode/settings.json"
37
38
  - CODE_OF_CONDUCT.md
38
39
  - Gemfile
39
40
  - LICENSE.txt
@@ -51,7 +52,7 @@ licenses:
51
52
  metadata:
52
53
  homepage_uri: https://github.com/aki77/html-pipeline-highlight
53
54
  source_code_uri: https://github.com/aki77/html-pipeline-highlight
54
- post_install_message:
55
+ post_install_message:
55
56
  rdoc_options: []
56
57
  require_paths:
57
58
  - lib
@@ -66,8 +67,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
67
  - !ruby/object:Gem::Version
67
68
  version: '0'
68
69
  requirements: []
69
- rubygems_version: 3.1.2
70
- signing_key:
70
+ rubygems_version: 3.4.10
71
+ signing_key:
71
72
  specification_version: 4
72
73
  summary: Highlight filter for html-pipeline.
73
74
  test_files: []