yatoc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +2 -0
- data/lib/yatoc.rb +123 -0
- metadata +111 -0
- metadata.gz.sig +2 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c2bb843d88e06a813cf01c3a47842d006a92b336f62d0c54b978cc852176d8a9
|
4
|
+
data.tar.gz: ab4b2bebe5992d53ca6006c1a7e5d48393130c7be1c5cae7d05b838cf1082a2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97966191c212ecf6a7487f35f8fdeef8d6c61e89ab0a437c10a099c8f748af29881979ebac7fc2ff0ed912f992fa5b0155693ad560eee53c2deaad780fc05a18
|
7
|
+
data.tar.gz: 319f11e91e8c7c551978dd1450e86f0a8d14c18b50035259b1864a129cbaad490ccf5d7f391ee58208b7741dc54fb220396d8e23ee9fe49e537091635d9830ec
|
checksums.yaml.gz.sig
ADDED
data.tar.gz.sig
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
��xDsjm�룺�@��ޖE��]�{�^�1����p�0�ɶ���%�Њ`{��7x��LfO�H�XZЖ(���f{��V&t������C,Gg��?i���g(��~���z�+=�E0��b��(�A�j�v�n�8�-�<��ޣ�o�/ɩ�G��g����&U{7��\�'Y�.��˶��[-Q���W�b�{(O��%N��/|��ۘZd�H C(�~��6~E�qĿ�Ǘn3<f�,0=�M2~���d��g�<��o�(n`B|��x�$���my��h��Kj'.� �d�ψ�1�;�)�A�H�o�
|
2
|
+
���G���GȈ[�9�ăr��&?f��E؉Z�~-�E�~��&
|
data/lib/yatoc.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: yatoc.rb
|
4
|
+
|
5
|
+
# description: Yet Another Table Of Contents HTML generator
|
6
|
+
|
7
|
+
|
8
|
+
require 'c32'
|
9
|
+
require 'line-tree'
|
10
|
+
|
11
|
+
|
12
|
+
class Yatoc
|
13
|
+
using ColouredText
|
14
|
+
|
15
|
+
attr_reader :to_html, :to_toc
|
16
|
+
|
17
|
+
def initialize(html, min_sections: 3, debug: false)
|
18
|
+
|
19
|
+
@debug = debug
|
20
|
+
|
21
|
+
@to_html = html.scan(/<h\d+/).length > 3 ? gen_toc(html) : html
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def gen_toc(html)
|
26
|
+
|
27
|
+
a = scan_headings html
|
28
|
+
puts a.inspect.debug if @debug
|
29
|
+
|
30
|
+
a2 = make_tree(a)
|
31
|
+
puts a2.inspect.debug if @debug
|
32
|
+
|
33
|
+
a3 = LineTree.new(a2).to_a
|
34
|
+
puts a3.inspect.debug if @debug
|
35
|
+
|
36
|
+
toc = "<ul>%s</ul>" % make_headings(a3)
|
37
|
+
@to_toc = toc
|
38
|
+
|
39
|
+
pos = html =~ /<h2/
|
40
|
+
html.insert(pos, "<div id='toc' class='toc'>\n%s\n</div>\n\n" % toc)
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def make_headings(a, indent=-1, count=nil)
|
47
|
+
|
48
|
+
items = a.map.with_index do |x, i|
|
49
|
+
|
50
|
+
if x.is_a? Array then
|
51
|
+
|
52
|
+
id, head, tail = if count then
|
53
|
+
|
54
|
+
[
|
55
|
+
count.to_s + '.' + i.to_s,
|
56
|
+
i == 1 ? "<ul>\n" : '',
|
57
|
+
i == a.length - 1 ? "</li>\n</ul></li>" : \
|
58
|
+
i == a.length - 1 ? '</ul></li>' : ''
|
59
|
+
]
|
60
|
+
|
61
|
+
else
|
62
|
+
[i+1, '', '']
|
63
|
+
end
|
64
|
+
|
65
|
+
head + make_headings(x, indent+1, id) + tail
|
66
|
+
|
67
|
+
else
|
68
|
+
|
69
|
+
#"%s%s %s" % [' ' * indent, count, x]
|
70
|
+
r = "%s<li><a href='#%s'><span>%s</span> %s</a>" % \
|
71
|
+
[' ' * indent, x.downcase.gsub(' ','-'), count, x]
|
72
|
+
i == 1 ? "<ul>" + r : r
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
items.join("\n")
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
|
83
|
+
def make_tree(a, indent=0)
|
84
|
+
|
85
|
+
if @debug then
|
86
|
+
puts 'inside make_tree'.debug
|
87
|
+
puts ('a: ' + a.inspect).debug
|
88
|
+
end
|
89
|
+
|
90
|
+
a.map.with_index do |x, i|
|
91
|
+
|
92
|
+
|
93
|
+
puts ('x: ' + x.inspect).debug if @debug
|
94
|
+
|
95
|
+
if x.is_a? Array then
|
96
|
+
|
97
|
+
puts 'before make_true()'.info if @debug
|
98
|
+
|
99
|
+
make_tree(x, indent+1)
|
100
|
+
|
101
|
+
else
|
102
|
+
|
103
|
+
next unless x =~ /<h[2-4]/
|
104
|
+
space = i == 0 ? indent-1 : indent
|
105
|
+
heading = (' ' * space) + x[/(?<=\>)[^<]+/]
|
106
|
+
puts ('heading: ' + heading.inspect).debug if @debug
|
107
|
+
heading
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end.compact.join("\n")
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
def scan_headings(s, n=2)
|
116
|
+
|
117
|
+
s.split(/(?=<h#{n})/).map do |x|
|
118
|
+
x.include?('<h' + (n+1).to_s) ? scan_headings(x, n+1) : x
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yatoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGI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dEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
|
28
|
+
BgkqhkiG9w0BAQsFAAOCAYEAGYqkk7bxuN4znd3JRkzOFX/9LwSE3rCiOck1Ej2n
|
29
|
+
6LXUds348wjG/zk1f0fdjWhKKyEfD0hAudANUadFWeGI2Shph7KDdHKOiZUICzy8
|
30
|
+
XoXLD7s0Ss3A+jZKmE0yrDks6FQNRMi/9ik0K0DD5MvuSdQtZWJhNcxyWqI1uO3R
|
31
|
+
pnN/NTF5POf0Ohg8/16LQRaJ/yeYZBI4mUxTEpEobMfovud6MbkJ0M5isZwYLrnU
|
32
|
+
3UENXnkmS3wFcYsr+451q5f+j9hJMVWaENnZtBTRFgBGUNm+69L7EK+Y0EIrxi5F
|
33
|
+
O4qsJCW7u4YyxGzm1JU4fFc0EjSLyvnj0mEzLajYZxp874kg70Sh9iCRZHUPy4Sj
|
34
|
+
snVHze5mtpNuBJgPulSAqrW0pT4CJXPrywSSWzryHrlJy94AHy3h8baXjdFc6ANo
|
35
|
+
7RVV+J+oYjvww0tYfGq6N2tECM5thrQYj3cKLzAEEPYBjoWcPA5bqRXBTNta+k+K
|
36
|
+
tc7DELyeAZoKgZBO2wAc4FQ6
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
date: 2018-12-17 00:00:00.000000000 Z
|
39
|
+
dependencies:
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: line-tree
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.7'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.7.0
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.7'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.7.0
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: c32
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.1'
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.1.2
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0.1'
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.1.2
|
80
|
+
description:
|
81
|
+
email: james@jamesrobertson.eu
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- lib/yatoc.rb
|
87
|
+
homepage: https://github.com/jrobertson/yatoc
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.7.6
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Yet Another Table Of Contents HTML generator.
|
111
|
+
test_files: []
|
metadata.gz.sig
ADDED
@@ -0,0 +1,2 @@
|
|
1
|
+
�!���C��W�$&U\����b�}�������x��h���h|�1��t��wjdz-3��nྗb����=�E�8��!^e�P�|���\,!� ���B��m&��</>'��;-��P�Z�0�gٕ��4�XN/�:�
|
2
|
+
��2�H�7(Hv�E��^B�?�Bt��U%Ҿ?��bL�wV`�0�����Ԉ���I!���y�I,S*Ւ6���q�;����3N��R_N;��e���<�U�k��c�Ji�[�R�Ԍ��a~��ɭ���9Yd��0���UXmu9���l/�k��/����Í��F��̦�M�V�ɦMG�r��,DN���)(1M�&�j�����W�x�����!���Mwp�ʔ ꆆP�^˵�~���
|