@@ -197,24 +197,43 @@ gh_toc(){
197197# It's need if TOC is generated for multiple documents.
198198#
199199gh_toc_grab () {
200+ common_awk_script='
201+ modified_href = ""
202+ split(href, chars, "")
203+ for (i=1;i <= length(href); i++) {
204+ c = chars[i]
205+ res = ""
206+ if (c == "+") {
207+ res = " "
208+ } else {
209+ if (c == "%") {
210+ res = "\\\\x"
211+ } else {
212+ res = c ""
213+ }
214+ }
215+ modified_href = modified_href res
216+ }
217+ print sprintf("%*s", level*3, " ") "* [" text "](" gh_url modified_href ")"
218+ '
200219 if [ ` uname -s` == " OS/390" ]; then
201220 grepcmd=" pcregrep -o"
202221 echoargs=" "
203222 awkscript=' {
204223 level = substr($0, length($0), 1)
205224 text = substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
206225 href = substr($0, match($0, "href=\"([^\"]+)?\"")+6, RLENGTH-7)
207- print sprintf("%*s", level*3, " ") "* [" text "](" gh_url href ")"
208- }'
226+ ' " $common_awk_script " '
227+ }'
209228 else
210229 grepcmd=" grep -Eo"
211230 echoargs=" -e"
212231 awkscript=' {
213232 level = substr($0, length($0), 1)
214233 text = substr($0, match($0, /a>.*<\/h/)+2, RLENGTH-5)
215234 href = substr($0, match($0, "href=\"[^\"]+?\"")+6, RLENGTH-7)
216- print sprintf("%*s", level*3, " ") "* [" text "](" gh_url href ")"
217- }'
235+ ' " $common_awk_script " '
236+ }'
218237 fi
219238 href_regex=' href=\"[^\"]+?\"'
220239
@@ -239,9 +258,11 @@ gh_toc_grab() {
239258 # format result line
240259 # * $0 - whole string
241260 # * last element of each row: "</hN" where N in (1,2,3,...)
242- echo $echoargs " $( awk -v " gh_url=$1 " " $awkscript " | sed ' y/+/ /; s/%/\\x/g ' ) "
261+ echo $echoargs " $( awk -v " gh_url=$1 " " $awkscript " ) "
243262}
244263
264+ # perl -lpE 's/(\[[^\]]*\]\()(.*?)(\))/my ($pre, $in, $post)=($1, $2, $3) ; $in =~ s{\+}{ }g; $in =~ s{%}{\\x}g; $pre.$in.$post/ems')"
265+
245266#
246267# Returns filename only from full path or url
247268#
0 commit comments