Skip to content

Commit 661b5c5

Browse files
authored
Fixed an issue in which the file path containing spaces could not be grepped (#136)
* Fixed an issue in which the file path containing spaces could not be grepped * fix remove backup file path * Delete configurationCache.log * Delete dryrun.log * Delete settings.json * Delete targets.log * add test case for file path with space * modify test script - add --insert flag
1 parent 129b822 commit 661b5c5

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

gh-md-toc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ gh_toc_md2html() {
6969

7070
local gh_tmp_file_md=$gh_file_md
7171
if [ "$skip_header" = "yes" ]; then
72-
if grep -Fxq "<!--te-->" $gh_src; then
72+
if grep -Fxq "<!--te-->" "$gh_src"; then
7373
# cut everything before the toc
7474
gh_tmp_file_md=$gh_file_md~~
7575
sed '1,/<!--te-->/d' $gh_file_md > $gh_tmp_file_md
@@ -168,7 +168,7 @@ gh_toc(){
168168
local toc=`echo "$rawhtml" | gh_toc_grab "$gh_src_copy" "$indent"`
169169
echo "$toc"
170170
if [ "$need_replace" = "yes" ]; then
171-
if grep -Fxq "<!--ts-->" $gh_src && grep -Fxq "<!--te-->" $gh_src; then
171+
if grep -Fxq "<!--ts-->" "$gh_src" && grep -Fxq "<!--te-->" "$gh_src"; then
172172
echo "Found markers"
173173
else
174174
echo "You don't have <!--ts--> or <!--te--> in your file...exiting"
@@ -198,7 +198,7 @@ gh_toc(){
198198
fi
199199
echo
200200
if [ "${no_backup}" = "yes" ]; then
201-
rm ${toc_path} ${gh_src}${ext}
201+
rm "$toc_path" "$gh_src$ext"
202202
fi
203203
echo "!! TOC was added into: '$gh_src'"
204204
if [ -z "${no_backup}" ]; then
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Title
2+
3+
<!--ts-->
4+
5+
- [Title](#title)
6+
- [This is test for file path with space](#this-is-test-for-file-path-with-space)
7+
8+
<!-- Created by https://github.com/ekalinin/github-markdown-toc -->
9+
<!-- Added by: sungminyou, at: 2022년 7월 17일 일요일 16시 48분 18초 KST -->
10+
11+
<!--te-->
12+
13+
Blabla...
14+
15+
## This is test for file path with space
16+
17+
Blabla...

tests/tests.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,11 @@ test_help() {
201201

202202
assert_equal "${lines[2]}" "* [C vs C++](#c-vs-c)"
203203
}
204+
205+
@test "Toc for file path with space, #136" {
206+
run $BATS_TEST_DIRNAME/../gh-md-toc --insert tests/test\ directory/test_filepathwithspace.md
207+
assert_success
208+
209+
assert_equal "${lines[2]}" "* [Title](#title)"
210+
assert_equal "${lines[3]}" " * [This is test for file path with space](#this-is-test-for-file-path-with-space)"
211+
}

0 commit comments

Comments
 (0)