html-pipeline 3.0.1 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +6 -6
- data/lib/html_pipeline/sanitization_filter.rb +2 -0
- data/lib/html_pipeline/version.rb +1 -1
- data/lib/html_pipeline.rb +33 -19
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22c3391b770c24cbed1ea42f396fabfa399935416c8d01a8ce8727094c456fe4
|
4
|
+
data.tar.gz: 6936f1943d251689b0bef19f43348ac46e2027d658ec7544dc4799ab98600602
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dce1a303621b079f2e482007ad77761d745ca0bdec98bf405cedeb5d4f1b6a097b7c28bf96e919ae2b2b5129cc1bf0f528dd6d4e617eafb2767f760a24079a6e
|
7
|
+
data.tar.gz: 821a0b306d7cc440069ae38ca857f7ed157d1ec5c3decbbbcfc3a4fd05b5c17e975e493e9017ac1eaed5a216de0b00dfc3bed405e64e40b2d1e03a04b44b14cb
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
## [v3.0.2] - 08-01-2024
|
2
|
+
## What's Changed
|
3
|
+
* README.md: Fix example code by @grekko in https://github.com/gjtorikian/html-pipeline/pull/390
|
4
|
+
* Allow pipeline to run without node filters by @gjtorikian in https://github.com/gjtorikian/html-pipeline/pull/392
|
5
|
+
|
6
|
+
## New Contributors
|
7
|
+
* @grekko made their first contribution in https://github.com/gjtorikian/html-pipeline/pull/390
|
8
|
+
|
9
|
+
**Full Changelog**: https://github.com/gjtorikian/html-pipeline/compare/v3.0.1...v3.0.2
|
10
|
+
## [v3.0.1] - 28-12-2023
|
11
|
+
## What's Changed
|
12
|
+
* Handle odd numbers of NodeFilters to be configured by @stevehill1981 in https://github.com/gjtorikian/html-pipeline/pull/389
|
13
|
+
|
14
|
+
## New Contributors
|
15
|
+
* @stevehill1981 made their first contribution in https://github.com/gjtorikian/html-pipeline/pull/389
|
16
|
+
|
17
|
+
**Full Changelog**: https://github.com/gjtorikian/html-pipeline/compare/v3.0.0...v3.0.1
|
1
18
|
## [v3.0.0] - 24-12-2023
|
2
19
|
## What's Changed
|
3
20
|
* Switch to GitHub Actions by @gjtorikian in https://github.com/gjtorikian/html-pipeline/pull/346
|
data/README.md
CHANGED
@@ -91,8 +91,8 @@ pipeline.call(user_supplied_text) # recommended: can call pipeline over and over
|
|
91
91
|
Filters can be custom ones you create (like `HelloJohnnyFilter`), and `HTMLPipeline` additionally provides several helpful ones (detailed below). If you only need a single filter, you can call one individually, too:
|
92
92
|
|
93
93
|
```ruby
|
94
|
-
filter = HTMLPipeline::ConvertFilter::MarkdownFilter.new
|
95
|
-
filter.call
|
94
|
+
filter = HTMLPipeline::ConvertFilter::MarkdownFilter.new
|
95
|
+
filter.call(text)
|
96
96
|
```
|
97
97
|
|
98
98
|
Filters combine into a sequential pipeline, and each filter hands its
|
@@ -104,9 +104,9 @@ used to pass around arguments and metadata between filters in a pipeline. For
|
|
104
104
|
example, if you want to disable footnotes in the `MarkdownFilter`, you can pass an option in the context hash:
|
105
105
|
|
106
106
|
```ruby
|
107
|
-
context = { markdown: extensions: { footnotes: false } }
|
108
|
-
filter = HTMLPipeline::ConvertFilter::MarkdownFilter.new(
|
109
|
-
filter.call
|
107
|
+
context = { markdown: { extensions: { footnotes: false } } }
|
108
|
+
filter = HTMLPipeline::ConvertFilter::MarkdownFilter.new(context: context)
|
109
|
+
filter.call("Hi **world**!")
|
110
110
|
```
|
111
111
|
|
112
112
|
Please refer to the documentation for each filter to understand what configuration options are available.
|
@@ -375,7 +375,7 @@ you to add additional elements. You can either modify the constant's value, or
|
|
375
375
|
re-define your own config and pass that in, such as:
|
376
376
|
|
377
377
|
```ruby
|
378
|
-
config = HTMLPipeline::
|
378
|
+
config = HTMLPipeline::SanitizationFilter::DEFAULT_CONFIG.dup
|
379
379
|
config[:elements] << "iframe" # sure, whatever you want
|
380
380
|
```
|
381
381
|
|
data/lib/html_pipeline.rb
CHANGED
@@ -114,10 +114,10 @@ class HTMLPipeline
|
|
114
114
|
def initialize(text_filters: [], convert_filter: nil, sanitization_config: SanitizationFilter::DEFAULT_CONFIG, node_filters: [], default_context: {}, result_class: Hash)
|
115
115
|
raise ArgumentError, "default_context cannot be nil" if default_context.nil?
|
116
116
|
|
117
|
-
@text_filters = text_filters.flatten.freeze
|
117
|
+
@text_filters = text_filters.flatten.freeze || []
|
118
118
|
validate_filters(@text_filters, HTMLPipeline::TextFilter)
|
119
119
|
|
120
|
-
@node_filters = node_filters.flatten.freeze
|
120
|
+
@node_filters = node_filters.flatten.freeze || []
|
121
121
|
validate_filters(@node_filters, HTMLPipeline::NodeFilter)
|
122
122
|
|
123
123
|
@convert_filter = convert_filter
|
@@ -151,33 +151,46 @@ class HTMLPipeline
|
|
151
151
|
context = context.freeze
|
152
152
|
result ||= {}
|
153
153
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
154
|
+
if @text_filters.any?
|
155
|
+
payload = default_payload({
|
156
|
+
text_filters: @text_filters.map(&:name),
|
157
|
+
context: context,
|
158
|
+
result: result,
|
159
|
+
})
|
160
|
+
instrument("call_text_filters.html_pipeline", payload) do
|
161
|
+
result[:output] =
|
162
|
+
@text_filters.inject(text) do |doc, filter|
|
163
|
+
perform_filter(filter, doc, context: context, result: result)
|
164
|
+
end
|
165
|
+
end
|
164
166
|
end
|
165
167
|
|
166
|
-
text = result[:output]
|
168
|
+
text = result[:output] || text
|
167
169
|
|
168
|
-
html =
|
170
|
+
html = if @convert_filter.nil?
|
171
|
+
text
|
172
|
+
else
|
173
|
+
instrument("call_convert_filter.html_pipeline", payload) do
|
174
|
+
html = @convert_filter.call(text)
|
175
|
+
end
|
176
|
+
end
|
169
177
|
|
170
178
|
unless @node_filters.empty?
|
171
|
-
payload = default_payload({
|
172
|
-
node_filters: @node_filters.map { |f| f.class.name },
|
173
|
-
context: context,
|
174
|
-
result: result,
|
175
|
-
})
|
176
179
|
instrument("call_node_filters.html_pipeline", payload) do
|
177
180
|
result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, handlers: @node_filters).rewrite(html)
|
181
|
+
html = result[:output]
|
182
|
+
payload = default_payload({
|
183
|
+
node_filters: @node_filters.map { |f| f.class.name },
|
184
|
+
context: context,
|
185
|
+
result: result,
|
186
|
+
})
|
178
187
|
end
|
179
188
|
end
|
180
189
|
|
190
|
+
instrument("html_pipeline.sanitization", payload) do
|
191
|
+
result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, handlers: @node_filters).rewrite(html)
|
192
|
+
end
|
193
|
+
|
181
194
|
result = result.merge(@node_filters.collect(&:result).reduce({}, :merge))
|
182
195
|
@node_filters.each(&:reset!)
|
183
196
|
|
@@ -195,6 +208,7 @@ class HTMLPipeline
|
|
195
208
|
context: context,
|
196
209
|
result: result,
|
197
210
|
})
|
211
|
+
|
198
212
|
instrument("call_filter.html_pipeline", payload) do
|
199
213
|
filter.call(doc, context: context, result: result)
|
200
214
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen J. Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: selma
|
@@ -111,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: 3.3.22
|
113
113
|
requirements: []
|
114
|
-
rubygems_version: 3.5.
|
114
|
+
rubygems_version: 3.5.5
|
115
115
|
signing_key:
|
116
116
|
specification_version: 4
|
117
117
|
summary: Helpers for processing content through a chain of filters
|