markdown_section_numbering 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: 10dc0e56ed3dcd9d60742626b3857d280956fbb1
4
- data.tar.gz: 9aff5550bdc5925cb15bf1a68ecd1a4e6cf50c7c
3
+ metadata.gz: 9cd27ab27a7fa017fdcebae39750ace4ed0a1d73
4
+ data.tar.gz: 8af35908c900440dcac023a7754d35aeba0e94f8
5
5
  SHA512:
6
- metadata.gz: 43583f120fff103cf59b9cb195c0861e155085612d202b5874777f239d32936bca70af17e43c5cc0e7641d63526d671485f4395cadcc11973077c98ae95a62a8
7
- data.tar.gz: 53dc2e817cd63473821ba51ed8e1da8dc3ecb58b8c86fe28edcfd7fa1fa4b1954caef00f242e722521c2bd68881a5b0dc132b0a655d1f106935b8e96568e85df
6
+ metadata.gz: 372069bd16ca69994f0abe6a850060c4f3f3d39b1d48ac69c31938f0fc5158de44567b3172cb3ad90fcbd6aca8e9505089a954d9454f3b2c34b7d8f4d93ca4d7
7
+ data.tar.gz: 7f0833f686b74f5096cca395eb14c66750babe32f50d5000cca814a44700f3ba556a064340460a6f3ecbcbdd3e07b8325e0f19fe3fbff8becbd37516d2563861
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'markdown_section_numbering'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'markdown_section_numbering'
8
+ end
9
+
10
+ $stdout.write MarkdownSectionNumbering.convert($stdin.read)
@@ -1,18 +1,16 @@
1
- require "markdown_section_numbering/version"
1
+ require 'markdown_section_numbering/version'
2
2
 
3
3
  class MarkdownSectionNumbering
4
4
  class << self
5
-
6
5
  def config(max_level)
7
6
  @max_level = max_level
8
7
  end
9
8
 
10
9
  def convert(input)
11
10
  @section_index = [-1] + [0] * max_level
12
-
13
11
  input.lines.map do |line|
14
12
  convert_line(line)
15
- end.join("\n")+"\n"
13
+ end.join("\n") + "\n"
16
14
  end
17
15
 
18
16
  private
@@ -23,7 +21,8 @@ class MarkdownSectionNumbering
23
21
 
24
22
  def convert_line(line)
25
23
  line.chomp!
26
- if not match = line.match(/^#+/)
24
+ match = line.match(/^#+/)
25
+ if !match
27
26
  line
28
27
  else
29
28
  level = match[0].length
@@ -33,23 +32,22 @@ class MarkdownSectionNumbering
33
32
 
34
33
  def add_section_number(line, target_level)
35
34
  return line if target_level > max_level
36
-
37
- header_sign = "#" * target_level
35
+
36
+ header_sign = '#' * target_level
38
37
  regex = Regexp.new("^#{header_sign}\\s*(\\d+(\\.\\d+)*)?\\s*(.+)")
39
38
  match = line.match(regex)
40
39
 
41
40
  number = calc_section_number(target_level)
42
-
41
+
43
42
  "#{header_sign} #{number} #{match[3]}"
44
43
  end
45
44
 
46
45
  def calc_section_number(target_level)
47
46
  @section_index[target_level] += 1
48
- (target_level+1 .. max_level).each do |child_level|
47
+ ((target_level + 1)..max_level).each do |child_level|
49
48
  @section_index[child_level] = 0
50
49
  end
51
- (1..target_level).map {|level| @section_index[level].to_s }.join(".")
50
+ (1..target_level).map { |level| @section_index[level].to_s }.join('.')
52
51
  end
53
-
54
52
  end
55
53
  end
@@ -1,3 +1,3 @@
1
1
  class MarkdownSectionNumbering
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -4,19 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'markdown_section_numbering/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "markdown_section_numbering"
7
+ spec.name = 'markdown_section_numbering'
8
8
  spec.version = MarkdownSectionNumbering::VERSION
9
- spec.authors = ["xoyip"]
10
- spec.email = ["xoyip@piyox.info"]
11
- spec.summary = %q{Add section numbers to markdown headings.}
12
- spec.description = %q{}
13
- spec.homepage = "https://github.com/xoyip/markdown_section_numbering"
14
- spec.license = "MIT"
9
+ spec.authors = ['xoyip']
10
+ spec.email = ['xoyip@piyox.info']
11
+ spec.summary = 'Add section numbers to markdown headings.'
12
+ spec.description = ''
13
+ spec.homepage = 'https://github.com/xoyip/markdown_section_numbering'
14
+ spec.license = 'MIT'
15
15
 
16
+ spec.executables = ['markdown-section-numbering']
16
17
  spec.files = `git ls-files -z`.split("\x0")
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
19
20
 
20
- spec.add_development_dependency "bundler", "~> 1.6"
21
- spec.add_development_dependency "rake"
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
22
23
  end
metadata CHANGED
@@ -1,56 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_section_numbering
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xoyip
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-05 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  description: ''
42
42
  email:
43
43
  - xoyip@piyox.info
44
- executables: []
44
+ executables:
45
+ - markdown-section-numbering
45
46
  extensions: []
46
47
  extra_rdoc_files: []
47
48
  files:
48
- - ".gitignore"
49
- - ".rspec"
49
+ - .gitignore
50
+ - .rspec
50
51
  - Gemfile
51
52
  - LICENSE.txt
52
53
  - README.md
53
54
  - Rakefile
55
+ - bin/markdown-section-numbering
54
56
  - example/example.rb
55
57
  - lib/markdown_section_numbering.rb
56
58
  - lib/markdown_section_numbering/version.rb
@@ -73,17 +75,17 @@ require_paths:
73
75
  - lib
74
76
  required_ruby_version: !ruby/object:Gem::Requirement
75
77
  requirements:
76
- - - ">="
78
+ - - '>='
77
79
  - !ruby/object:Gem::Version
78
80
  version: '0'
79
81
  required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  requirements:
81
- - - ">="
83
+ - - '>='
82
84
  - !ruby/object:Gem::Version
83
85
  version: '0'
84
86
  requirements: []
85
87
  rubyforge_project:
86
- rubygems_version: 2.2.0
88
+ rubygems_version: 2.4.5
87
89
  signing_key:
88
90
  specification_version: 4
89
91
  summary: Add section numbers to markdown headings.
@@ -96,3 +98,4 @@ test_files:
96
98
  - spec/fixtures/output2.md
97
99
  - spec/markdown_section_numbering_spec.rb
98
100
  - spec/spec_helper.rb
101
+ has_rdoc: