@@ -51,6 +51,8 @@ gh_toc_load() {
5151# <p>Hello world github/linguist#1 <strong>cool</strong>, and #1!</p>'"
5252gh_toc_md2html () {
5353 local gh_file_md=$1
54+ local skip_header=$2
55+
5456 URL=https://api.github.com/markdown/raw
5557
5658 if [ ! -z " $GH_TOC_TOKEN " ]; then
@@ -65,14 +67,25 @@ gh_toc_md2html() {
6567 AUTHORIZATION=" Authorization: token ${TOKEN} "
6668 fi
6769
70+ local gh_tmp_file_md=$gh_file_md
71+ if [ " $skip_header " = " yes" ]; then
72+ if grep -Fxq " <!--te-->" $gh_src ; then
73+ # cut everything before the toc
74+ gh_tmp_file_md=$gh_file_md ~~
75+ sed ' 1,/<!--te-->/d' $gh_file_md > $gh_tmp_file_md
76+ fi
77+ fi
78+
6879 # echo $URL 1>&2
6980 OUTPUT=$( curl -s \
7081 --user-agent " $gh_user_agent " \
71- --data-binary @" $gh_file_md " \
82+ --data-binary @" $gh_tmp_file_md " \
7283 -H " Content-Type:text/plain" \
7384 -H " $AUTHORIZATION " \
7485 " $URL " )
7586
87+ rm -f $gh_file_md ~~
88+
7689 if [ " $? " != " 0" ]; then
7790 echo " XXNetworkErrorXX"
7891 fi
@@ -107,6 +120,7 @@ gh_toc(){
107120 local no_backup=$4
108121 local no_footer=$5
109122 local indent=$6
123+ local skip_header=$7
110124
111125 if [ " $gh_src " = " " ]; then
112126 echo " Please, enter URL or local path for a README.md"
@@ -138,7 +152,7 @@ gh_toc(){
138152 echo
139153 fi
140154 else
141- local rawhtml=$( gh_toc_md2html " $gh_src " )
155+ local rawhtml=$( gh_toc_md2html " $gh_src " " $skip_header " )
142156 if [ " $rawhtml " == " XXNetworkErrorXX" ]; then
143157 echo " Parsing local markdown file requires access to github API"
144158 echo " Please make sure curl is installed and check your network connectivity"
@@ -250,16 +264,16 @@ gh_toc_grab() {
250264 # </h1>
251265 # became: The command <code>foo1</code></h1>
252266 sed -e ' :a' -e ' N' -e ' $!ba' -e ' s/\n<\/h/<\/h/g' |
253-
267+
254268 # find strings that corresponds to template
255269 $grepcmd ' <a.*id="user-content-[^"]*".*</h[1-6]' |
256-
270+
257271 # remove code tags
258272 sed ' s/<code>//g' | sed ' s/<\/code>//g' |
259273
260274 # remove g-emoji
261275 sed ' s/<g-emoji[^>]*[^<]*<\/g-emoji> //g' |
262-
276+
263277 # now all rows are like:
264278 # <a id="user-content-..." href="..."><span ...></span></a> ... </h1
265279 # format result line
@@ -289,8 +303,8 @@ gh_toc_app() {
289303 echo " GitHub TOC generator ($app_name ): $gh_toc_version "
290304 echo " "
291305 echo " Usage:"
292- echo " $app_name [--insert] [--hide-footer] [--indent #spaces] src [src] Create TOC for a README file (url or local path)"
293- echo " $app_name [--no-backup] [--hide-footer] [--indent #spaces] src [src] Create TOC without backup, requires <!--ts--> / <!--te--> placeholders"
306+ echo " $app_name [--insert] [--hide-footer] [--skip-header] [-- indent #spaces] src [src] Create TOC for a README file (url or local path)"
307+ echo " $app_name [--no-backup] [--hide-footer] [--skip-header] [-- indent #spaces] src [src] Create TOC without backup, requires <!--ts--> / <!--te--> placeholders"
294308 echo " $app_name - Create TOC for markdown from STDIN"
295309 echo " $app_name --help Show help"
296310 echo " $app_name --version Show version"
@@ -353,10 +367,16 @@ gh_toc_app() {
353367 shift
354368 fi
355369
370+ if [ " $1 " = ' --skip-header' ]; then
371+ skip_header=" yes"
372+ shift
373+ fi
374+
375+
356376 for md in " $@ "
357377 do
358378 echo " "
359- gh_toc " $md " " $# " " $need_replace " " $no_backup " " $no_footer " " $indent "
379+ gh_toc " $md " " $# " " $need_replace " " $no_backup " " $no_footer " " $indent " " $skip_header "
360380 done
361381
362382 echo " "
0 commit comments