Repository navigation
feat(toc): add --stdout option to print the whole file with TOC - #183
Merged
Merged
Conversation
Fixes #62. --stdout prints the document with the new TOC between <!--ts--> and <!--te-->, the same content --insert writes, without changing the file or creating backup files. It takes one local file or - for STDIN; its errors go to stderr. STDIN is now read as is, keeping whitespace and a last line without a newline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #62: a mode like
--insertthat outputs the entire new contents of the file tostdout instead of overwriting it.
--stdoutprints the whole document with the new TOC between<!--ts-->and<!--te-->: the same content that--insertwrites into the file. The file is notchanged, no
.orig.<date>or.toc.<date>file is created, and nothing else goes tostdout (no
Table of Contentsheader, no status lines).gh-md-toc:gh_toc_stdout(new): uses the same TOC block and the same sed expressions as--insert, without-i, so the output is byte-for-byte what--insertwrites,a last line without a newline included.
gh_tocand the--insertcode are notchanged.
gh_toc_app:--stdoutis parsed right after--hide-footerand before--skip-header. It takes one local file or-for STDIN.--hide-footer,--skip-header,--indent,--depth,--numberedand--bulletwork with it aswith
--insert;--insertand--no-backupnext to it do not change the file.> out.mdthe error text does not end up in the file: no input, several inputs ora URL, a document without the markers (both before any network call), and the
GitHub API errors. The other modes keep printing errors to stdout.
gh_toc_mktemp(new): the temporary file code of the-branch, shared with--stdout. On OS/390 the name gets$$.$RANDOM, because--stdout -makes twofiles in the same second. The temporary files of
--stdoutare removed on exit,errors included.
cat, for-too. The oldwhile read -rloop removedleading and trailing whitespace and dropped a last line without a newline, so an
indented code line like
# commentbecame a TOC entry, andprintf '# A\n\n## B' | gh-md-toc -printed nothing.--help: a new line right after--hide-footer.README.md: a paragraph with examples in "Auto insert and update TOC", without a newheading, so the README TOC asserted in the tests does not change.
tests/tests.bats: 15 new tests on a new fixturetest_stdout.md(it has no newlineat the end on purpose, no test writes into it);
test_helpupdated.openspec: theadd-toc-stdoutchange (proposal, design, specs, tasks), not archivedyet.
Not included: a remote URL as input of
--stdout(a GitHub page is loaded as renderedHTML, there is no Markdown source; STDIN covers it), several inputs in one run, an
--output <FILE>option, printing the errors of the other modes to stderr.Testing
with it (macOS, BSD sed).
--numbered outlineand--depth 1with--stdout, and theremote README piped into
--stdout -(exit code 0, the lines outside the markers arethe same as in the input).
make lintpasses.