html-pipeline 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d66ab39f5d7421758fc4599939bdbb364a50b3da
4
- data.tar.gz: 7f0ff92ba9e248534ce6bf8579d86e1b965f2901
3
+ metadata.gz: a78d7a993503d1652b0143b5c5cc5314251a1b1e
4
+ data.tar.gz: 1d5e8f1286c4dbb564b42824d8b950f296a18652
5
5
  SHA512:
6
- metadata.gz: 6f26ca78fe3a9549c5023601919593f0f3265bab16865efac85cfe187ec2588f217f1c4e5d92e10fcef4d8417fa64eb20dc256945a7ed7cf1d1931706f790bc1
7
- data.tar.gz: fbd6e5c3ce3174f467515e8ce8bdb685ef2c56878920d2c600ed7b5bf38a3b6bcfbec2cb62cc07a1e8c6ece21b223f20addccfce65100089d59b8a972d609b06
6
+ metadata.gz: a41f0686fe77ab68a026926840865f5ac81a3065657919724a4df3c6fe5f906125dbcd5e8b91949d8d4a666954566272cff512de81cacf5998cb61ed5970b3d1
7
+ data.tar.gz: 66e61ab2aba3d69f442fd537477c1350d7d1c6b2eb65aa6814c38276918162b8bb120b3a0e5c08777d08d9d23a2838734651a71600c339fbb161c0c4618e2534
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.10.0
4
+
5
+ * Anchor TOCFilter with id's instead of name's #140 bkeepers
6
+ * Add `details` to sanitization whitelist #139 tansaku
7
+ * Fix README spelling #137 Razer6
8
+ * Remove ActiveSupport `try` dependency #132 simeonwillbanks
9
+
3
10
  ## 1.9.0
4
11
 
5
12
  * Generalize https filter with :base_url #124 #131 rymohr
