mdtoc 0.3.1 → 0.4.2

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: 18181b859f98c2413c06fc51d9cb02d6350eda1e82953019dc7007e48a00784b
4
+ data.tar.gz: 6bcd6502f07056de61e2ac6679b296338babbfd5470b731a2a7ca6ccc0f06259
5
5
  SHA512:
6
- metadata.gz: 2282ca2fb424b8dc093c856c83d4c13373bc10206d0a0f6c80c05c83329d057d1b3ce2c8dcf1a68ca2a7f303df22b95fccf3a71c1ead0f4c4e6da8049477005e
7
- data.tar.gz: 714e58db5f76da82a910398f308698ed049bd56c9632b85d7131465d04d247ac57a0648b718f28b37dfa86be275535b0aee31a0cf5362a4f86523ced23037151
6
+ metadata.gz: 8045d2d699f6f6fcdd5d2c5671ed08950c279f3a6c3d836f149f1bfc7d8edad60582cf2539f2e042ebabde2b99b3eb7ccf0b6c3476fb294ba170afbe9c787b6f
7
+ data.tar.gz: d077544177ade528172c9642df28174c596ba663e658ea36b838d8fc616eb662960be342fa030137a987eace0e2615389c339562d1cde09997038d9416f866f5
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # mdtoc - Markdown Table of Contents
2
2
 
3
+ [![CI](https://github.com/andornaut/mdtoc/actions/workflows/release.yml/badge.svg)](https://github.com/andornaut/mdtoc/actions/workflows/release.yml)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
3
6
  Read Markdown files and output a table of contents.
4
7
 
5
8
  ## Installation
@@ -15,7 +18,7 @@ gem install mdtoc
15
18
  ## Usage
16
19
 
17
20
  ```bash
18
- $ mdtoc --help
21
+ mdtoc --help
19
22
  Usage: mdtoc [options] files or directories...
20
23
  -h, --help Show this message
21
24
  -o, --output PATH Update a table of contents in the file at PATH
@@ -25,25 +28,24 @@ Usage: mdtoc [options] files or directories...
25
28
 
26
29
  1. Add a `<!-- mdtoc -->` tag to a Markdown file.
27
30
 
28
- ```bash
29
- echo '<!-- mdtoc -->' >> README.md
30
- ```
31
+ ```bash
32
+ echo '<!-- mdtoc -->' >> README.md
33
+ ```
31
34
 
32
35
  2. Run `mdtoc` and specify input files or directories (eg. the "test/samples" directory) and an output file (eg. "README.md").
33
36
 
34
- ```bash
35
- mdtoc -aco README.md test/samples
36
- ```
37
+ ```bash
38
+ mdtoc -aco README.md test/samples
39
+ ```
37
40
 
38
41
  ## Example Rakefile
39
42
 
40
43
  Create a `Rakefile` with the contents below, then run
41
44
  [`rake`](https://github.com/ruby/rake) to:
42
45
 
43
- * `git pullgem push pkg/mdtoc-0.2.0.gem`
44
- * `git add` any *.md files
45
46
  * Run `mdtoc` to update the generated table of contents in the ./README.md file
46
- * Git commit and push any changes
47
+ * `git add` any `*.md` files
48
+ * Git commit, pull, and push any changes
47
49
 
48
50
  ```ruby
49
51
  task default: %w[mdtoc]
@@ -57,7 +59,7 @@ task :mdtoc do
57
59
  exit 1
58
60
  fi
59
61
  mdtoc --append --create --output README.md docs/
60
- git add *.md **/*.md
62
+ git add README.md docs/*.md
61
63
  git commit -qm 'Update TOC' || true
62
64
  git pull
63
65
  git push
@@ -70,9 +72,9 @@ task :mdtoc do
70
72
  end
71
73
  ```
72
74
 
73
- See [andornaut/til](https://github.com/andornaut/til/blob/master/Rakefile) for an example.
75
+ See [andornaut/til](https://github.com/andornaut/til/blob/main/Rakefile) for an example.
74
76
 
75
- ## Development
77
+ ## Developing
76
78
 
77
79
  ### Setup
78
80
 
@@ -90,23 +92,34 @@ bin/setup
90
92
 
91
93
  ```bash
92
94
  # List rake tasks
93
- $ rake -T
95
+ rake -T
94
96
  rake build # Build gem into the pkg directory
95
97
  rake default # Run the build, rubocop, sorbet and test tasks
96
98
  rake install # Build and install gem into system gems
97
99
  rake rubocop # Run RuboCop
98
100
  rake sorbet # Run the Sorbet type checker
99
101
  rake test # Run tests
100
- ```
102
+
101
103
  # Run mdtoc with test inputs
102
- $ ruby -Ilib bin/mdtoc test/samples
104
+ ruby -Ilib bin/mdtoc test/samples
103
105
 
104
106
  # 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}
107
+ f=$(mktemp) && ruby -Ilib bin/mdtoc -aco ${f} test/samples ; cat ${f}
106
108
  ```
107
109
 
108
110
  ### Publishing
109
111
 
110
- ```bash
111
- rake release
112
- ```
112
+ 1. Bump version in `lib/mdtoc/version.rb`
113
+ 2. Run `bundle install` to update `Gemfile.lock`
114
+ 3. Commit the changes
115
+ 4. Tag the commit `vX.Y.Z` and push the tag
116
+
117
+ Pushing the tag is the whole release. The Release workflow runs the checks,
118
+ builds the gem, cuts the GitHub release, and pushes that same gem to RubyGems.
119
+ `rake release` is not run by hand.
120
+
121
+ Nothing here holds a RubyGems API key. The workflow authenticates with a
122
+ short-lived credential minted from its own OIDC claim, against a trusted
123
+ publisher registered on RubyGems that names this repository and
124
+ `.github/workflows/release.yml`. Renaming that file stops publishing until the
125
+ trusted publisher is updated to match.
data/bin/mdtoc CHANGED
@@ -2,5 +2,5 @@
2
2
  # typed: true
3
3
  # frozen_string_literal: true
4
4
 
5
- require "mdtoc"
5
+ require 'mdtoc'
6
6
  Mdtoc.main(ARGV)
@@ -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,10 @@ 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
+ headers.each { |h| h.depth -= min_depth } if min_depth.positive?
32
+ headers.join("\n")
32
33
  end
33
34
  end
34
35
 
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.2'
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.2
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-08-17 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.13.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.13.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
@@ -111,6 +111,9 @@ dependencies:
111
111
  description: |
112
112
  # mdtoc - Markdown Table of Contents
113
113
 
114
+ [![CI](https://github.com/andornaut/mdtoc/actions/workflows/release.yml/badge.svg)](https://github.com/andornaut/mdtoc/actions/workflows/release.yml)
115
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
116
+
114
117
  Read Markdown files and output a table of contents.
115
118
 
116
119
  ## Installation
@@ -126,7 +129,7 @@ description: |
126
129
  ## Usage
127
130
 
128
131
  ```bash
129
- $ mdtoc --help
132
+ mdtoc --help
130
133
  Usage: mdtoc [options] files or directories...
131
134
  -h, --help Show this message
132
135
  -o, --output PATH Update a table of contents in the file at PATH
@@ -136,25 +139,24 @@ description: |
136
139
 
137
140
  1. Add a `<!-- mdtoc -->` tag to a Markdown file.
138
141
 
139
- ```bash
140
- echo '<!-- mdtoc -->' >> README.md
141
- ```
142
+ ```bash
143
+ echo '<!-- mdtoc -->' >> README.md
144
+ ```
142
145
 
143
146
  2. Run `mdtoc` and specify input files or directories (eg. the "test/samples" directory) and an output file (eg. "README.md").
144
147
 
145
- ```bash
146
- mdtoc -aco README.md test/samples
147
- ```
148
+ ```bash
149
+ mdtoc -aco README.md test/samples
150
+ ```
148
151
 
149
152
  ## Example Rakefile
150
153
 
151
154
  Create a `Rakefile` with the contents below, then run
152
155
  [`rake`](https://github.com/ruby/rake) to:
153
156
 
154
- * `git pullgem push pkg/mdtoc-0.2.0.gem`
155
- * `git add` any *.md files
156
157
  * Run `mdtoc` to update the generated table of contents in the ./README.md file
157
- * Git commit and push any changes
158
+ * `git add` any `*.md` files
159
+ * Git commit, pull, and push any changes
158
160
 
159
161
  ```ruby
160
162
  task default: %w[mdtoc]
@@ -168,7 +170,7 @@ description: |
168
170
  exit 1
169
171
  fi
170
172
  mdtoc --append --create --output README.md docs/
171
- git add *.md **/*.md
173
+ git add README.md docs/*.md
172
174
  git commit -qm 'Update TOC' || true
173
175
  git pull
174
176
  git push
@@ -181,9 +183,9 @@ description: |
181
183
  end
182
184
  ```
183
185
 
184
- See [andornaut/til](https://github.com/andornaut/til/blob/master/Rakefile) for an example.
186
+ See [andornaut/til](https://github.com/andornaut/til/blob/main/Rakefile) for an example.
185
187
 
186
- ## Development
188
+ ## Developing
187
189
 
188
190
  ### Setup
189
191
 
@@ -201,26 +203,37 @@ description: |
201
203
 
202
204
  ```bash
203
205
  # List rake tasks
204
- $ rake -T
206
+ rake -T
205
207
  rake build # Build gem into the pkg directory
206
208
  rake default # Run the build, rubocop, sorbet and test tasks
207
209
  rake install # Build and install gem into system gems
208
210
  rake rubocop # Run RuboCop
209
211
  rake sorbet # Run the Sorbet type checker
210
212
  rake test # Run tests
211
- ```
213
+
212
214
  # Run mdtoc with test inputs
213
- $ ruby -Ilib bin/mdtoc test/samples
215
+ ruby -Ilib bin/mdtoc test/samples
214
216
 
215
217
  # 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}
218
+ f=$(mktemp) && ruby -Ilib bin/mdtoc -aco ${f} test/samples ; cat ${f}
217
219
  ```
218
220
 
219
221
  ### Publishing
220
222
 
221
- ```bash
222
- rake release
223
- ```
223
+ 1. Bump version in `lib/mdtoc/version.rb`
224
+ 2. Run `bundle install` to update `Gemfile.lock`
225
+ 3. Commit the changes
226
+ 4. Tag the commit `vX.Y.Z` and push the tag
227
+
228
+ Pushing the tag is the whole release. The Release workflow runs the checks,
229
+ builds the gem, cuts the GitHub release, and pushes that same gem to RubyGems.
230
+ `rake release` is not run by hand.
231
+
232
+ Nothing here holds a RubyGems API key. The workflow authenticates with a
233
+ short-lived credential minted from its own OIDC claim, against a trusted
234
+ publisher registered on RubyGems that names this repository and
235
+ `.github/workflows/release.yml`. Renaming that file stops publishing until the
236
+ trusted publisher is updated to match.
224
237
  email:
225
238
  executables:
226
239
  - mdtoc
@@ -252,7 +265,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
252
265
  requirements:
253
266
  - - ">="
254
267
  - !ruby/object:Gem::Version
255
- version: 2.7.2
268
+ version: 3.2.0
256
269
  required_rubygems_version: !ruby/object:Gem::Requirement
257
270
  requirements:
258
271
  - - ">="