Add SourceHut .build.yml
Use Commander for CLI argument parsing
Update README Helix config
Keep numbered, reference-style Markdown links in sequential order. If you have a document like this:
Here's a [link][1].
[1]: https://link-a.com
Here's another [link][2].
[2]: https://link-b.com
And you add a new link at the beginning, like this:
Here's a [new link][3]. Here's a [link][1].
[1]: https://link-a.com
[3]: https://link-c.com
Here's another [link][2].
[2]: https://link-b.com
The result of running mdrenum --fix
will be:
Here's a [new link][1]. Here's a [link][2].
[1]: https://link-c.com
[2]: https://link-a.com
Here's another [link][3].
[3]: https://link-b.com
Usage: mdrenum [options] [files...]
Arguments:
files files to scan (default: .md files in current directory + subdirectories)
Options:
-s, --stdin read content from STDIN, write to STDOUT (default: false)
-f, --fix update files to put links in sequential order (default: false)
-h, --help display help for command
mdrenum
will report an error and won't update the file.mdrenum
encounters multiple definitions with the same identifier, it will report an error and won't update the file.We use Bun to compile a standalone executable. The version is specified in .tool-versions
. Compile the program with bun run build
. The resulting executable will be bin/mdrenum
, which you can copy to a directory on $PATH
.
Tests live in src/mdrenum.test.ts
. Run them with bun test
.
To instruct Helix to automatically renumber links on save, add the following to ~/.config/helix/languages.toml
:
[[language]]
name = "markdown"
auto-format = true
formatter = { command = "mdrenum" , args = ["--stdin"] }
All credit to the unified collective for creating mdast
, which is doing most of the heavy lifting here.