html-pipeline 3.2.0 → 3.2.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: e8252d2015129b2ee071b6c094a773afecd796a75d0ab3d24aaa18b997be8f1f
4
- data.tar.gz: 3ace3231f84d7f5a82b4921d2ee600a4ae069440adb15e4ee527eda290b00637
3
+ metadata.gz: 6e66a69a9e35bc5703f036d091740bdc654f98cfaf38870761797699ed28199b
4
+ data.tar.gz: 7624bb08357fa9f358cb4947dbf5742916a3e620fa7db2d5296e9aba414e40f5
5
5
  SHA512:
6
- metadata.gz: be71b5590d6599b2a2c8d6dfdb98b27e61701a07bbc1a0aa14982459bfd65d8aec69228318834c939a6357dff03c982e739d2a39a83853e12016049e2ddd13e2
7
- data.tar.gz: b90b25b60016557c21eef5ee431c21890f5580589fabfafbe36e530ff3dc63cd3e3a83cf835c757cf8b7398e58c2f290096cf7ef8173177a27457b15871fe5e9
6
+ metadata.gz: 19083c1093cf8908028e8ea5233c97005a25072b5d77e9c28368570d477ff09cba5f6ae78e93e3633b766b9dcaeccc7bd746aacecbfdf480cd467306b230c1af
7
+ data.tar.gz: 74e3afc29616225353448945af5a3ee516a8cea67924e865edf89a65b92cf77d56196b2be50ccd6fce6d5d343ed4cc7181b3b6b7d2a146dbb281a1165ba66ef3
@@ -1,4 +1,4 @@
1
- name: Release
1
+ name: Tag and Release
2
2
 
3
3
  on:
4
4
  workflow_dispatch:
@@ -7,13 +7,18 @@ on:
7
7
  - main
8
8
  paths:
9
9
  - "lib/html_pipeline/version.rb"
10
+ pull_request_target:
11
+ types:
12
+ - closed
10
13
 
11
14
  jobs:
12
15
  ruby:
13
16
  uses: yettoapp/actions/.github/workflows/ruby_gem_release.yml@main
14
17
  secrets:
15
18
  rubygems_api_key: ${{ secrets.RUBYGEMS_API_BOT_KEY }}
16
- gh_token: ${{ secrets.PUBLIC_PUSH_TO_PROTECTED_BRANCH }}
19
+ gh_token: ${{ secrets.GITHUB_TOKEN }}
17
20
  with:
18
21
  gem_name: html-pipeline
19
22
  version_filepath: lib/html_pipeline/version.rb
