html-pipeline 3.1.1 → 3.2.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: fabe2eaefdce46521fffa5ddbbe5fc1d77a763a48ad4beab286ff77cabd2bbd4
4
- data.tar.gz: faf1d2aea3de3f6ee47e309cf7bd6fe631aa027c164525fd2eee7b8b038e845b
3
+ metadata.gz: e8252d2015129b2ee071b6c094a773afecd796a75d0ab3d24aaa18b997be8f1f
4
+ data.tar.gz: 3ace3231f84d7f5a82b4921d2ee600a4ae069440adb15e4ee527eda290b00637
5
5
  SHA512:
6
- metadata.gz: b7e3b4445465f84909c991cfbbbcadc268c95e2ff0936748eb4257f046201a4a3abe65f9117cfba9679246adc2292e7a379d5eb9fad50dfb40fc3534ea330c21
7
- data.tar.gz: 97d015f909923900889e2fea5ee077f56ddd8166089c98f1860280c52be5ba01a363c87f404a15d6fbb6519b04aa1f2d6d9281dfc07c9ab36ceb43c851672ef9
6
+ metadata.gz: be71b5590d6599b2a2c8d6dfdb98b27e61701a07bbc1a0aa14982459bfd65d8aec69228318834c939a6357dff03c982e739d2a39a83853e12016049e2ddd13e2
7
+ data.tar.gz: b90b25b60016557c21eef5ee431c21890f5580589fabfafbe36e530ff3dc63cd3e3a83cf835c757cf8b7398e58c2f290096cf7ef8173177a27457b15871fe5e9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [v3.1.1] - 09-04-2024
2
+ ## What's Changed
3
+ * Correct missing method implementation by @gjtorikian in https://github.com/gjtorikian/html-pipeline/pull/401
4
+
5
+
6
+ **Full Changelog**: https://github.com/gjtorikian/html-pipeline/compare/v3.1.0...v3.1.1
1
7
  ## [v3.1.0] - 28-02-2024
2
8
  ## What's Changed
3
9
  * UPGRADING: not removed by @dentarg in https://github.com/gjtorikian/html-pipeline/pull/397
data/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # HTML-Pipeline
2
2
 
3
- > **Note**
4
- > This README refers to the behavior in the new 3.0.0.pre gem.
5
-
6
3
  HTML processing filters and utilities. This module is a small
7
4
  framework for defining CSS-based content filters and applying them to user
8
5
  provided content.
@@ -60,9 +57,15 @@ results tothe next filter. A pipeline has several kinds of filters available to
60
57
 
61
58
  You can assemble each sequence into a single pipeline, or choose to call each filter individually.
62
59
 
63
- As an example, suppose we want to transform Commonmark source text into Markdown HTML. With the content, we also want to:
60
+ As an example, suppose we want to transform Commonmark source text into Markdown HTML:
64
61
 
65
- - change every instance of `$NAME` to "`Johnny"
62
+ ```
63
+ Hey there, @gjtorikian
64
+ ```
65
+
66
+ With the content, we also want to:
67
+
68
+ - change every instance of `Hey` to `Hello`
66
69
  - strip undesired HTML
67
70
  - linkify @mention
68
71
 
@@ -73,7 +76,7 @@ require 'html_pipeline'
73
76
 
74
77
  class HelloJohnnyFilter < HTMLPipelineFilter
75
78
  def call
76
- text.gsub("$NAME", "Johnny")
79
+ text.gsub("Hey", "Hello")
77
80
  end
78
81
  end
79
82
 
@@ -104,11 +107,21 @@ used to pass around arguments and metadata between filters in a pipeline. For
104
107
  example, if you want to disable footnotes in the `MarkdownFilter`, you can pass an option in the context hash:
105
108
 
106
109
  ```ruby
107
- context = { markdown: { extensions: { footnotes: false } } }
110
+ context = { markdown: { extensions: { footnotes: false } } }
108
111
  filter = HTMLPipeline::ConvertFilter::MarkdownFilter.new(context: context)
109
112
  filter.call("Hi **world**!")
110
113
  ```
