diff --git a/gh-md-toc b/gh-md-toc index a9fbae6..55b81b5 100755 --- a/gh-md-toc +++ b/gh-md-toc @@ -47,7 +47,7 @@ gh_toc_load() { # # Converts local md file into html by GitHub # -# ➥ curl -X POST --data '{"text": "Hello world github/linguist#1 **cool**, and #1!"}' https://api.github.com/markdown +# -> curl -X POST --data '{"text": "Hello world github/linguist#1 **cool**, and #1!"}' https://api.github.com/markdown #
Hello world github/linguist#1 cool, and #1!
'" gh_toc_md2html() { local gh_file_md=$1 @@ -182,7 +182,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 @@ -191,31 +191,50 @@ gh_toc(){ # # Grabber of the TOC from rendered html # -# $1 — a source url of document. +# $1 - a source url of document. # It's need if TOC is generated for multiple documents. # gh_toc_grab() { - # if closedfoo1
- #
- # became: The command foo1
+ if [ `uname -s` == "OS/390" ]; then
+ grepcmd="pcregrep -o"
+ echoargs=""
+ awkscript='{
+ 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 ")"
+ }'
+ else
+ grepcmd="grep -Eo"
+ echoargs="-e"
+ awkscript='{
+ 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 ")"
+ }'
+ fi
+ href_regex='href=\"[^\"]+?\"'
+
+ # if closed foo1
+ #
+ # became: The command foo1
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n<\/h/<\/h/g' |
+
# find strings that corresponds to template
- grep -E -o '