23
+ prepare: ${{ github.event_name == 'push' }}
24
+ release: ${{ github.event_name == 'workflow_dispatch' || ((github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'release'))) }}
data/.gitignore CHANGED
@@ -17,4 +17,4 @@ test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
19
  exec/*
20
- vendor/gems
20
+ vendor/cache/
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ # [v3.2.2] - 09-08-2024
2
+ ## What's Changed
3
+ * Add support for @ prefix on MentionFilter base_url by @jeremysmithco in https://github.com/gjtorikian/html-pipeline/pull/411
4
+ * Bugfix: sanitization-only filters should still work by @gjtorikian in https://github.com/gjtorikian/html-pipeline/pull/414
5
+
6
+ ## New Contributors
7
+ * @jeremysmithco made their first contribution in https://github.com/gjtorikian/html-pipeline/pull/411
8
+
9
+ **Full Changelog**: https://github.com/gjtorikian/html-pipeline/compare/v3.2.1...v3.2.2
10
+ # [v3.2.1] - 16-07-2024
11
+ ## What's Changed
12
+ * Update commonmarker requirement from ~> 1.0.0.pre7 to ~> 1.1.2 in the bundler-dependencies group by @dependabot in https://github.com/gjtorikian/html-pipeline/pull/404
13
+ * Remove superfluous sanitization by @gjtorikian in https://github.com/gjtorikian/html-pipeline/pull/408
14
+
15
+
16
+ **Full Changelog**: https://github.com/gjtorikian/html-pipeline/compare/v3.2.0...v3.2.1
17
+ ## [v3.2.0] - 30-04-2024
18
+ ## What's Changed
19
+ * Pass context along to every part of the pipeline by @gjtorikian in https://github.com/gjtorikian/html-pipeline/pull/403
20
+
21
+
22
+ **Full Changelog**: https://github.com/gjtorikian/html-pipeline/compare/v3.1.1...v3.2.0
1
23
  ## [v3.1.1] - 09-04-2024
2
24
  ## What's Changed
3
25
  * Correct missing method implementation by @gjtorikian in https://github.com/gjtorikian/html-pipeline/pull/401
data/Gemfile CHANGED
@@ -25,7 +25,7 @@ group :development do
25
25
  end
26
26
 
27
27
  group :test do
28
- gem "commonmarker", "~> 1.0.0.pre7", require: false
28
+ gem "commonmarker", "~> 2.0.1", require: false
29
29
  gem "gemoji", "~> 4.1", require: false
30
30
  gem "gemojione", "~> 4.3", require: false
31
31
 
data/README.md CHANGED
@@ -171,9 +171,9 @@ The `ConvertFilter` takes text and turns it into HTML. `@text`, `@config`, and `
171
171
 
172
172
  ### Sanitization
173
173
 
174
- Because the web can be a scary place, HTML is automatically sanitized after the `ConvertFilter` runs and before the `NodeFilter`s are processed. This is to prevent malicious or unexpected input from entering the pipeline.
174
+ Because the web can be a scary place, **HTML is automatically sanitized** after the `ConvertFilter` runs and before the `NodeFilter`s are processed. This is to prevent malicious or unexpected input from entering the pipeline.
175
175
 
176
- The sanitization process takes a hash configuration of settings. See the [Selma](https://www.github.com/gjtorikian/selma) documentation for more information on how to configure these settings.
176
+ The sanitization process takes a hash configuration of settings. See the [Selma](https://www.github.com/gjtorikian/selma) documentation for more information on how to configure these settings. Note that users must correctly configure the sanitization configuration if they expect to use it correctly in conjunction with handlers which manipulate HTML.
177
177
 
178
178
  A default sanitization config is provided by this library (`HTMLPipeline::SanitizationFilter::DEFAULT_CONFIG`). A sample custom sanitization allowlist might look like this:
179
179
 
@@ -224,7 +224,7 @@ For more examples of customizing the sanitization process to include the tags yo
224
224
 
225
225
  `NodeFilters`s can operate either on HTML elements or text nodes using CSS selectors. Each `NodeFilter` must define a method named `selector` which provides an instance of `Selma::Selector`. If elements are being manipulated, `handle_element` must be defined, taking one argument, `element`; if text nodes are being manipulated, `handle_text_chunk` must be defined, taking one argument, `text_chunk`. `@config`, and `@result` are available to use, and any changes made to these ivars are passed on to the next filter.
226
226
 
227
- `NodeFilter` also has an optional method, `after_initialize`, which is run after the filter initializes. This can be useful in setting up a custom state for `result` to take advantage of.
227
+ `NodeFilter` also has an optional method, `after_initialize`, which is run after the filter initializes. This can be useful in setting up a fresh custom state for `result` to start from each time the pipeline is called.
228
228
 
229
229
  Here's an example `NodeFilter` that adds a base url to images that are root relative:
230
230
 
@@ -343,34 +343,6 @@ service.subscribe "call_text_filters.html_pipeline" do |event, start, ending, tr
343
343
  end
344
344
  ```
345
345
 
346
- ## Third Party Extensions
347
-
348
- If you have an idea for a filter, propose it as
349
- [an issue](https://github.com/gjtorikian/html-pipeline/issues) first. This allows us to discuss
350
- whether the filter is a common enough use case to belong in this gem, or should be
351
- built as an external gem.
352
-
353
- Here are some extensions people have built:
354
-
355
- - [html-pipeline-asciidoc_filter](https://github.com/asciidoctor/html-pipeline-asciidoc_filter)
356
- - [jekyll-html-pipeline](https://github.com/gjtorikian/jekyll-html-pipeline)
357
- - [nanoc-html-pipeline](https://github.com/burnto/nanoc-html-pipeline)
358
- - [html-pipeline-bitly](https://github.com/dewski/html-pipeline-bitly)
359
- - [html-pipeline-cite](https://github.com/lifted-studios/html-pipeline-cite)
360
- - [tilt-html-pipeline](https://github.com/bradgessler/tilt-html-pipeline)
361
- - [html-pipeline-wiki-link'](https://github.com/lifted-studios/html-pipeline-wiki-link) - WikiMedia-style wiki links
362
- - [task_list](https://github.com/github/task_list) - GitHub flavor Markdown Task List
363
- - [html-pipeline-nico_link](https://github.com/rutan/html-pipeline-nico_link) - An HTMLPipeline filter for [niconico](http://www.nicovideo.jp) description links
364
- - [html-pipeline-gitlab](https://gitlab.com/gitlab-org/html-pipeline-gitlab) - This gem implements various filters for html-pipeline used by GitLab
365
- - [html-pipeline-youtube](https://github.com/st0012/html-pipeline-youtube) - An HTMLPipeline filter for YouTube links
366
- - [html-pipeline-flickr](https://github.com/st0012/html-pipeline-flickr) - An HTMLPipeline filter for Flickr links
367
- - [html-pipeline-vimeo](https://github.com/dlackty/html-pipeline-vimeo) - An HTMLPipeline filter for Vimeo links
368
- - [html-pipeline-hashtag](https://github.com/mr-dxdy/html-pipeline-hashtag) - An HTMLPipeline filter for hashtags
369
- - [html-pipeline-linkify_github](https://github.com/jollygoodcode/html-pipeline-linkify_github) - An HTMLPipeline filter to autolink GitHub urls
370
- - [html-pipeline-redcarpet_filter](https://github.com/bmikol/html-pipeline-redcarpet_filter) - Render Markdown source text into Markdown HTML using Redcarpet
371
- - [html-pipeline-typogruby_filter](https://github.com/bmikol/html-pipeline-typogruby_filter) - Add Typogruby text filters to your HTMLPipeline
372
- - [korgi](https://github.com/jodeci/korgi) - HTMLPipeline filters for links to Rails resources
373
-
374
346
  ## FAQ
375
347
 
376
348
  ### 1. Why doesn't my pipeline work when there's no root element in the document?
@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
25
25
  "rubygems_mfa_required" => "true",
26
26
  }
27
27
 
28
- gem.add_dependency("selma", "~> 0.1")
28
+ gem.add_dependency("selma", "~> 0.4")
29
29
  gem.add_dependency("zeitwerk", "~> 2.5")
30
30
 
31
31
  gem.post_install_message = <<~MSG
@@ -12,7 +12,7 @@ class HTMLPipeline
12
12
  # :markdown[:extensions] => Commonmarker extensions options
13
13
  class MarkdownFilter < ConvertFilter
14
14
  def initialize(context: {}, result: {})
15
- super(context: context, result: result)
15
+ super
16
16
  end
17
17
 
18
18
  # Convert Commonmark to HTML using the best available implementation.
@@ -5,7 +5,7 @@ class HTMLPipeline
5
5
  attr_reader :text, :html
6
6
 
7
7
  def initialize(context: {}, result: {})
8
- super(context: context, result: result)
8
+ super
9
9
  end
10
10
 
11
11
  class << self
@@ -115,7 +115,8 @@ class HTMLPipeline
115
115
  result[:mentioned_usernames] |= [login]
116
116
 
117
117
  url = base_url.dup
118
- url << "/" unless %r{[/~]\z}.match?(url)
118
+ excluded_prefixes = %r{[/(?:~|@]\z}
119
+ url << "/" unless excluded_prefixes.match?(url)
119
120
 
120
121
  "<a href=\"#{url << login}\" class=\"user-mention\">" \
121
122
  "@#{login}" \
@@ -15,7 +15,7 @@ class HTMLPipeline
15
15
  # This filter does not write any additional information to the context hash.
16
16
  class SyntaxHighlightFilter < NodeFilter
17
17
  def initialize(context: {}, result: {})
18
- super(context: context, result: result)
18
+ super
19
19
  # TODO: test the optionality of this
20
20
  @formatter = context[:formatter] || Rouge::Formatters::HTML.new
21
21
  end
@@ -94,7 +94,8 @@ class HTMLPipeline
94
94
  result[:mentioned_teams] |= [team]
95
95
 
96
96
  url = base_url.dup
97
- url << "/" unless %r{[/~]\z}.match?(url)
97
+ excluded_prefixes = %r{[/(?:~|@]\z}
98
+ url << "/" unless excluded_prefixes.match?(url)
98
99
 
99
100
  "<a href=\"#{url << org}/#{team}\" class=\"team-mention\">" \
100
101
  "@#{org}/#{team}" \
@@ -5,7 +5,7 @@ class HTMLPipeline
5
5
  attr_reader :text
6
6
 
7
7
  def initialize(context: {}, result: {})
8
- super(context: context, result: result)
8
+ super
9
9
  end
10
10
 
11
11
  class << self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class HTMLPipeline
4
- VERSION = "3.2.0"
4
+ VERSION = "3.2.2"
5
5
  end
data/lib/html_pipeline.rb CHANGED
@@ -175,11 +175,20 @@ class HTMLPipeline
175
175
  end
176
176
  end
177
177
 
178
- unless @node_filters.empty?
178
+ rewriter_options = {
179
+ memory: {
180
+ max_allowed_memory_usage: 5242880, # arbitrary limit of 5MB
181
+ },
182
+ }
183
+
184
+ if @node_filters.empty?
185
+ instrument("sanitization.html_pipeline", payload) do
186
+ result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, options: rewriter_options).rewrite(html)
187
+ end
188
+ else
179
189
  instrument("call_node_filters.html_pipeline", payload) do
180
190
  @node_filters.each { |filter| filter.context = (filter.context || {}).merge(context) }
181
- result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, handlers: @node_filters).rewrite(html)
182
- html = result[:output]
191
+ result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, handlers: @node_filters, options: rewriter_options).rewrite(html)
183
192
  payload = default_payload({
184
193
  node_filters: @node_filters.map { |f| f.class.name },
185
194
  context: context,
@@ -188,10 +197,6 @@ class HTMLPipeline
188
197
  end
189
198
  end
190
199
 
191
- instrument("sanitization.html_pipeline", payload) do
192
- result[:output] = Selma::Rewriter.new(sanitizer: @sanitization_config, handlers: @node_filters).rewrite(html)
193
- end
194
-
195
200
  result = result.merge(@node_filters.collect(&:result).reduce({}, :merge))
196
201
  @node_filters.each(&:reset!)
197
202
 
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.2.0
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen J. Torikian
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-30 00:00:00.000000000 Z
11
+ date: 2024-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: selma
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.1'
19
+ version: '0.4'
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.1'
26
+ version: '0.4'
27
27
  force_ruby_platform: false
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: zeitwerk
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: 3.3.22
113
113
  requirements: []
114
114
  rubygems_version: 3.4.6
115
- signing_key:
115
+ signing_key:
116
116
  specification_version: 4
117
117
  summary: Helpers for processing content through a chain of filters
118
118
  test_files: []