html-pipeline 2.11.1 → 2.13.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: 6247333ffe74b1a26211f5563ceea18e43b355aa8b8fe5b0474355f7efa81f93
4
- data.tar.gz: 0f29d8cae966aa24960a57e874a73693e50040444d3f98d2c505b6bb6161c9e9
3
+ metadata.gz: e8d5622a3fa6bf3a03909aa620ddb19ff0c2b1b3296a2a019410e1f69a5e4fa1
4
+ data.tar.gz: f21358c32997b668bd7c8d70756b18763e049ae1a10bbd65bd87d1a84d723efb
5
5
  SHA512:
6
- metadata.gz: 19b69c57d6b7df1efa7ad35c754b283242d46d61a6b8a8313ca27ea2929511934eecf4c019e744cd640704455a0ac0ec06f52bcb2929425f58153320b2e47be2
7
- data.tar.gz: 9fb8ca18eeb49d3150e7b88e024b89da94e88e8723861964e49a8873e0045e8886b49745deff0973b3cd731fb2488283a96fad7b23dec7d3fd9f424a087a75f9
6
+ metadata.gz: e2d55abf9182888317ecdc9e426185ecea7d4047096766082d9f271df78b21fb257bfacbcecf9ca500aac8bc1e7db5a00dbdc9b762bb2cae18205c55228e1215
7
+ data.tar.gz: cc8eedcfeb8cebfbd651f0f1ba86391857e825766e1a87d9b4c330f42bdbb881dda9b6690aed17e7134e49c6bd61ff3ff70e7fac08dd03adead8a1ddb90d710c
@@ -0,0 +1,4 @@
1
+ github: gjtorikian
2
+ patreon: gjtorikian
3
+ open_collective: garen-torikian
4
+ issuehunt: gjtorikian
@@ -13,6 +13,7 @@ addons:
13
13
  script: bundle exec rake
14
14
 
15
15
  gemfile:
16
+ - gemfiles/rails_6.gemfile
16
17
  - gemfiles/rails_5.gemfile
17
18
  - gemfiles/rails_4.gemfile
18
19
  - gemfiles/rails_3.gemfile
@@ -20,6 +21,7 @@ gemfile:
20
21
  rvm:
21
22
  - 2.4.6
22
23
  - 2.3.8
24
+ - 2.5.7
23
25
  - ruby-head
24
26
 
25
27
  matrix:
@@ -27,7 +29,15 @@ matrix:
27
29
  allow_failures:
28
30
  - rvm: ruby-head
29
31
  exclude:
32
+ - gemfile: gemfiles/rails_6.gemfile
33
+ rvm: 2.4.6
34
+ - gemfile: gemfiles/rails_6.gemfile
35
+ rvm: 2.3.8
36
+ - gemfile: gemfiles/rails_4.gemfile
37
+ rvm: 2.5.7
30
38
  - gemfile: gemfiles/rails_4.gemfile
31
39
  rvm: 2.4.6
40
+ - gemfile: gemfiles/rails_3.gemfile
41
+ rvm: 2.5.7
32
42
  - gemfile: gemfiles/rails_3.gemfile
33
43
  rvm: 2.4.6
data/Appraisals CHANGED
@@ -13,3 +13,7 @@ end
13
13
  appraise 'rails-5' do
14
14
  gem 'rails', '~> 5.0.0'
15
15
  end
