derlin / bitdowntoc

Online and command-line Markdown TOC generator, with built-in support for BitBucket Server, GitHub, Gitlab, dev.to and more!
https://bitdowntoc.derlin.ch
Other
92 stars 8 forks source link

Allow markdown to be piped into the mac CLI instead of directly passing an input file #33

Closed 0xdevalias closed 7 months ago

0xdevalias commented 7 months ago

It would be awesome if we could pipe markdown directly into the CLI rather than needing to specify an input file:

⇒ echo "aaa" | ~/Desktop/bitdowntoc_mac
Usage: cli [OPTIONS] INPUTFILE

Error: Missing argument "INPUTFILE"

And then ideally it would write the output to STDOUT so we could pipe it elsewhere as well.

derlin commented 7 months ago

@0xdevalias Thanks for the issue! This makes sense. I propose to support "-" as an argument to read from stdin:

echo "aaa" | java -jar bitdowntoc.jar -

I created a pull request, can you have a look and see if this works for you? (the built jar can be downloaded from the workflow run of the PR).

0xdevalias commented 7 months ago

I created a pull request, can you have a look and see if this works for you?

@derlin Gave it a go, looks good!

From a super basic test, looks like it works:

⇒ echo "# Foo\n[TOC]\n## Bar\n### Baz\n## Bar2" | java -jar ~/Desktop/bitdowntoc-jvm-2.0.2-SNAPSHOT.jar -
# Foo
<!-- TOC start (generated with https://github.com/derlin/bitdowntoc) -->

- [Bar](#bar)
   * [Baz](#baz)
- [Bar2](#bar2)

<!-- TOC end -->
<!-- TOC --><a name="bar"></a>
## Bar
<!-- TOC --><a name="baz"></a>
### Baz
<!-- TOC --><a name="bar2"></a>
## Bar2

And also ran it over a much more complex markdown file and it generated an equivalent TOC as the one from the online version, so LGTM! 👌🏻

Originally posted by @0xdevalias in https://github.com/derlin/bitdowntoc/issues/39#issuecomment-2081923838