markdown_section_numbering 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -0
- data/lib/markdown_section_numbering.rb +2 -2
- data/lib/markdown_section_numbering/version.rb +1 -1
- data/spec/fixtures/input3.md +23 -0
- data/spec/markdown_section_numbering_spec.rb +10 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10dc0e56ed3dcd9d60742626b3857d280956fbb1
|
4
|
+
data.tar.gz: 9aff5550bdc5925cb15bf1a68ecd1a4e6cf50c7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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}
|
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[
|
43
|
+
"#{header_sign} #{number} #{match[3]}"
|
44
44
|
end
|
45
45
|
|
46
46
|
def calc_section_number(target_level)
|
@@ -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.
|
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-
|
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
|