mdtoc 0.3.1 → 0.4.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
  SHA256:
3
- metadata.gz: dd651a744c265508fe1b78eae797f688f83a417d0710ed70fdff838a05e8e2b9
4
- data.tar.gz: bfd727b632d7d5076ef17e309e1a2715f5de971a313e74190b9e1facadcade7a
3
+ metadata.gz: f53365d2172397bc4b50a26f88ce05d13c8766453b56c96fd1513151b2d72cad
4
+ data.tar.gz: c49f859803c2bf3928c51f70535ba35a9bffda3ccc69457713977497c6a50f6e
5
5
  SHA512:
6
- metadata.gz: 2282ca2fb424b8dc093c856c83d4c13373bc10206d0a0f6c80c05c83329d057d1b3ce2c8dcf1a68ca2a7f303df22b95fccf3a71c1ead0f4c4e6da8049477005e
7
- data.tar.gz: 714e58db5f76da82a910398f308698ed049bd56c9632b85d7131465d04d247ac57a0648b718f28b37dfa86be275535b0aee31a0cf5362a4f86523ced23037151
6
+ metadata.gz: de596f6886429e537d249cc2c2516521cfb23ee8c407f002348a68fe93b3de30f0b6e4809d64c5c2e75858e33791e4507d9060c35c79a8f0459202c105e54b73
7
+ data.tar.gz: 8da62161d757e8be2c7970ed076b58ea1dbc0b1416e35d497dbc5545faf84764ab88e08895f21c3995e98acd2c1f0f88bec4c9b96b5bcb3f27ad6a80ef07b88e
data/README.md CHANGED
@@ -15,7 +15,7 @@ gem install mdtoc
15
15
  ## Usage
16
16
 
17
17
  ```bash
18
- $ mdtoc --help
18
+ mdtoc --help
19
19
  Usage: mdtoc [options] files or directories...
20
20
  -h, --help Show this message
21
21
  -o, --output PATH Update a table of contents in the file at PATH
@@ -25,23 +25,23 @@ Usage: mdtoc [options] files or directories...
25
25
 
26
26
  1. Add a `<!-- mdtoc -->` tag to a Markdown file.
27
27
 
28
- ```bash
29
- echo '<!-- mdtoc -->' >> README.md
30
- ```
28
+ ```bash
29
+ echo '<!-- mdtoc -->' >> README.md
30
+ ```
31
31
 
32
32
  2. Run `mdtoc` and specify input files or directories (eg. the "test/samples" directory) and an output file (eg. "README.md").
33
33
 
34
- ```bash
35
- mdtoc -aco README.md test/samples
36
- ```
34
+ ```bash
35
+ mdtoc -aco README.md test/samples
36
+ ```
37
37
 
38
38
  ## Example Rakefile
39
39
 
40
40
  Create a `Rakefile` with the contents below, then run
41
41
  [`rake`](https://github.com/ruby/rake) to:
42
42
 
43
- * `git pullgem push pkg/mdtoc-0.2.0.gem`
44
- * `git add` any *.md files
43
+ * `git pull`
44
+ * `git add` any `*.md` files
45
45
  * Run `mdtoc` to update the generated table of contents in the ./README.md file
46
46
  * Git commit and push any changes
47
47
 
@@ -90,23 +90,24 @@ bin/setup
90
90
 
91
91
  ```bash
92
92
  # List rake tasks
93
- $ rake -T
93
+ rake -T
94
94
  rake build # Build gem into the pkg directory
95
95
  rake default # Run the build, rubocop, sorbet and test tasks
96
96
  rake install # Build and install gem into system gems
97
97
  rake rubocop # Run RuboCop
98
98
  rake sorbet # Run the Sorbet type checker
99
99
  rake test # Run tests
100
- ```
100
+
101
101
  # Run mdtoc with test inputs
102
- $ ruby -Ilib bin/mdtoc test/samples
102
+ ruby -Ilib bin/mdtoc test/samples
103
103
 
104
104
  # Run mdtoc with test inputs, and write to a newly created output file
105
- $ f=$(mktemp) && ruby -Ilib bin/mdtoc -aco ${f} test/samples ; cat ${f}
105
+ f=$(mktemp) && ruby -Ilib bin/mdtoc -aco ${f} test/samples ; cat ${f}
106
106
  ```
107
107
 
108
108
  ### Publishing
109
109
 
110
- ```bash
111
- rake release
112
- ```
110
+ 1. Bump version in `lib/mdtoc/version.rb`
111
+ 2. Run `bundle install` to update `Gemfile.lock`
112
+ 3. Commit the changes
113
+ 4. Run `rake release` to publish the gem to RubyGems, create the git tag, and push
@@ -9,6 +9,9 @@ module Mdtoc
9
9
  class Header
10
10
  extend T::Sig
11
11
 