111
114
 
115
+ Alternatively, you can construct a pipeline, and pass in a context during the call:
116
+
117
+ ```ruby
118
+ pipeline = HTMLPipeline.new(
119
+ convert_filter: HTMLPipeline::ConvertFilter::MarkdownFilter.new,
120
+ node_filters: [HTMLPipeline::NodeFilter::MentionFilter.new]
121
+ )
122
+ pipeline.call(user_supplied_text, context: { markdown: { extensions: { footnotes: false } } })
123
+ ```
124
+
112
125
  Please refer to the documentation for each filter to understand what configuration options are available.
113
126
 
114
127
  ### More Examples
@@ -3,7 +3,7 @@
3
3
  HTMLPipeline.require_dependency("commonmarker", "MarkdownFilter")
4
4
 
5
5
  class HTMLPipeline
6
- class ConvertFilter
6
+ class ConvertFilter < Filter
7
7
  # HTML Filter that converts Markdown text into HTML.
8
8
  #
9
9
  # Context options:
@@ -16,8 +16,8 @@ class HTMLPipeline
16
16
  end
17
17
 
18
18
  # Convert Commonmark to HTML using the best available implementation.
19
- def call(text)
20
- options = @context.fetch(:markdown, {})
19
+ def call(text, context: @context)
20
+ options = context.fetch(:markdown, {})
21
21
  plugins = options.fetch(:plugins, {})
22
22
  Commonmarker.to_html(text, options: options, plugins: plugins).rstrip!
23
23
  end
@@ -27,7 +27,7 @@ class HTMLPipeline
27
27
  # Public: Returns a simple Hash used to pass extra information into filters
28
28
  # and also to allow filters to make extracted information available to the
29
29
  # caller.
30
- attr_reader :context
30
+ attr_accessor :context
31
31
 
32
32
  # Public: Returns a Hash used to allow filters to pass back information
33
33
  # to callers of the various Pipelines. This can be used for
@@ -4,6 +4,8 @@ require "selma"
4
4
 
5
5
  class HTMLPipeline
6
6
  class NodeFilter < Filter
7
+ attr_accessor :context
8
+
7
9
  def initialize(context: {}, result: {})
8
10
  super(context: context, result: {})
9
11
  send(:after_initialize) if respond_to?(:after_initialize)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class HTMLPipeline
4
- VERSION = "3.1.1"
4
+ VERSION = "3.2.0"
5
5
  end
data/lib/html_pipeline.rb CHANGED
@@ -160,7 +160,7 @@ class HTMLPipeline
160
160
  instrument("call_text_filters.html_pipeline", payload) do
161
161
  result[:output] =
162
162
  @text_filters.inject(text) do |doc, filter|
163
- perform_filter(filter, doc, context: context, result: result)
163
+ perform_filter(filter, doc, context: (filter.context || {}).merge(context), result: result)
164
164
  end
165
165
  end
166
166
  end
@@ -171,12 +171,13 @@ class HTMLPipeline
171
171
  text
172
172
  else
173
173
  instrument("call_convert_filter.html_pipeline", payload) do
174
- html = @convert_filter.call(text)
174
+ html = @convert_filter.call(text, context: (@convert_filter.context || {}).merge(context))
175
175
  end
176
176
  end
177
177
 
178
178
  unless @node_filters.empty?
179
179
  instrument("call_node_filters.html_pipeline", payload) do
180
+ @node_filters.each { |filter| filter.context = (filter.context || {}).merge(context) }
180
181
  result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, handlers: @node_filters).rewrite(html)
181
182
  html = result[:output]
182
183
  payload = default_payload({
@@ -187,7 +188,7 @@ class HTMLPipeline
187
188
  end
188
189
  end
189
190
 
190
- instrument("html_pipeline.sanitization", payload) do
191
+ instrument("sanitization.html_pipeline", payload) do
191
192
  result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, handlers: @node_filters).rewrite(html)
192
193
  end
193
194
 
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.1.1
4
+ version: 3.2.0
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: 2024-04-09 00:00:00.000000000 Z
11
+ date: 2024-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selma