Obtain the table of contents from copy and pasting (through the PDF viewer (pdf.js seems to be working the best for me))
Work in progress...
Using regular expressions to clean up the table of contents:
^(.*)$ to +$1 # add a + to the beginning of each line
^(.* )([1-9]|[1-9][0-9]|[1-9][0-9][0-9])$ to $1|$2 # add a | before the page number
^(.*)( \.)+(.*)$ to +$1$2$3 # indicate it is the 2nd level of bookmark
\. to '' # remove the ". "