yatoc 0.2.1 → 0.2.2
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
- checksums.yaml.gz.sig +0 -0
- data/lib/yatoc.rb +36 -11
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 061ba88c77e2543b861955d8e23112aa08fdb3091ca376e53dea5e9e628b9c9d
|
4
|
+
data.tar.gz: 1cd7cea727e58d66cc28245d1a7c332a0bcf6e8aa5e18e9093943ae31fe652f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49486468c6d8764da0dcc6e4c9efdf586b08871b9c32166571d781fc2749b77bc46d0887fca0bee40f7a001c5f3a7873490b7961f78aa8514051b7bc2d090e9c
|
7
|
+
data.tar.gz: 2179c3faa35602c8d89a7fb716b482956e6e08134d5a1c044ef6cbf990227b971763c1eb9c8fc2d5f383d938613418362c726fa33830bc09236eed4e4fc8ace4
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/yatoc.rb
CHANGED
@@ -10,29 +10,55 @@ require 'line-tree'
|
|
10
10
|
class Yatoc
|
11
11
|
using ColouredText
|
12
12
|
|
13
|
-
attr_reader :to_html, :to_toc
|
13
|
+
attr_reader :to_html, :to_toc, :to_index
|
14
14
|
|
15
15
|
def initialize(html, min_sections: 3, numbered: true, debug: false)
|
16
16
|
|
17
17
|
@numbered, @debug = numbered, debug
|
18
18
|
|
19
|
-
|
19
|
+
if html.scan(/<h\d+/).length > min_sections then
|
20
|
+
|
21
|
+
gen_index(html)
|
22
|
+
@to_html = gen_toc(html)
|
23
|
+
|
24
|
+
|
25
|
+
else
|
26
|
+
html
|
27
|
+
end
|
20
28
|
|
21
29
|
end
|
22
30
|
|
23
|
-
private
|
24
|
-
|
25
|
-
def gen_toc(html)
|
31
|
+
private
|
26
32
|
|
27
|
-
|
28
|
-
|
33
|
+
def build_html(a)
|
34
|
+
|
35
|
+
puts ('a: ' + a.inspect).debug if @debug
|
29
36
|
|
30
37
|
a2 = make_tree(a)
|
31
38
|
puts a2.inspect.debug if @debug
|
32
|
-
raw_html = LineTree.new(a2).to_html(numbered: @numbered)
|
33
39
|
|
40
|
+
raw_html = LineTree.new(a2).to_html(numbered: @numbered)
|
34
41
|
puts ('raw_html: ' + raw_html.inspect).debug if @debug
|
35
|
-
|
42
|
+
|
43
|
+
make_linkable(raw_html)
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def gen_index(html)
|
48
|
+
|
49
|
+
a = html.split(/(?=<h2)/)
|
50
|
+
|
51
|
+
index = build_html(a)
|
52
|
+
|
53
|
+
@to_index = "<div id='index' class='index'>\n%s\n</div>\n\n" % index
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
def gen_toc(html)
|
58
|
+
|
59
|
+
a = scan_headings html
|
60
|
+
|
61
|
+
toc = build_html(a)
|
36
62
|
@to_toc = toc
|
37
63
|
|
38
64
|
pos = html =~ /<h2/
|
@@ -59,7 +85,6 @@ class Yatoc
|
|
59
85
|
anchor.text = node.text if node.text
|
60
86
|
end
|
61
87
|
|
62
|
-
|
63
88
|
node.add anchor
|
64
89
|
node.text = ''
|
65
90
|
|
@@ -102,7 +127,7 @@ class Yatoc
|
|
102
127
|
end
|
103
128
|
|
104
129
|
def scan_headings(s, n=2)
|
105
|
-
|
130
|
+
|
106
131
|
s.split(/(?=<h#{n})/).map do |x|
|
107
132
|
x.include?('<h' + (n+1).to_s) ? scan_headings(x, n+1) : x
|
108
133
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yatoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
7RVV+J+oYjvww0tYfGq6N2tECM5thrQYj3cKLzAEEPYBjoWcPA5bqRXBTNta+k+K
|
36
36
|
tc7DELyeAZoKgZBO2wAc4FQ6
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date:
|
38
|
+
date: 2019-01-16 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: line-tree
|
metadata.gz.sig
CHANGED
Binary file
|