html-pipeline-highlight 0.2.0 → 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 +4 -4
- data/.vscode/settings.json +5 -0
- data/README.md +5 -5
- data/html-pipeline-highlight.gemspec +2 -2
- data/lib/html/pipeline/highlight/filter.rb +27 -34
- data/lib/html/pipeline/highlight/version.rb +3 -5
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4424f7176e0bfbba8176d9c4ab3cbe79969c63fc5d7471a9e689268450a78e3b
|
4
|
+
data.tar.gz: 1592c479e27a1e3b0b7ecafeeda8f752fb4add2307225d35d5d5eaadfe52970e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22b14a02438ef7d7352c495ca3ec7102a85578d7211920d44f4b8db331a0648b75dd11dc5b7e0f3efd08dcab25a56cdeb47e3b7d531fe19abdc14281aa0f226c
|
7
|
+
data.tar.gz: 6d8f77118c4f99eca2b12c318d3f0fd1f09e8b8a315981206390a382b9ceebb0ac340b4bdc3bb88653a49d946b53e3b9d1a0c2143f11a553eb9f05116e451d58
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# HTMLPipeline::Highlight
|
2
2
|
|
3
|
-
Highlight
|
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
|
-
|
25
|
-
|
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
|
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 =
|
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 '
|
1
|
+
require 'html_pipeline'
|
2
2
|
|
3
|
-
|
4
|
-
class
|
5
|
-
|
6
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
12
|
+
def handle_text_chunk(text)
|
13
|
+
text.replace(apply_filter(text.to_s), as: :html)
|
14
|
+
end
|
21
15
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
26
|
+
def validate
|
27
|
+
needs(:highlight_pattern)
|
28
|
+
end
|
35
29
|
|
36
|
-
|
30
|
+
private
|
37
31
|
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
def class_name
|
33
|
+
context.fetch(:highlight_class_name, DEFAULT_CLASS_NAME)
|
34
|
+
end
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
36
|
+
def converter
|
37
|
+
context[:highlight_converter]
|
45
38
|
end
|
46
39
|
end
|
47
40
|
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.
|
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:
|
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.
|
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: []
|