16
+
17
+ appraise 'rails-6' do
18
+ gem 'rails', '~> 6.0.0'
19
+ end
@@ -1,80 +1,161 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.12.3
4
+
5
+ * Bug fix in `SyntaxHighlightFilter` [#325](https://github.com/jch/html-pipeline/pull/325)
6
+
7
+ ## 2.12.2
8
+
9
+ * Allow unsafe option for Custom Renderer of `MarkdownFilter` [#322](https://github.com/jch/html-pipeline/pull/322)
10
+ * Test with minitest-focus
11
+
12
+ ## 2.12.1
13
+
14
+ * Allow Custom Renderer for `MarkdownFilter` [#318](https://github.com/jch/html-pipeline/pull/318)
15
+ * Test against more Rails versions
16
+
17
+ ## 2.12.0
18
+
19
+ * Team mention filter [#314](https://github.com/jch/html-pipeline/pull/314)
20
+
21
+ ## 2.11.1
22
+
23
+ * Avoid YARD warning: Unknown tag @mention [#309](https://github.com/jch/html-pipeline/pull/309)
24
+ * Freeze string literals in Ruby 2.3 and beyond [#313](https://github.com/jch/html-pipeline/pull/313)
25
+
26
+ ## 2.11.0
27
+
28
+ * Test against Ruby 2.4 [#310](https://github.com/jch/html-pipeline/pull/310)
29
+ * CamoFilter: use String#unpack to hexencode URLs [#256](https://github.com/jch/html-pipeline/pull/256)
30
+
31
+ ## 2.10.0
32
+
33
+ * Add XMPP URI [#307](https://github.com/jch/html-pipeline/pull/307)
34
+ * Stop testing against Ruby 2.2
35
+
36
+ ## 2.9.2
37
+
38
+ * Whitelist various inline semantic/formatting tags [#306](https://github.com/jch/html-pipeline/pull/306)
39
+
40
+ ## 2.9.1
41
+
42
+ * Render irc and ircs URLs [#191](https://github.com/jch/html-pipeline/pull/191)
43
+
44
+ ## 2.9.0
45
+
46
+ * Fix one more missing freeze [#300](https://github.com/jch/html-pipeline/pull/300)
47
+ * Adds `UNSAFE` option to CommonMarker usage where needed [#304](https://github.com/jch/html-pipeline/pull/304)
48
+
49
+ ## 2.8.4
50
+
51
+ * Freeze all elements in HTML::Pipeline::SanitizationFilter [#299](https://github.com/jch/html-pipeline/pull/299)
52
+
53
+ ## 2.8.3
54
+
55
+ * Whitelist some accessibility properties [#298](https://github.com/jch/html-pipeline/pull/298)
56
+
57
+ ## 2.8.2
58
+
59
+ * Update ruby-sanitize (fixes CVE-2018-3740)
60
+
61
+ ## 2.8.1
62
+
63
+ * Fix XSS vulnerability on table of content generation [#296](https://github.com/jch/html-pipeline/pull/296)
64
+
65
+ ## 2.8.0
66
+
67
+ * Ensure `<pre>` nodes are not removed after syntax highlighting [#295](https://github.com/jch/html-pipeline/pull/295)
68
+
69
+ ## 2.7.2
70
+
71
+ * Apply mention filter & emoji filter on node text [#290](https://github.com/jch/html-pipeline/pull/290)
72
+ * Disable processing @mentions in `<script>` tag [#292](https://github.com/jch/html-pipeline/pull/292)
73
+ * Update dependencies [#291](https://github.com/jch/html-pipeline/pull/291)
74
+
75
+ ## 2.7.1
76
+
77
+ * Output underlying load error when wrapping [#284](https://github.com/jch/html-pipeline/pull/284)
78
+
79
+ ## 2.7.0
80
+
81
+ * Let users set the common marker extensions [#279](https://github.com/jch/html-pipeline/pull/279)
82
+
3
83
  ## 2.6.0
4
- * Switch from github-markdown to CommonMark #274
5
- * Fixed a few warnings
84
+
85
+ * Switch from github-markdown to CommonMark [#274](https://github.com/jch/html-pipeline/pull/274)
86
+ * Fixed a few warnings
6
87
 
7
88
  ## 2.5.0
8
89
 
9
- * Ruby 2.4 support. Backwards compatible, but bumped minor version so projects can choose to lock at older version [#268](https://github.com/jch/html-pipeline/pull/268)
90
+ * Ruby 2.4 support. Backwards compatible, but bumped minor version so projects can choose to lock at older version [#268](https://github.com/jch/html-pipeline/pull/268)
10
91
 
11
92
  ## 2.4.2
12
93
 
13
- * Make EmojiFilter generated img tag HTML attributes configurable [#258](https://github.com/jch/html-pipeline/pull/258)
94
+ * Make EmojiFilter generated img tag HTML attributes configurable [#258](https://github.com/jch/html-pipeline/pull/258)
14
95
 
15
96
  ## 2.4.1
16
97
 
17
- * Regression in EmailReplyPipeline: unfiltered content is being omitted [#253](https://github.com/jch/html-pipeline/pull/253)
98
+ * Regression in EmailReplyPipeline: unfiltered content is being omitted [#253](https://github.com/jch/html-pipeline/pull/253)
18
99
 
19
100
  ## 2.4.0
20
101
 
21
- * Optionally filter email addresses [#247](https://github.com/jch/html-pipeline/pull/247)
102
+ * Optionally filter email addresses [#247](https://github.com/jch/html-pipeline/pull/247)
22
103
 
23
104
  ## 2.3.0
24
105
 
25
- * Add option to pass in an anchor icon, instead of using octicons [#244](https://github.com/jch/html-pipeline/pull/244)
106
+ * Add option to pass in an anchor icon, instead of using octicons [#244](https://github.com/jch/html-pipeline/pull/244)
26
107
 
27
108
  ## 2.2.4
28
109
 
29
- * Use entire namespace so MissingDependencyError constant is resolved [#243](https://github.com/jch/html-pipeline/pull/243)
110
+ * Use entire namespace so MissingDependencyError constant is resolved [#243](https://github.com/jch/html-pipeline/pull/243)
30
111
 
31
112
  ## 2.2.3
32
113
 
33
- * raise MissingDependencyError instead of aborting on missing dependency [#241](https://github.com/jch/html-pipeline/pull/241)
34
- * Fix typo [#239](https://github.com/jch/html-pipeline/pull/239)
35
- * Test against Ruby 2.3.0 on Travis CI [#238](https://github.com/jch/html-pipeline/pull/238)
36
- * use travis containers [#237](https://github.com/jch/html-pipeline/pull/237)
114
+ * raise MissingDependencyError instead of aborting on missing dependency [#241](https://github.com/jch/html-pipeline/pull/241)
115
+ * Fix typo [#239](https://github.com/jch/html-pipeline/pull/239)
116
+ * Test against Ruby 2.3.0 on Travis CI [#238](https://github.com/jch/html-pipeline/pull/238)
117
+ * use travis containers [#237](https://github.com/jch/html-pipeline/pull/237)
37
118
 
38
119
  ## 2.2.2
39
120
 
40
- * Fix for calling mention_link_filter with only one argument [#230](https://github.com/jch/html-pipeline/pull/230)
41
- * Add html-pipeline-linkify_github to 3rd Party Extensions in README [#228](https://github.com/jch/html-pipeline/pull/228)
121
+ * Fix for calling mention_link_filter with only one argument [#230](https://github.com/jch/html-pipeline/pull/230)
122
+ * Add html-pipeline-linkify_github to 3rd Party Extensions in README [#228](https://github.com/jch/html-pipeline/pull/228)
42
123
 
43
124
  ## 2.2.1
44
125
 
45
- * Soften Nokogiri dependency to versions ">= 1.4" [#208](https://github.com/jch/html-pipeline/pull/208)
126
+ * Soften Nokogiri dependency to versions ">= 1.4" [#208](https://github.com/jch/html-pipeline/pull/208)
46
127
 
47
128
  ## 2.2.0
48
129
 
49
- * Only allow cite attribute on blockquote and restrict schemes [#223](https://github.com/jch/html-pipeline/pull/223)
130
+ * Only allow cite attribute on blockquote and restrict schemes [#223](https://github.com/jch/html-pipeline/pull/223)
50
131
 
51
132
  ## 2.1.0
52
133
 
53
- * Whitelist schemes for longdesc [#221](https://github.com/jch/html-pipeline/pull/221)
54
- * Extract emoji image tag generation to own method [#195](https://github.com/jch/html-pipeline/pull/195)
55
- * Update README.md [#211](https://github.com/jch/html-pipeline/pull/211)
56
- * Add ImageFilter for image url to img tag conversion [#207](https://github.com/jch/html-pipeline/pull/207)
134
+ * Whitelist schemes for longdesc [#221](https://github.com/jch/html-pipeline/pull/221)
135
+ * Extract emoji image tag generation to own method [#195](https://github.com/jch/html-pipeline/pull/195)
136
+ * Update README.md [#211](https://github.com/jch/html-pipeline/pull/211)
137
+ * Add ImageFilter for image url to img tag conversion [#207](https://github.com/jch/html-pipeline/pull/207)
57
138
 
58
139
  ## 2.0
59
140
 
60
141
  **New**
61
142
 
62
- * Implement new EmojiFilter context option: ignored_ancestor_tags to accept more ignored tags. [#170](https://github.com/jch/html-pipeline/pull/170) @JuanitoFatas
63
- * Add GitHub flavor Markdown Task List extension [#162](https://github.com/jch/html-pipeline/pull/162) @simeonwillbanks
64
- * @mention allow for custom regex to identify usernames. [#157](https://github.com/jch/html-pipeline/pull/157) @brittballard
65
- * EmojiFilter now requires gemoji ~> 2. [#159](https://github.com/jch/html-pipeline/pull/159) @jch
143
+ * Implement new EmojiFilter context option: ignored_ancestor_tags to accept more ignored tags. [#170](https://github.com/jch/html-pipeline/pull/170) @JuanitoFatas
144
+ * Add GitHub flavor Markdown Task List extension [#162](https://github.com/jch/html-pipeline/pull/162) @simeonwillbanks
145
+ * @mention allow for custom regex to identify usernames. [#157](https://github.com/jch/html-pipeline/pull/157) @brittballard
146
+ * EmojiFilter now requires gemoji ~> 2. [#159](https://github.com/jch/html-pipeline/pull/159) @jch
66
147
 
67
148
  **Changes**
68
149
 
69
- * Restrict nokogiri to >= 1.4, <= 1.6.5 [#176](https://github.com/jch/html-pipeline/pull/176) @simeonwillbanks
70
- * MentionFilter#link_to_mentioned_user: Replace String introspection with Regexp match [#172](https://github.com/jch/html-pipeline/pull/172) @simeonwillbanks
71
- * Whitelist summary and details element. [#171](https://github.com/jch/html-pipeline/pull/171) @JuanitoFatas
72
- * Support ~login for MentionFilter. [#167](https://github.com/jch/html-pipeline/pull/167) @JuanitoFatas
73
- * Revert "Search for text nodes on DocumentFragments without root tags" [#158](https://github.com/jch/html-pipeline/pull/158) @jch
74
- * Drop support for ruby ree, 1.9.2, 1.9.3 [#156](https://github.com/jch/html-pipeline/pull/156) @jch
75
- * Skip EmojiFilter in `<tt>` tags [#147](https://github.com/jch/html-pipeline/pull/147) @moskvax
76
- * Use Linguist lexers [#153](https://github.com/jch/html-pipeline/pull/153) @pchaigno
77
- * Constrain Active Support >= 2, < 5 [#180](https://github.com/jch/html-pipeline/pull/180) @jch
150
+ * Restrict nokogiri to >= 1.4, <= 1.6.5 [#176](https://github.com/jch/html-pipeline/pull/176) @simeonwillbanks
151
+ * MentionFilter#link_to_mentioned_user: Replace String introspection with Regexp match [#172](https://github.com/jch/html-pipeline/pull/172) @simeonwillbanks
152
+ * Whitelist summary and details element. [#171](https://github.com/jch/html-pipeline/pull/171) @JuanitoFatas
153
+ * Support ~login for MentionFilter. [#167](https://github.com/jch/html-pipeline/pull/167) @JuanitoFatas
154
+ * Revert "Search for text nodes on DocumentFragments without root tags" [#158](https://github.com/jch/html-pipeline/pull/158) @jch
155
+ * Drop support for ruby ree, 1.9.2, 1.9.3 [#156](https://github.com/jch/html-pipeline/pull/156) @jch
156
+ * Skip EmojiFilter in `<tt>` tags [#147](https://github.com/jch/html-pipeline/pull/147) @moskvax
157
+ * Use Linguist lexers [#153](https://github.com/jch/html-pipeline/pull/153) @pchaigno
158
+ * Constrain Active Support >= 2, < 5 [#180](https://github.com/jch/html-pipeline/pull/180) @jch
78
159
 
79
160
  ## 1.11.0
80
161
 
data/Gemfile CHANGED
@@ -22,4 +22,5 @@ group :test do
22
22
 
23
23
  gem 'escape_utils', '~> 1.0', require: false
24
24
  gem 'rouge', '~> 3.1', require: false
25
+ gem 'minitest-focus', '~> 1.1'
25
26
  end
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # HTML::Pipeline [![Build Status](https://travis-ci.org/jch/html-pipeline.svg?branch=master)](https://travis-ci.org/jch/html-pipeline)
2
2
 
3
- GitHub HTML processing filters and utilities. This module includes a small
3
+ HTML processing filters and utilities. This module includes a small
4
4
  framework for defining DOM based content filters and applying them to user
5
- provided content. Read an introduction about this project in
6
- [this blog post](https://github.com/blog/1311-html-pipeline-chainable-content-filters).
5
+ provided content.
6
+
7
+ [This project was started at GitHub](https://github.com/blog/1311-html-pipeline-chainable-content-filters). While GitHub still uses a similar design and pattern for rendering content, this gem should be considered standalone and independent from GitHub.
7
8
 
8
9
  - [Installation](#installation)
9
10
  - [Usage](#usage)
@@ -82,7 +83,7 @@ Prints:
82
83
  </code></pre>
83
84
  ```
84
85
 
85
- To generate CSS for HTML formatted code, use the [Rouge CSS Theme](https://github.com/jneen/rouge#css-theme-options) `#css` method. `rouge` is a dependency of the `SyntaxHighlightFilter`.
86
+ To generate CSS for HTML formatted code, use the [Rouge CSS Theme](https://github.com/rouge-ruby/rouge#css-options) `#css` method. `rouge` is a dependency of the `SyntaxHighlightFilter`.
86
87
 
87
88
  Some filters take an optional **context** and/or **result** hash. These are
88
89
  used to pass around arguments and metadata between filters in a pipeline. For
@@ -153,6 +154,7 @@ EmojiPipeline = Pipeline.new [
153
154
  ## Filters
154
155
 
155
156
  * `MentionFilter` - replace `@user` mentions with links
157
+ * `TeamMentionFilter` - replace `@org/team` mentions with links
156
158
  * `AbsoluteSourceFilter` - replace relative image urls with fully qualified versions
157
159
  * `AutolinkFilter` - auto_linking urls in HTML
158
160
  * `CamoFilter` - replace http image urls with [camo-fied](https://github.com/atmos/camo) https versions
@@ -353,6 +355,8 @@ Thanks to all of [these contributors](https://github.com/jch/html-pipeline/graph
353
355
 
354
356
  Project is a member of the [OSS Manifesto](http://ossmanifesto.org/).
355
357
 
358
+ The current maintainer is @gjtorikian
359
+
356
360
  ### Releasing A New Version
357
361
 
358
362
  This section is for gem maintainers to cut a new version of the gem.
@@ -38,6 +38,7 @@ module HTML
38
38
  autoload :ImageMaxWidthFilter, 'html/pipeline/image_max_width_filter'
39
39
  autoload :MarkdownFilter, 'html/pipeline/markdown_filter'
40
40
  autoload :MentionFilter, 'html/pipeline/@mention_filter'
41
+ autoload :TeamMentionFilter, 'html/pipeline/@team_mention_filter'
41
42
  autoload :PlainTextInputFilter, 'html/pipeline/plain_text_input_filter'
42
43
  autoload :SanitizationFilter, 'html/pipeline/sanitization_filter'
43
44
  autoload :SyntaxHighlightFilter, 'html/pipeline/syntax_highlight_filter'
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'set'
4
+
5
+ module HTML
6
+ class Pipeline
7
+ # HTML filter that replaces @org/team mentions with links. Mentions within
8
+ # <pre>, <code>, <a>, <style>, and <script> elements are ignored.
9
+ #
10
+ # Context options:
11
+ # :base_url - Used to construct links to team profile pages for each
12
+ # mention.
13
+ # :team_pattern - Used to provide a custom regular expression to
14
+ # identify team names
15
+ #
16
+ class TeamMentionFilter < Filter
17
+ # Public: Find @org/team mentions in text. See
18
+ # TeamMentionFilter#team_mention_link_filter.
19
+ #
20
+ # TeamMentionFilter.mentioned_teams_in(text) do |match, org, team|
21
+ # "<a href=...>#{team}</a>"
22
+ # end
23
+ #
24
+ # text - String text to search.
25
+ #
26
+ # Yields the String match, org name, and team name. The yield's
27
+ # return replaces the match in the original text.
28
+ #
29
+ # Returns a String replaced with the return of the block.
30
+ def self.mentioned_teams_in(text, team_pattern = TeamPattern)
31
+ text.gsub team_pattern do |match|
32
+ org = $1
33
+ team = $2
34
+ yield match, org, team
35
+ end
36
+ end
37
+
38
+ # Default pattern used to extract team names from text. The value can be
39
+ # overridden by providing the team_pattern variable in the context. To
40
+ # properly link the mention, should be in the format of /@(1)\/(2)/.
41
+ TeamPattern = /
42
+ (?<=^|\W) # beginning of string or non-word char
43
+ @([a-z0-9][a-z0-9-]*) # @organization
44
+ \/ # dividing slash
45
+ ([a-z0-9][a-z0-9\-_]*) # team
46
+ \b
47
+ /ix
48
+
49
+ # Don't look for mentions in text nodes that are children of these elements
50
+ IGNORE_PARENTS = %w[pre code a style script].to_set
51
+
52
+ def call
53
+ result[:mentioned_teams] ||= []
54
+
55
+ doc.search('.//text()').each do |node|
56
+ content = node.to_html
57
+ next unless content.include?('@')
58
+ next if has_ancestor?(node, IGNORE_PARENTS)
59
+ html = mention_link_filter(content, base_url, team_pattern)
60
+ next if html == content
61
+ node.replace(html)
62
+ end
63
+ doc
64
+ end
65
+
66
+ def team_pattern
67
+ context[:team_pattern] || TeamPattern
68
+ end
69
+
70
+ # Replace @org/team mentions in text with links to the mentioned team's
71
+ # page.
72
+ #
73
+ # text - String text to replace @mention team names in.
74
+ # base_url - The base URL used to construct team page URLs.
75
+ # team_pattern - Regular expression used to identify teams in text
76
+ #
77
+ # Returns a string with @team mentions replaced with links. All links have a
78
+ # 'team-mention' class name attached for styling.
79
+ def mention_link_filter(text, _base_url = '/', team_pattern = TeamPattern)
80
+ self.class.mentioned_teams_in(text, team_pattern) do |match, org, team|
81
+ link = link_to_mentioned_team(org, team)
82
+
83
+ link ? match.sub("@#{org}/#{team}", link) : match
84
+ end
85
+ end
86
+
87
+ def link_to_mentioned_team(org, team)
88
+ result[:mentioned_teams] |= [team]
89
+
90
+ url = base_url.dup
91
+ url << '/' unless url =~ /[\/~]\z/
92
+
93
+ "<a href='#{url << org}/#{team}' class='team-mention'>" \
94
+ "@#{org}/#{team}" \
95
+ '</a>'
96
+ end
97
+ end
98
+ end
99
+ end
@@ -11,10 +11,12 @@ module HTML
11
11
  # Context options:
12
12
  # :gfm => false Disable GFM line-end processing
13
13
  # :commonmarker_extensions => [ :table, :strikethrough,
14
- # :tagfilter, :autolink ] Common marker extensions to include
14
+ # :tagfilter, :autolink ] Commonmarker extensions to include
15
15
  #
16
16
  # This filter does not write any additional information to the context hash.
17
17
  class MarkdownFilter < TextFilter
18
+ DEFAULT_COMMONMARKER_EXTENSIONS = %i[table strikethrough tagfilter autolink].freeze
19
+
18
20
  def initialize(text, context = nil, result = nil)
19
21
  super text, context, result
20
22
  @text = @text.delete "\r"
@@ -23,14 +25,29 @@ module HTML
23
25
  # Convert Markdown to HTML using the best available implementation
24
26
  # and convert into a DocumentFragment.
25
27
  def call
26
- options = [:GITHUB_PRE_LANG]
27
- options << :HARDBREAKS if context[:gfm] != false
28
- options << :UNSAFE if context[:unsafe]
29
28
  extensions = context.fetch(
30
29
  :commonmarker_extensions,
31
- %i[table strikethrough tagfilter autolink]
30
+ DEFAULT_COMMONMARKER_EXTENSIONS
32
31
  )
33
- html = CommonMarker.render_html(@text, options, extensions)
32
+ html = if (renderer = context[:commonmarker_renderer])
33
+ unless renderer < CommonMarker::HtmlRenderer
34
+ raise ArgumentError, "`commonmark_renderer` must be derived from `CommonMarker::HtmlRenderer`"
35
+ end
36
+ parse_options = :DEFAULT
37
+ parse_options = [:UNSAFE] if context[:unsafe]
38
+
39
+ render_options = [:GITHUB_PRE_LANG]
40
+ render_options << :HARDBREAKS if context[:gfm] != false
41
+ render_options = [:UNSAFE] if context[:unsafe]
42
+
43
+ doc = CommonMarker.render_doc(@text, parse_options, extensions)
44
+ renderer.new(options: render_options, extensions: extensions).render(doc)
45
+ else
46
+ options = [:GITHUB_PRE_LANG]
47
+ options << :HARDBREAKS if context[:gfm] != false
48
+ options << :UNSAFE if context[:unsafe]
49
+ CommonMarker.render_html(@text, options, extensions)
50
+ end
34
51
  html.rstrip!
35
52
  html
36
53
  end
@@ -69,7 +69,7 @@ module HTML
69
69
  maxlength media method
70
70
  multiple name nohref noshade
71
71
  nowrap open prompt readonly rel rev
72
- rows rowspan rules scope
72
+ role rows rowspan rules scope
73
73
  selected shape size span
74
74
  start summary tabindex target
75
75
  title type usemap valign value
@@ -4,8 +4,15 @@ HTML::Pipeline.require_dependency('rouge', 'SyntaxHighlightFilter')
4
4
 
5
5
  module HTML
6
6
  class Pipeline
7
- # HTML Filter that syntax highlights code blocks wrapped
8
- # in <pre lang="...">.
7
+ # HTML Filter that syntax highlights text inside code blocks.
8
+ #
9
+ # Context options:
10
+ #
11
+ # :highlight => String represents the language to pick lexer. Defaults to empty string.
12
+ # :scope => String represents the class attribute adds to pre element after.
13
+ # Defaults to "highlight highlight-css" if highlights a css code block.
14
+ #
15
+ # This filter does not write any additional information to the context hash.
9
16
  class SyntaxHighlightFilter < Filter
10
17
  def initialize(*args)
11
18
  super(*args)
@@ -17,23 +24,20 @@ module HTML
17
24
  default = context[:highlight] && context[:highlight].to_s
18
25
  next unless lang = node['lang'] || default
19
26
  next unless lexer = lexer_for(lang)
20
- text = node.inner_text
21
27
 
22
- html = highlight_with_timeout_handling(text, lang)
28
+ text = node.inner_text
29
+ html = highlight_with_timeout_handling(text, lexer)
23
30
  next if html.nil?
24
31
 
25
32
  node.inner_html = html
26
- klass = node['class']
27
- scope = context[:scope] || "highlight-#{lang}"
28
- klass = [klass, scope].compact.join ' '
29
-
30
- node['class'] = klass
33
+ scope = context.fetch(:scope) { 'highlight' }
34
+ node['class'] = "#{scope} #{scope}-#{lang}"
31
35
  end
32
36
  doc
33
37
  end
34
38
 
35
- def highlight_with_timeout_handling(text, lang)
36
- Rouge.highlight(text, lang, @formatter)
39
+ def highlight_with_timeout_handling(text, lexer)
40
+ Rouge.highlight(text, lexer, @formatter)
37
41
  rescue Timeout::Error => _
38
42
  nil
39
43
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module HTML
4
4
  class Pipeline
5
- VERSION = '2.11.1'.freeze
5
+ VERSION = '2.13.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.1
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-07-18 00:00:00.000000000 Z
13
+ date: 2020-05-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -49,6 +49,7 @@ executables: []
49
49
  extensions: []
50
50
  extra_rdoc_files: []
51
51
  files:
52
+ - ".github/FUNDING.yml"
52
53
  - ".gitignore"
53
54
  - ".travis.yml"
54
55
  - Appraisals
@@ -62,6 +63,7 @@ files:
62
63
  - html-pipeline.gemspec
63
64
  - lib/html/pipeline.rb
64
65
  - lib/html/pipeline/@mention_filter.rb
66
+ - lib/html/pipeline/@team_mention_filter.rb
65
67
  - lib/html/pipeline/absolute_source_filter.rb
66
68
  - lib/html/pipeline/autolink_filter.rb
67
69
  - lib/html/pipeline/body_content.rb
@@ -105,8 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
107
  - !ruby/object:Gem::Version
106
108
  version: '0'
107
109
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.7.6
110
+ rubygems_version: 3.1.2
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: Helpers for processing content through a chain of filters