Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions gh-md-toc
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ gh_toc(){
local need_replace=$3
local no_backup=$4

if [ "$gh_src" = "" ]; then
echo "Please, enter URL or local path for a README.md"
exit 1
fi


# Show "TOC" string only if working with one document
if [ "$gh_ttl_docs" = "1" ]; then

Expand Down Expand Up @@ -182,7 +176,7 @@ gh_toc(){
if [ -z $no_backup ]; then
echo "!! Origin version of the file: '${gh_src}${ext}'"
echo "!! TOC added into a separate file: '${toc_path}'"
fi
fi
echo
fi
fi
Expand All @@ -195,11 +189,11 @@ gh_toc(){
# It's need if TOC is generated for multiple documents.
#
gh_toc_grab() {
# if closed <h[1-6]> is on the new line, then move it on the prev line
# for example:
# was: The command <code>foo1</code>
# </h1>
# became: The command <code>foo1</code></h1>
# if closed <h[1-6]> is on the new line, then move it on the prev line
# for example:
# was: The command <code>foo1</code>
# </h1>
# became: The command <code>foo1</code></h1>
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
# find strings that corresponds to template
grep -E -o '<a.*id="user-content-[^"]*".*</h[1-6]' |
Expand Down Expand Up @@ -275,6 +269,7 @@ gh_toc_app() {

if [ "$1" = '--insert' ]; then
need_replace="yes"
no_backup="yes"
Copy link
Copy Markdown

@axeljonson axeljonson Jul 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jordantrizz I don't think this going to get you what you are expecting. Placing no_backup="yes" on line 272 will cause the "--insert" and "--no_backup" CLI options to be dependent and that may not be what folks want or expect. Just because I want to insert the TOC does not necessarily mean I don't want a backup. To keep them independent, you may want to remove this line and add the following:
line 233: local no_backup="no"
And then change line 182 as follows:
from:
if [ -z $no_backup ]; then
to:
if [ $no_backup = "no" ], then

I think this will keep the two CLI options independent and the code will provide the expected results.

Copy link
Copy Markdown
Contributor Author

@jordantrizz jordantrizz Nov 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally, wish I had time to commit to this but I don't :(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed differently in #108

shift
fi

Expand All @@ -283,12 +278,18 @@ gh_toc_app() {
no_backup="yes"
shift
fi
for md in "$@"
do
if [ -z $@ ]; then
echo "No file or URL specified defaulting to local README.md"
md="README.md"
echo ""
gh_toc "$md" "$#" "$need_replace" "$no_backup"
done

else
for md in "$@"
do
echo ""
gh_toc "$md" "$#" "$need_replace" "$no_backup"
done
fi
echo ""
echo "Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)"
}
Expand Down