html-pipeline-highlight 0.2.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: 27b92c584e4dd32fb66fa437b11af62d2de5ec94190002de4fe5270fd0e9a200
4
- data.tar.gz: 0eadbd7776460f32a28bbaf55437ed8bce142b539e6ed1fdc7106b43a97c4d97
3
+ metadata.gz: 4424f7176e0bfbba8176d9c4ab3cbe79969c63fc5d7471a9e689268450a78e3b
4
+ data.tar.gz: 1592c479e27a1e3b0b7ecafeeda8f752fb4add2307225d35d5d5eaadfe52970e
5
5
  SHA512:
6
- metadata.gz: bc2b71ea2c9ce5b5f64f696075331430400eadce97ab69c43a5f8f4861b45ff576b35130813e394d0ba664d908f85b2db57fb24cbb95079585e40ab74caeca83
7
- data.tar.gz: cf43ab1b0deb70334249da04fa504dc39ff16814bed614b0cd17cc10028671ac31350b441bd5fd6fd58455a9756d2eaa18c3e18bd9aac146d289d6ff1b3e1094
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,47 +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|
24
- if converter
25
- converter.call(Regexp.last_match)
26
- else
27
- %(<span class="#{class_name}">#{ERB::Util.html_escape(text)}</span>)
28
- end
16
+ def apply_filter(content)
17
+ content.gsub(context[:highlight_pattern]) do |text|
18
+ if converter
19
+ converter.call(Regexp.last_match)
20
+ else
21
+ %(<span class="#{class_name}">#{ERB::Util.html_escape(text)}</span>)
29
22
  end
30
23
  end
24
+ end
31
25
 
32
- def validate
33
- needs(:highlight_pattern)
34
- end
26
+ def validate
27
+ needs(:highlight_pattern)
28
+ end
35
29
 
36
- private
30
+ private
37
31
 
38
- def class_name
39
- @context[:highlight_class_name] || DEFAULT_CLASS_NAME
40
- end
32
+ def class_name
33
+ context.fetch(:highlight_class_name, DEFAULT_CLASS_NAME)
34
+ end
41
35
 
42
- def converter
43
- @context[:highlight_converter]
44
- end
36
+ def converter
37
+ context[:highlight_converter]
45
38
  end
46
39
  end
47
40
  end
@@ -1,7 +1,5 @@
1
- module HTML
2
- class Pipeline
3
- module Highlight
4
- VERSION = '0.2.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.2.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: 2021-07-05 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: []