Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Table of contents project template from https://learnvanillajs.com.

Project Details

Write a script that generates a table of contents from the headings in a document.

Considerations

  • Which heading levels should you use?
  • Should you only use one heading level, or provide a deep, nested table of contents?
  • Should you like to items in the document or not?
  • If a heading doesn't have an ID, how can you link to it?

Need help?

This project is part of the Writing Plugins pocket guide and video course.

<!DOCTYPE html>
<html>
<head>
<title>Project Template</title>
<style type="text/css">
body {
margin-left: auto;
margin-right: auto;
max-width: 40em;
width: 88%;
}
</style>
</head>
<body>
<h1>Some Document</h1>
<div id="toc"></div>
<h2>Anchor's Away!</h2>
<p>Fore furl holystone mutiny lugsail hempen halter Brethren of the Coast Corsair. Loaded to the gunwalls lookout brig hands blow the man down case shot jolly boat hempen halter. Gun gunwalls chase guns furl hornswaggle dance the hempen jig yard hail-shot. Pressgang quarterdeck prow lugger spanker fluke broadside reef.</p>
<p>Hempen halter me gangplank snow smartly boom fire ship aft. Rope's end draught interloper schooner ho wench jury mast lateen sail. Pillage lanyard nipperkin plunder crack Jennys tea cup hogshead chantey mizzenmast. Spanker blow the man down Buccaneer Sail ho rum tender warp brigantine.</p>
<h2>Man O' War</h2>
<p>Man-of-war booty brigantine fire ship tack no prey, no pay wherry lee. Reef heave to line chandler fore cable smartly me. Avast list spanker Arr fathom American Main lookout grapple. Jolly boat black spot chandler list chantey pinnace brig Yellow Jack.</p>
<p>Chantey Davy Jones' Locker snow jib careen galleon Admiral of the Black lass. Rum booty heave to grog hempen halter gangway long clothes wherry. Mutiny chase Sea Legs grapple crow's nest wherry jury mast lateen sail. Hogshead clap of thunder loot port swing the lead run a rig booty Chain Shot.</p>
<h2>Corsair</h2>
<p>Line Corsair haul wind pink provost hardtack keelhaul hang the jib. Splice the main brace matey hornswaggle strike colors run a shot across the bow cackle fruit hang the jib jack. Sheet bounty wherry nipperkin belay flogging Chain Shot main sheet. Lad Spanish Main barque port smartly Chain Shot deadlights Jack Ketch.</p>
<p>Flogging heave down sloop me squiffy barkadeer loot chantey. Ye spike port lugsail belaying pin nipperkin loot yardarm. Prow gangplank six pounders chase guns pressgang chandler Shiver me timbers piracy. Hearties Shiver me timbers sloop driver fire in the hole gaff prow gally.</p>
<h2>Scallywags be among us</h2>
<p>Fore furl holystone mutiny lugsail hempen halter Brethren of the Coast Corsair. Loaded to the gunwalls lookout brig hands blow the man down case shot jolly boat hempen halter. Gun gunwalls chase guns furl hornswaggle dance the hempen jig yard hail-shot. Pressgang quarterdeck prow lugger spanker fluke broadside reef.</p>
<p>Hempen halter me gangplank snow smartly boom fire ship aft. Rope's end draught interloper schooner ho wench jury mast lateen sail. Pillage lanyard nipperkin plunder crack Jennys tea cup hogshead chantey mizzenmast. Spanker blow the man down Buccaneer Sail ho rum tender warp brigantine.</p>
<h2>The Jolly Roger</h2>
<p>Man-of-war booty brigantine fire ship tack no prey, no pay wherry lee. Reef heave to line chandler fore cable smartly me. Avast list spanker Arr fathom American Main lookout grapple. Jolly boat black spot chandler list chantey pinnace brig Yellow Jack.</p>
<p>Chantey Davy Jones' Locker snow jib careen galleon Admiral of the Black lass. Rum booty heave to grog hempen halter gangway long clothes wherry. Mutiny chase Sea Legs grapple crow's nest wherry jury mast lateen sail. Hogshead clap of thunder loot port swing the lead run a rig booty Chain Shot.</p>
<h2>The Sloop</h2>
<p>Line Corsair haul wind pink provost hardtack keelhaul hang the jib. Splice the main brace matey hornswaggle strike colors run a shot across the bow cackle fruit hang the jib jack. Sheet bounty wherry nipperkin belay flogging Chain Shot main sheet. Lad Spanish Main barque port smartly Chain Shot deadlights Jack Ketch.</p>
<p>Flogging heave down sloop me squiffy barkadeer loot chantey. Ye spike port lugsail belaying pin nipperkin loot yardarm. Prow gangplank six pounders chase guns pressgang chandler Shiver me timbers piracy. Hearties Shiver me timbers sloop driver fire in the hole gaff prow gally.</p>
<h2>Lost Treasure</h2>
<p>Fore furl holystone mutiny lugsail hempen halter Brethren of the Coast Corsair. Loaded to the gunwalls lookout brig hands blow the man down case shot jolly boat hempen halter. Gun gunwalls chase guns furl hornswaggle dance the hempen jig yard hail-shot. Pressgang quarterdeck prow lugger spanker fluke broadside reef.</p>
<p>Hempen halter me gangplank snow smartly boom fire ship aft. Rope's end draught interloper schooner ho wench jury mast lateen sail. Pillage lanyard nipperkin plunder crack Jennys tea cup hogshead chantey mizzenmast. Spanker blow the man down Buccaneer Sail ho rum tender warp brigantine.</p>
<h2>Sea Legs</h2>
<p>Man-of-war booty brigantine fire ship tack no prey, no pay wherry lee. Reef heave to line chandler fore cable smartly me. Avast list spanker Arr fathom American Main lookout grapple. Jolly boat black spot chandler list chantey pinnace brig Yellow Jack.</p>
<p>Chantey Davy Jones' Locker snow jib careen galleon Admiral of the Black lass. Rum booty heave to grog hempen halter gangway long clothes wherry. Mutiny chase Sea Legs grapple crow's nest wherry jury mast lateen sail. Hogshead clap of thunder loot port swing the lead run a rig booty Chain Shot.</p>
<h2>Barnacles and Crustaceans</h2>
<p>Line Corsair haul wind pink provost hardtack keelhaul hang the jib. Splice the main brace matey hornswaggle strike colors run a shot across the bow cackle fruit hang the jib jack. Sheet bounty wherry nipperkin belay flogging Chain Shot main sheet. Lad Spanish Main barque port smartly Chain Shot deadlights Jack Ketch.</p>
<p>Flogging heave down sloop me squiffy barkadeer loot chantey. Ye spike port lugsail belaying pin nipperkin loot yardarm. Prow gangplank six pounders chase guns pressgang chandler Shiver me timbers piracy. Hearties Shiver me timbers sloop driver fire in the hole gaff prow gally.</p>
<script>
// Project code...
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.