booklab-toc 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/booklab/toc/format/markdown.rb +10 -1
- data/lib/booklab/toc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9144dd74ada6b36a467e13a30edce33bbd753e61739a664a8f1eddd01e41a70f
|
4
|
+
data.tar.gz: e0d4c36ed1151004d450a96b68bb571157914121d1fd8d15741a344024e848c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd62e4d3ae1ac1d1e24e8d0cb6a91ec94a55a2fe3f30f3af5d33f53084c425c4a11238ebcc370e4a2abcf3ec3b329fdfbacdb1084bd00247344125b961bd43ed
|
7
|
+
data.tar.gz: 43dd75b2ae34c7985de7621797dc8edd4b23aa66c350f57a7dd803892bc38f23efb26c4ce15d1379db7ef78f859596f12c295cd71b034932b2b54a2dc1897489
|
@@ -5,13 +5,22 @@ module BookLab
|
|
5
5
|
class << self
|
6
6
|
def load(raw)
|
7
7
|
items = []
|
8
|
+
|
9
|
+
# check indent style, 2 spaces/4 spaces/1 tab
|
10
|
+
space_size = 4
|
11
|
+
if raw.match(/^[\t]{1}[\s]?[-\*]/m)
|
12
|
+
space_size = 1
|
13
|
+
elsif raw.match(/^[\s]{2}[\s]?[-\*]/m)
|
14
|
+
space_size = 2
|
15
|
+
end
|
16
|
+
|
8
17
|
lines = raw.split("\n")
|
9
18
|
lines.each do |line|
|
10
19
|
item = { "title" => nil, "url" => nil, "depth" => 0 }
|
11
20
|
# replace * prefix to - prefix
|
12
21
|
line = line.gsub(/^([\s]+)\*/, "\\1-")
|
13
22
|
# calculate indent as depth
|
14
|
-
item["depth"] = (line.match(/^([\s]+)/).to_s.length /
|
23
|
+
item["depth"] = (line.match(/^([\s]+)/).to_s.length / space_size).round
|
15
24
|
|
16
25
|
# check line is include link
|
17
26
|
m = line.match(/\[(?<title>.+?)\]\((?<url>.+?)\)/)
|
data/lib/booklab/toc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booklab-toc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|