middleman-hashicorp 0.3.14 → 0.3.15
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 +4 -4
- data/lib/middleman-hashicorp/redcarpet.rb +27 -24
- data/lib/middleman-hashicorp/version.rb +1 -1
- data/spec/unit/markdown_spec.rb +7 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faa6604885b0ec377d901ba569d5e6c77af4d14f
|
4
|
+
data.tar.gz: abb5f50ffff04dffc4f39f7b94e14336af23c74b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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="#{
|
42
|
-
<a name="#{
|
32
|
+
<h#{level} id="#{anchor}">
|
33
|
+
<a name="#{anchor}" class="anchor" href="##{anchor}">»</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 =
|
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
|
-
#
|
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
|
110
|
-
|
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
|
#
|
data/spec/unit/markdown_spec.rb
CHANGED
@@ -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="
|
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="
|
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">»</a>
|
218
219
|
Subpath
|
219
220
|
</h2>
|
221
|
+
<h2 id="code-subpath">
|
222
|
+
<a name="code-subpath" class="anchor" href="#code-subpath">»</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.
|
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-
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman
|