Skip to content

Commit

Permalink
fixed new html layout. more readble awk code
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin committed Dec 29, 2018
1 parent 3e881f9 commit 09419c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion gh-md-toc
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,13 @@ gh_toc_grab() {
# <a id="user-content-..." href="..."><span ...></span></a> ... </h1
# format result line
# * $0 — whole string
# * last element of each row: "</hN" where N in (1,2,3,...)
echo -e "$(awk -v "gh_url=$1" '{
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')"
level = substr($0, length($0), 1)
text = substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
href = substr($0, match($0, "href=\"[^\"]+?\"")+6, RLENGTH-7)
print sprintf("%*s", level*3, " ") "* [" text "](" gh_url href ")" }' |
sed 'y/+/ /; s/%/\\x/g')"
}

#
Expand Down
6 changes: 3 additions & 3 deletions tests/tests.bats
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ load test_helper
assert_success

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


run $BATS_TEST_DIRNAME/../gh-md-toc \
Expand Down

0 comments on commit 09419c2

Please sign in to comment.