grip icon indicating copy to clipboard operation
grip copied to clipboard

table of contents?

Open robertmarkbram opened this issue 5 years ago • 2 comments

Is there a way to generate a table of contents when using --export?

Love this tool btw.

robertmarkbram avatar Mar 15 '19 01:03 robertmarkbram

I am using the following in a bash script as a pre-processing step to achieve this atm.

   rm -r temp.md
   touch temp.md
   echo -e "\n\nTOC\n" >> temp.md
   IFS=$'\n';
   for line in $(cat README.md | grep -E '^#+ ') ; do
      heading=$(echo "${line}" | sed -re 's/[ \t]*$//' -e 's/^#+ (.*)$/\1/')
      link=$(echo "${line}" | sed -re 's/[ \t]*$//' -e 's/^#+ (.*)/\1/' -e 's/ /-/g' -e 's/.*/\L&/g')
      bullet=$(echo "${line}" | sed -re 's/^(#*)# .*/\1- /' -e 's/#/  /g')
      echo "${bullet}[${heading}](#${link})" >> temp.md
   done
   echo -e "\n" >> temp.md
   cat README.md >> temp.md
   grip temp.md --export readme.html

robertmarkbram avatar Mar 15 '19 01:03 robertmarkbram

I use doctoc.

t0stiman avatar May 29 '19 07:05 t0stiman