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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: af57ed120792b883aa0bd9f3552748fa052b0629deb252619d8557531685a2c4
4
- data.tar.gz: 39700de8519309586960c3cb2a0f7fd967a2233abd309b26022bb958d5379df7
3
+ metadata.gz: 9144dd74ada6b36a467e13a30edce33bbd753e61739a664a8f1eddd01e41a70f
4
+ data.tar.gz: e0d4c36ed1151004d450a96b68bb571157914121d1fd8d15741a344024e848c1
5
5
  SHA512:
6
- metadata.gz: 4842c9fdbeedd824a77a671468a2a7f79475ace110424a983c9d123f210340be9fcf29973af0363b5c695e6302e3679c8a0aee2cb1f08f0925339100c37810c3
7
- data.tar.gz: 46e0d41670768d053814aa0a77b9a344ca02d0e215f14074eb27f9fff82f14e4ecefe6911a5859dfabdf6fac76490fdca240c75899eee74247df1d957308afb2
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 / 2.0).round
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>.+?)\)/)
@@ -1,5 +1,5 @@
1
1
  module BookLab
2
2
  module Toc
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  end
5
5
  end
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.3
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-30 00:00:00.000000000 Z
11
+ date: 2018-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails