ToC in HTML with VSC

the case

  • Add table of content to an HTML article in VSC

solution

  • Find <h2>
  • Replace by one to <h2 id="n">

  • Find all <h2.*
  • Select all matches
  • Copy all matches –
  • Paste all matches into a separate throw-away file

  • remove all tags and keep just the titles either by an emmet command remove tag or by a regex
    • find <h2 id=".*">(.*)</h2>
    • replace: $1

  • Copy the chapter names into a proper section of the document
  • Use Wrap individual lines with Abbreviation Command and as a command insert
    • ul>li*>a

  • Find <a href="">
  • Replace-by-one to <a href="n"> where n is an ordinal from 1 to 13

Result

Leave a Reply

Your email address will not be published. Required fields are marked *