html-pipeline 3.0.1 → 3.0.2

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: ca6ca26f7072957b016a32ac4f88923b1f7a34da25b91646612783bae9fd0cef
4
- data.tar.gz: 44c0de334401dbdb58cbfc68f398311beb61b135f6fc3931c63818f063c0fc7d
3
+ metadata.gz: ad9e9991f181f9b708acdb8b5ba27537e759f3f87cd624c2587e248524747f0f
4
+ data.tar.gz: ffaa220bac349aedd97a240de688c6ef0abe44b947a8aedd9df804fc13057e71
5
5
  SHA512:
6
- metadata.gz: e582606d24060d6e54387df1014182c8b7952d3f84fbe7d68fd135ac0e3c93826241810cf9fa5eb36c8c9f864f4fffa9935d36f1813b9604bf7307a360d52132
7
- data.tar.gz: c7c1e2bfd59d9607f877c1134ffe05a4da93f070763240c88fac61316fb861f61e80ea93df3400bc9fe353dc6411de24194ef2e3e4e3f2131ca6a0fb0a96d87d
6
+ metadata.gz: 41179127f775429b7de505c334d76a22771a903a9bcfb4fe6c47c344aae6fa94b92d15a66fb41bb61657924a5360548858ee7c7daac08476c2b72be73f355230
7
+ data.tar.gz: 1f937f9f2eee0ea99d5d8c1069648f10c8702da88524057e70aa1ca691be1a49bf645f249bdb07b6d4ccc8c9620ec463ca85f2285274cfee29a3f052368128c9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [v3.0.1] - 28-12-2023
2
+ ## What's Changed
3
+ * Handle odd numbers of NodeFilters to be configured by @stevehill1981 in https://github.com/gjtorikian/html-pipeline/pull/389
4
+
5
+ ## New Contributors
6
+ * @stevehill1981 made their first contribution in https://github.com/gjtorikian/html-pipeline/pull/389
7
+
8
+ **Full Changelog**: https://github.com/gjtorikian/html-pipeline/compare/v3.0.0...v3.0.1
1
9
  ## [v3.0.0] - 24-12-2023
2
10
  ## What's Changed
3
11
  * 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(text)
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("Hi **world**!", context: context)
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class HTMLPipeline
4
- VERSION = "3.0.1"
4
+ VERSION = "3.0.2"
5
5
  end
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
- payload = default_payload({
155
- text_filters: @text_filters.map(&:name),
156
- context: context,
157
- result: result,
158
- })
159
- instrument("call_text_filters.html_pipeline", payload) do
160
- result[:output] =
161
- @text_filters.inject(text) do |doc, filter|
162
- perform_filter(filter, doc, context: context, result: result)
163
- end
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 = @convert_filter.call(text) unless @convert_filter.nil?
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.1
4
+ version: 3.0.2
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: 2023-12-28 00:00:00.000000000 Z
11
+ date: 2024-01-08 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.3
114
+ rubygems_version: 3.5.4
115
115
  signing_key:
116
116
  specification_version: 4
117
117
  summary: Helpers for processing content through a chain of filters