12
+ sig { returns(Integer) }
13
+ attr_accessor :depth
14
+
12
15
  sig { params(depth: Integer, label: String, url: String).void }
13
16
  def initialize(depth, label, url)
14
17
  raise ArgumentError, "Header depth must be >= 0, but was #{depth}" if depth.negative?
data/lib/mdtoc/node.rb CHANGED
@@ -26,9 +26,12 @@ module Mdtoc
26
26
 
27
27
  sig { params(paths: T::Array[String]).returns(String) }
28
28
  def render(paths)
29
- paths
30
- .flat_map { |path| for_path(path).headers }
31
- .join("\n")
29
+ headers = paths.flat_map { |path| for_path(path).headers }
30
+ min_depth = headers.map(&:depth).min || 0
31
+ if min_depth.positive?
32
+ headers.each { |h| h.depth -= min_depth }
33
+ end
34
+ headers.join("\n")
32
35
  end
33
36
  end
34
37
 
data/lib/mdtoc/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Mdtoc
5
- VERSION = '0.3.1'
5
+ VERSION = '0.4.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdtoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - andornaut
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-03 00:00:00.000000000 Z
11
+ date: 2026-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.25'
19
+ version: '6.0'
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
- version: '5.25'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,28 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.10.0
75
+ version: 0.12.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.10.0
82
+ version: 0.12.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: unparser
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.6.0
89
+ version: 0.8.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.6.0
96
+ version: 0.8.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: sorbet-runtime
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +126,7 @@ description: |
126
126
  ## Usage
127
127
 
128
128
  ```bash
129
- $ mdtoc --help
129
+ mdtoc --help
130
130
  Usage: mdtoc [options] files or directories...
131
131
  -h, --help Show this message
132
132
  -o, --output PATH Update a table of contents in the file at PATH
@@ -136,23 +136,23 @@ description: |
136
136
 
137
137
  1. Add a `<!-- mdtoc -->` tag to a Markdown file.
138
138
 
139
- ```bash
140
- echo '<!-- mdtoc -->' >> README.md
141
- ```
139
+ ```bash
140
+ echo '<!-- mdtoc -->' >> README.md
141
+ ```
142
142
 
143
143
  2. Run `mdtoc` and specify input files or directories (eg. the "test/samples" directory) and an output file (eg. "README.md").
144
144
 
145
- ```bash
146
- mdtoc -aco README.md test/samples
147
- ```
145
+ ```bash
146
+ mdtoc -aco README.md test/samples
147
+ ```
148
148
 
149
149
  ## Example Rakefile
150
150
 
151
151
  Create a `Rakefile` with the contents below, then run
152
152
  [`rake`](https://github.com/ruby/rake) to:
153
153
 
154
- * `git pullgem push pkg/mdtoc-0.2.0.gem`
155
- * `git add` any *.md files
154
+ * `git pull`
155
+ * `git add` any `*.md` files
156
156
  * Run `mdtoc` to update the generated table of contents in the ./README.md file
157
157
  * Git commit and push any changes
158
158
 
@@ -201,26 +201,27 @@ description: |
201
201
 
202
202
  ```bash
203
203
  # List rake tasks
204
- $ rake -T
204
+ rake -T
205
205
  rake build # Build gem into the pkg directory
206
206
  rake default # Run the build, rubocop, sorbet and test tasks
207
207
  rake install # Build and install gem into system gems
208
208
  rake rubocop # Run RuboCop
209
209
  rake sorbet # Run the Sorbet type checker
210
210
  rake test # Run tests
211
- ```
211
+
212
212
  # Run mdtoc with test inputs
213
- $ ruby -Ilib bin/mdtoc test/samples
213
+ ruby -Ilib bin/mdtoc test/samples
214
214
 
215
215
  # Run mdtoc with test inputs, and write to a newly created output file
216
- $ f=$(mktemp) && ruby -Ilib bin/mdtoc -aco ${f} test/samples ; cat ${f}
216
+ f=$(mktemp) && ruby -Ilib bin/mdtoc -aco ${f} test/samples ; cat ${f}
217
217
  ```
218
218
 
219
219
  ### Publishing
220
220
 
221
- ```bash
222
- rake release
223
- ```
221
+ 1. Bump version in `lib/mdtoc/version.rb`
222
+ 2. Run `bundle install` to update `Gemfile.lock`
223
+ 3. Commit the changes
224
+ 4. Run `rake release` to publish the gem to RubyGems, create the git tag, and push
224
225
  email:
225
226
  executables:
226
227
  - mdtoc
@@ -252,7 +253,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
253
  requirements:
253
254
  - - ">="
254
255
  - !ruby/object:Gem::Version
255
- version: 2.7.2
256
+ version: 3.1.0
256
257
  required_rubygems_version: !ruby/object:Gem::Requirement
257
258
  requirements:
258
259
  - - ">="