Skip to content

Commit 09419c2

Browse files
committed
fixed new html layout. more readble awk code
1 parent 3e881f9 commit 09419c2

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

gh-md-toc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,13 @@ gh_toc_grab() {
186186
# <a id="user-content-..." href="..."><span ...></span></a> ... </h1
187187
# format result line
188188
# * $0 — whole string
189+
# * last element of each row: "</hN" where N in (1,2,3,...)
189190
echo -e "$(awk -v "gh_url=$1" '{
190-
print sprintf("%*s", substr($0, length($0), 1)*3, " ") "* [" substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)"](" gh_url substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8) ")"}' | sed 'y/+/ /; s/%/\\x/g')"
191+
level = substr($0, length($0), 1)
192+
text = substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
193+
href = substr($0, match($0, "href=\"[^\"]+?\"")+6, RLENGTH-7)
194+
print sprintf("%*s", level*3, " ") "* [" text "](" gh_url href ")" }' |
195+
sed 'y/+/ /; s/%/\\x/g')"
191196
}
192197

193198
#

tests/tests.bats

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ load test_helper
114114
assert_success
115115

116116
assert_equal "${lines[2]}" " * [envirius](#envirius)"
117-
assert_equal "${lines[3]}" " * [Идея](#Идея)"
118-
assert_equal "${lines[4]}" " * [Особенности](#Особенности)"
119-
assert_equal "${lines[5]}" " * [Установка](#Установка)"
117+
assert_equal "${lines[3]}" " * [Идея](#идея)"
118+
assert_equal "${lines[4]}" " * [Особенности](#особенности)"
119+
assert_equal "${lines[5]}" " * [Установка](#установка)"
120120

121121

122122
run $BATS_TEST_DIRNAME/../gh-md-toc \

0 commit comments

Comments
 (0)