yatoc 0.2.1 → 0.2.2

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: d2166264952987dfcd34e23217e9d9184438822109366478cd888be296ac63d3
4
- data.tar.gz: 6adcef0d31574c4e833c9bc5780ae3ca15e45dbf88e73385632e838d5efbdd33
3
+ metadata.gz: 061ba88c77e2543b861955d8e23112aa08fdb3091ca376e53dea5e9e628b9c9d
4
+ data.tar.gz: 1cd7cea727e58d66cc28245d1a7c332a0bcf6e8aa5e18e9093943ae31fe652f3
5
5
  SHA512:
6
- metadata.gz: ef0a83971d92e394880af82b6d32f87ad05b5becaa44e52b73febd1dce22d6c47758b03978fd55af5b96098a0d4c0a082a643c37ed979a9b3d625e7ee9648bb9
7
- data.tar.gz: f85eb87148e2407f7db9b7a7711c5f8c327c0ed849543a715490d7b1db80c698cad5cb5d9b156721cad10fbf06c56fea2fb3d60ea416383bb270c35c6a9bc048
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
- @to_html = html.scan(/<h\d+/).length > min_sections ? gen_toc(html) : html
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
- a = scan_headings html
28
- puts ('a: ' + a.inspect).debug if @debug
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
- toc = make_linkable(raw_html)
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.1
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: 2018-12-19 00:00:00.000000000 Z
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