markdown_section_numbering 0.9.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bd695f991b84fd57e45afaca3e03f4135b2931c
4
- data.tar.gz: ecfd26b2b8bb24f953d373507fe38ac46701e5ba
3
+ metadata.gz: 10dc0e56ed3dcd9d60742626b3857d280956fbb1
4
+ data.tar.gz: 9aff5550bdc5925cb15bf1a68ecd1a4e6cf50c7c
5
5
  SHA512:
6
- metadata.gz: e6860f7d55dbcbcec2a16207f7725d861d3d6f2576b80cdde66e6355543d7163fa35bd0e781d648b112b92fa42255f8c761601d4ab616ab6ad338cb95d71ff6a
7
- data.tar.gz: dbb514c7dc2c1f85a353bcdf0061157355d87606b6e1caf4c3d74e8c4024bedaf8c65d60b9ac7487e5f9c348103ab6b21a40e0c9ee47a10c1687210be144806d
6
+ metadata.gz: 43583f120fff103cf59b9cb195c0861e155085612d202b5874777f239d32936bca70af17e43c5cc0e7641d63526d671485f4395cadcc11973077c98ae95a62a8
7
+ data.tar.gz: 53dc2e817cd63473821ba51ed8e1da8dc3ecb58b8c86fe28edcfd7fa1fa4b1954caef00f242e722521c2bd68881a5b0dc132b0a655d1f106935b8e96568e85df
data/README.md CHANGED
@@ -18,6 +18,8 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
+ ### Basic
22
+
21
23
  ```ruby
22
24
  require "markdown_section_numbering"
23
25
 
@@ -52,6 +54,31 @@ foo bar
52
54
  - list
53
55
  ```
54
56
 
57
+ ### Re-numbering
58
+
59
+ Section numbers are replaced with new number.
60
+
61
+ Following markdown is going to be converted,
62
+
63
+ ```
64
+ # foo
65
+ # 1 a
66
+ ## 1.1 b
67
+ ## bar
68
+ ## 1.2 c
69
+ ```
70
+
71
+ like this.
72
+
73
+ ```
74
+ # 1 foo
75
+ # 2 a
76
+ ## 2.1 b
77
+ ## 2.2 bar
78
+ ## 2.3 c
79
+ ```
80
+
81
+
55
82
  ## Contributing
56
83
 
57
84
  1. Fork it ( https://github.com/[my-github-username]/markdown_section_numbering/fork )
@@ -35,12 +35,12 @@ class MarkdownSectionNumbering
35
35
  return line if target_level > max_level
36
36
 
37
37
  header_sign = "#" * target_level
38
- regex = Regexp.new("^#{header_sign}\s*(.+)")
38
+ regex = Regexp.new("^#{header_sign}\\s*(\\d+(\\.\\d+)*)?\\s*(.+)")
39
39
  match = line.match(regex)
40
40
 
41
41
  number = calc_section_number(target_level)
42
42
 
43
- "#{header_sign} #{number} #{match[1]}"
43
+ "#{header_sign} #{number} #{match[3]}"
44
44
  end
45
45
 
46
46
  def calc_section_number(target_level)
@@ -1,3 +1,3 @@
1
1
  class MarkdownSectionNumbering
2
- VERSION = "0.9.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,23 @@
1
+ # 1 a
2
+ ## 1.1 b
3
+ ### 1.1.1 c
4
+ ## 1.2 d
5
+ ### 1.2.1 e
6
+ ### 1.2.2 f
7
+
8
+ # 2 g
9
+ ## h
10
+
11
+ ### i
12
+ ### j
13
+ ## 2.1 k
14
+ ### 2.1.1 l
15
+ ### m
16
+ ### 2.1.2 n
17
+ ## 2.2 o
18
+ ### 2.2.1 p
19
+ ### 2.2.2 q
20
+
21
+ # r
22
+
23
+ # 3 s
@@ -15,12 +15,20 @@ describe MarkdownSectionNumbering do
15
15
  expect(output).to eq(expected)
16
16
  end
17
17
 
18
+ specify "replace old section numbers with new one" do
19
+ input = fixture("input3.md")
20
+ expected = fixture("output1.md")
21
+ output = MarkdownSectionNumbering.convert(input)
22
+ expect(output).to eq(expected)
23
+ end
24
+
18
25
  specify "when max level is set to 2, headings deeper than 2 are not converted" do
26
+ MarkdownSectionNumbering.config(2)
27
+
19
28
  input = fixture("input1.md")
20
29
  expected = fixture("output2.md")
21
- MarkdownSectionNumbering.config(2)
22
30
  output = MarkdownSectionNumbering.convert(input)
23
31
  expect(output).to eq(expected)
24
32
  end
25
-
33
+
26
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_section_numbering
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.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-04 00:00:00.000000000 Z
11
+ date: 2014-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,6 +58,7 @@ files:
58
58
  - spec/.rspec
59
59
  - spec/fixtures/input1.md
60
60
  - spec/fixtures/input2.md
61
+ - spec/fixtures/input3.md
61
62
  - spec/fixtures/output1.md
62
63
  - spec/fixtures/output2.md
63
64
  - spec/markdown_section_numbering_spec.rb
@@ -90,6 +91,7 @@ test_files:
90
91
  - spec/.rspec
91
92
  - spec/fixtures/input1.md
92
93
  - spec/fixtures/input2.md
94
+ - spec/fixtures/input3.md
93
95
  - spec/fixtures/output1.md
94
96
  - spec/fixtures/output2.md
95
97
  - spec/markdown_section_numbering_spec.rb