data/README.md CHANGED
@@ -88,8 +88,8 @@ To generate CSS for HTML formatted code, use the [pygments.rb](https://github.co
88
88
 
89
89
  Some filters take an optional **context** and/or **result** hash. These are
90
90
  used to pass around arguments and metadata between filters in a pipeline. For
91
- example, if you want don't want to use GitHub formatted Markdown, you can
92
- pass an option in the context hash:
91
+ example, if you don't want to use GitHub formatted Markdown, you can pass an
92
+ option in the context hash:
93
93
 
94
94
  ```ruby
95
95
  filter = HTML::Pipeline::MarkdownFilter.new("Hi **world**!", :gfm => false)
@@ -57,7 +57,7 @@ module HTML
57
57
  'border', 'cellpadding', 'cellspacing', 'char',
58
58
  'charoff', 'charset', 'checked', 'cite',
59
59
  'clear', 'cols', 'colspan', 'color',
60
- 'compact', 'coords', 'datetime', 'dir',
60
+ 'compact', 'coords', 'datetime', 'details', 'dir',
61
61
  'disabled', 'enctype', 'for', 'frame',
62
62
  'headers', 'height', 'hreflang',
63
63
  'hspace', 'ismap', 'label', 'lang',
@@ -1,6 +1,6 @@
1
1
  module HTML
2
2
  class Pipeline
3
- # HTML filter that adds a 'name' attribute to all headers
3
+ # HTML filter that adds an 'id' attribute to all headers
4
4
  # in a document, so they can be accessed from a table of contents.
5
5
  #
6
6
  # Generates the Table of Contents, with links to each header.
@@ -21,7 +21,7 @@ module HTML
21
21
  # result[:toc]
22
22
  # # => "<ul class=\"section-nav\">\n<li><a href=\"#ice-cube\">...</li><ul>"
23
23
  # result[:output].to_s
24
- # # => "<h1>\n<a name=\"ice-cube\" class=\"anchor\" href=\"#ice-cube\">..."
24
+ # # => "<h1>\n<a id=\"ice-cube\" class=\"anchor\" href=\"#ice-cube\">..."
25
25
  class TableOfContentsFilter < Filter
26
26
  PUNCTUATION_REGEXP = RUBY_VERSION > "1.9" ? /[^\p{Word}\- ]/u : /[^\w\- ]/
27
27
 
@@ -31,15 +31,15 @@ module HTML
31
31
  headers = Hash.new(0)
32
32
  doc.css('h1, h2, h3, h4, h5, h6').each do |node|
33
33
  text = node.text
34
- name = text.downcase
35
- name.gsub!(PUNCTUATION_REGEXP, '') # remove punctuation
36
- name.gsub!(' ', '-') # replace spaces with dash
34
+ id = text.downcase
35
+ id.gsub!(PUNCTUATION_REGEXP, '') # remove punctuation
36
+ id.gsub!(' ', '-') # replace spaces with dash
37
37
 
38
- uniq = (headers[name] > 0) ? "-#{headers[name]}" : ''
39
- headers[name] += 1
38
+ uniq = (headers[id] > 0) ? "-#{headers[id]}" : ''
39
+ headers[id] += 1
40
40
  if header_content = node.children.first
41
- result[:toc] << %Q{<li><a href="##{name}#{uniq}">#{text}</a></li>\n}
42
- header_content.add_previous_sibling(%Q{<a name="#{name}#{uniq}" class="anchor" href="##{name}#{uniq}"><span class="octicon octicon-link"></span></a>})
41
+ result[:toc] << %Q{<li><a href="##{id}#{uniq}">#{text}</a></li>\n}
42
+ header_content.add_previous_sibling(%Q{<a id="#{id}#{uniq}" class="anchor" href="##{id}#{uniq}" aria-hidden="true"><span class="octicon octicon-link"></span></a>})
43
43
  end
44
44
  end
45
45
  result[:toc] = %Q{<ul class="section-nav">\n#{result[:toc]}</ul>} unless result[:toc].empty?
@@ -1,5 +1,5 @@
1
1
  module HTML
2
2
  class Pipeline
3
- VERSION = "1.9.0"
3
+ VERSION = "1.10.0"
4
4
  end
5
5
  end
@@ -17,7 +17,7 @@ class HTML::Pipeline::TableOfContentsFilterTest < Minitest::Test
17
17
 
18
18
  def test_anchors_are_added_properly
19
19
  orig = %(<h1>Ice cube</h1><p>Will swarm on any motherfucker in a blue uniform</p>)
20
- assert_includes TocFilter.call(orig).to_s, '<a name='
20
+ assert_includes TocFilter.call(orig).to_s, '<a id='
21
21
  end
22
22
 
23
23
  def test_toc_list_added_properly
@@ -35,6 +35,12 @@ class HTML::Pipeline::TableOfContentsFilterTest < Minitest::Test
35
35
  assert_includes result, '"mc-ren"'
36
36
  end
37
37
 
38
+ def test_anchors_have_aria_hidden
39
+ orig = "<h1>Straight Outta Compton</h1>"
40
+ result = TocFilter.call(orig).to_s
41
+ assert_includes result, 'aria-hidden="true"'
42
+ end
43
+
38
44
  def test_toc_hrefs_have_sane_values
39
45
  @orig = %(<h1>Dr Dre</h1><h1>Ice Cube</h1><h1>Eazy-E</h1><h1>MC Ren</h1>)
40
46
  assert_includes toc, '"#dr-dre"'
@@ -101,9 +107,9 @@ class HTML::Pipeline::TableOfContentsFilterTest < Minitest::Test
101
107
 
102
108
  rendered_h1s = TocFilter.call(orig).search('h1').map(&:to_s)
103
109
 
104
- assert_equal "<h1>\n<a name=\"%E6%97%A5%E6%9C%AC%E8%AA%9E\" class=\"anchor\" href=\"#%E6%97%A5%E6%9C%AC%E8%AA%9E\"><span class=\"octicon octicon-link\"></span></a>日本語</h1>",
110
+ assert_equal "<h1>\n<a id=\"日本語\" class=\"anchor\" href=\"#%E6%97%A5%E6%9C%AC%E8%AA%9E\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"></span></a>日本語</h1>",
105
111
  rendered_h1s[0]
106
- assert_equal "<h1>\n<a name=\"%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9\" class=\"anchor\" href=\"#%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9\"><span class=\"octicon octicon-link\"></span></a>Русский</h1>",
112
+ assert_equal "<h1>\n<a id=\"Русский\" class=\"anchor\" href=\"#%D0%A0%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"></span></a>Русский</h1>",
107
113
  rendered_h1s[1]
108
114
  end
109
115
 
data/test/test_helper.rb CHANGED
@@ -3,7 +3,6 @@ require 'html/pipeline'
3
3
  require 'minitest/autorun'
4
4
 
5
5
  require 'active_support/core_ext/string'
6
- require 'active_support/core_ext/object/try'
7
6
 
8
7
  module TestHelpers
9
8
  # Asserts that two html fragments are equivalent. Attribute order
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: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-07 00:00:00.000000000 Z
12
+ date: 2014-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri