Skip to content

Commit

Permalink
0.4.6: fixed #19
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin committed Jan 27, 2016
1 parent bb5e6f6 commit 991b3dd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gh-md-toc
Expand Up @@ -23,7 +23,7 @@
# substr($0, match($0, "href=\".*\" ")+5, RLENGTH-6)
#

gh_toc_version="0.4.5"
gh_toc_version="0.4.6"

gh_user_agent="gh-md-toc v$gh_toc_version"

Expand Down Expand Up @@ -111,8 +111,9 @@ fi
#
gh_toc_grab() {
# find strings that corresponds to template
#'<h[1-6]>\s*<a\s*id="user-content-[^"]*"\s*class="anchor"\s*href="[^"]*"[^>]*>\s*<span[^<*]*</span>\s*</a>.*?\s*</h' | \
$GH_GREP \
'<h[1-6]>\s*<a\s*id="user-content-[^"]*"\s*class="anchor"\s*href="[^"]*"[^>]*>\s*<span[^<*]*</span>\s*</a>.*?\s*</h' | \
'<h[1-6]>\s*<a\s*id="user-content-[^"]*"\s*class="anchor"\s*href="[^"]*"[^>]*>.*?</a>.*?\s*</h' | \
# replace all new lines except last one
sed 's/h$/h\nendd/g' | tr '\n' ' ' | sed 's/h endd/\h\n/g' | \
# trim head spaces
Expand All @@ -123,7 +124,7 @@ gh_toc_grab() {
# <h1> <a id="user-content-..." href="..."><span ...></span></a> ... </h
# format result line
echo -e "$(awk -v "gh_url=$1" '{
print sprintf("%*s", substr($1, 3, 1)*2, " ") "* [" substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)"](" gh_url substr($0, match($0, "href=\".*\" ")+6, RLENGTH-8) ")"}' | sed 'y/+/ /; s/%/\\x/g')"
print sprintf("%*s", substr($1, 3, 1)*2, " ") "* [" substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)"](" gh_url substr($0, match($0, "href=\"[^\"]+?\" ")+6, RLENGTH-8) ")"}' | sed 'y/+/ /; s/%/\\x/g')"
}

#
Expand Down

0 comments on commit 991b3dd

Please sign in to comment.