middleman-hashicorp 0.3.14 → 0.3.15

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
  SHA1:
3
- metadata.gz: c6e17a35054d12adb10150112bfd766bb05a9323
4
- data.tar.gz: 660989c15ec9ecbba9f4fd5b6b4a28fe428bda60
3
+ metadata.gz: faa6604885b0ec377d901ba569d5e6c77af4d14f
4
+ data.tar.gz: abb5f50ffff04dffc4f39f7b94e14336af23c74b
5
5
  SHA512:
6
- metadata.gz: ad92925188ac51058bda123c4a0a325e283751239ebc6458d50dd78dfe1e9c7ce71f92706e77c918d3b23db9a7bf9f19a541a65e3d06b857e1d9245de43b1916
7
- data.tar.gz: b277f0f8232673bf60ee1a29ed9e9375eec223f52cffa2112a745c64a9328c5fe83119f3bb6d6d2b1319f334c6fc4f441307ba6a20f3ba21e6166e49fdb95cab
6
+ metadata.gz: 25f52e284323c966063293223a5852b75f5735208b5f6004bca6a3d9e43eb030e533aaf7b156cffd277648b642c6cd85f37059d65210b0f83176dc6d46bf0291
7
+ data.tar.gz: 551ed2efa0fef9310eb19d825d7410b58bdeb969ff4d2805919f505189b56f15d7f90c7d335d68717beec406a921c43e534da92c5463106b2d47b39bfa5fed84
@@ -1,5 +1,6 @@
1
1
  require "middleman-core"
2
2
  require "middleman-core/renderers/redcarpet"
3
+ require "nokogiri"
3
4
  require "active_support/core_ext/module/attribute_accessors"
4
5
 
5
6
  # Our custom Markdown parser - extends middleman's customer parser so we pick up
@@ -25,21 +26,11 @@ class Middleman::HashiCorp::RedcarpetHTML < ::Middleman::Renderers::MiddlemanRed
25
26
  # Override headers to add custom links.
26
27
  #
27
28
  def header(title, level)
28
- @headers ||= {}
29
-
30
- name = title.downcase.strip.gsub(/\W+/, '-').gsub(/\A\-/, '')
31
-
32
- i = 0
33
- permalink = name
34
- while @headers.key?(permalink) do
35
- i += 1
36
- permalink = "#{name}-#{i}"
37
- end
38
- @headers[permalink] = true
29
+ anchor = anchor_link(title)
39
30
 
40
31
  return <<-EOH.gsub(/^ {6}/, "")
41
- <h#{level} id="#{permalink}">
42
- <a name="#{permalink}" class="anchor" href="##{permalink}">&raquo;</a>
32
+ <h#{level} id="#{anchor}">
33
+ <a name="#{anchor}" class="anchor" href="##{anchor}">&raquo;</a>
43
34
  #{title}
44
35
  </h#{level}>
45
36
  EOH
@@ -52,12 +43,14 @@ class Middleman::HashiCorp::RedcarpetHTML < ::Middleman::Renderers::MiddlemanRed
52
43
  # @param [String] list_type
53
44
  #
54
45
  def list_item(text, list_type)
46
+ @anchors ||= {}
47
+
55
48
  md = text.match(/\A(?:<p>)?(<code>(.+?)<\/code>)/)
56
49
  linked = !text.match(/\A(<p>)?<a(.+?)>(.+?)<\/a>\s*?[-:]?/).nil?
57
50
 
58
51
  if !md.nil? && !linked
59
52
  container, name = md.captures
60
- anchor = anchor_for(name)
53
+ anchor = anchor_link(name)
61
54
 
62
55
  replace = %|<a name="#{anchor}" /><a href="##{anchor}">#{container}</a>|
63
56
  text.sub!(container, replace)
@@ -95,19 +88,29 @@ class Middleman::HashiCorp::RedcarpetHTML < ::Middleman::Renderers::MiddlemanRed
95
88
  private
96
89
 
97
90
  #
98
- # Remove any special characters from the anchor name.
99
- #
100
- # @example
101
- # anchor_for("this") #=> "this"
102
- # anchor_for("this is cool") #=> "this_is_cool"
103
- # anchor_for("this__is__cool!") #=> "this__is__cool_"
91
+ # Generate an anchor link from the generated raw value.
104
92
  #
105
- #
106
- # @param [String] text
107
93
  # @return [String]
108
94
  #
109
- def anchor_for(text)
110
- text.gsub(/[^[:word:]]/, "_").squeeze("_")
95
+ def anchor_link(raw)
96
+ @anchors ||= {}
97
+
98
+ name = raw
99
+ .downcase
100
+ .strip
101
+ .gsub(/<\/?[^>]*>/, '') # Strip links
102
+ .gsub(/\W+/, '-') # Whitespace to -
103
+ .gsub(/\A\-/, '') # No leading -
104
+ .squeeze('-') # Collapse --
105
+
106
+ i = 0
107
+ link = name
108
+ while @anchors.key?(link) do
109
+ i += 1
110
+ link = "#{name}-#{i}"
111
+ end
112
+ @anchors[link] = true
113
+ return link
111
114
  end
112
115
 
113
116
  #
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module HashiCorp
3
- VERSION = "0.3.14"
3
+ VERSION = "0.3.15"
4
4
  end
5
5
  end
@@ -20,7 +20,7 @@ module Middleman::HashiCorp
20
20
  </li>
21
21
  <li><a name="two" /><a href="#two"><code>two</code></a> has some <code>code</code> inside
22
22
  </li>
23
- <li><a name="three_has_and_spaces" /><a href="#three_has_and_spaces"><code>three has ^ and spaces</code></a> with text
23
+ <li><a name="three-has-and-spaces" /><a href="#three-has-and-spaces"><code>three has ^ and spaces</code></a> with text
24
24
  </li>
25
25
  <li>four
26
26
  </li>
@@ -50,7 +50,7 @@ module Middleman::HashiCorp
50
50
  </li>
51
51
  <li><p><a name="two" /><a href="#two"><code>two</code></a> has some <code>code</code> inside</p>
52
52
  </li>
53
- <li><p><a name="three_has_and_spaces" /><a href="#three_has_and_spaces"><code>three has ^ and spaces</code></a> with text</p>
53
+ <li><p><a name="three-has-and-spaces" /><a href="#three-has-and-spaces"><code>three has ^ and spaces</code></a> with text</p>
54
54
  </li>
55
55
  <li><p>four</p>
56
56
  </li>
@@ -203,6 +203,7 @@ module Middleman::HashiCorp
203
203
  # Hello World
204
204
  ## Subpath
205
205
  ## Subpath
206
+ ## `code` Subpath
206
207
  EOH
207
208
  output = <<-EOH.gsub(/^ {8}/, "")
208
209
  <h1 id="hello-world">
@@ -217,6 +218,10 @@ module Middleman::HashiCorp
217
218
  <a name="subpath-1" class="anchor" href="#subpath-1">&raquo;</a>
218
219
  Subpath
219
220
  </h2>
221
+ <h2 id="code-subpath">
222
+ <a name="code-subpath" class="anchor" href="#code-subpath">&raquo;</a>
223
+ <code>code</code> Subpath
224
+ </h2>
220
225
  EOH
221
226
 
222
227
  expect(markdown).to render_html(output)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-hashicorp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.14
4
+ version: 0.3.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-14 00:00:00.000000000 Z
11
+ date: 2017-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman