6.0.2 • Published 4 months ago

@svelte-put/toc v6.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@svelte-put/toc

npm.badge bundlephobia.badge docs.badge repl.badge

Svelte use:toc action for building table of contents

svelte-put

This package is part of the @svelte-put family. For contributing guideline and more, refer to its readme.

Usage & Documentation

See the dedicated documentation page here.

Quick Start

<!-- input.svelte -->
<script>
	import { Toc } from '@svelte-put/toc';

	const toc = new Toc({ observe: true });
</script>

<main use:toc.actions.root>
	<h1>Page Heading</h1>

	<section>
		<h2>Table of Contents</h2>
		{#if toc.items.size}
		<ul>
			{#each toc.items.values() as tocItem (tocItem.id)}
			<li>
				<!-- svelte-ignore a11y_missing_attribute -->
				<a use:toc.actions.link="{tocItem}">
					<!-- textContent injected by toc -->
				</a>
			</li>
			{/each}
		</ul>
		{/if}
	</section>

	<section>
		<h2>Section Heading Level 2</h2>
		<p>...</p>
	</section>

	<section>
		<h3>Section Heading Level 3</h3>
		<p>...</p>
	</section>
</main>

will render...

<!-- output.html -->
<main
	data-toc-observe-for="page-heading"
	data-toc-root="ee4f13a3-dfec-401d-b52c-a52550e20ddf"
	data-toc-observe-active-id="section-heading-level-3"
>
	<h1 id="page-heading" data-toc="">
		<a aria-hidden="true" tabindex="-1" href="#page-heading" data-toc-anchor="">#</a>Page Heading
	</h1>
	<section data-toc-observe-for="table-of-contents">
		<h2 id="table-of-contents" data-toc="">
			<a aria-hidden="true" tabindex="-1" href="#table-of-contents" data-toc-anchor="">#</a>Table of
			Contents
		</h2>
		<ul>
			<li>
				<a href="#page-heading" data-toc-link-for="page-heading" data-toc-link-current="false"
					>Page Heading</a
				>
			</li>
			<li>
				<a
					href="#table-of-contents"
					data-toc-link-for="table-of-contents"
					data-toc-link-current="false"
					>Table of Contents</a
				>
			</li>
			<li>
				<a
					href="#section-heading-level-2"
					data-toc-link-for="section-heading-level-2"
					data-toc-link-current="false"
					>Section Heading Level 2</a
				>
			</li>
			<li>
				<a
					href="#section-heading-level-3"
					data-toc-link-for="section-heading-level-3"
					data-toc-link-current="true"
					>Section Heading Level 3</a
				>
			</li>
		</ul>
	</section>
	<section data-toc-observe-for="section-heading-level-2">
		<h2 id="section-heading-level-2" data-toc="">
			<a aria-hidden="true" tabindex="-1" href="#section-heading-level-2" data-toc-anchor="">#</a
			>Section Heading Level 2
		</h2>
		<p>...</p>
	</section>
	<section data-toc-observe-for="section-heading-level-3">
		<h3 id="section-heading-level-3" data-toc="">
			<a aria-hidden="true" tabindex="-1" href="#section-heading-level-3" data-toc-anchor="">#</a
			>Section Heading Level 3
		</h3>
		<p>...</p>
	</section>
</main>

Acknowledgement

This package relies on svelte action strategy and attempts to stay minimal. If you are looking for a declarative, component-oriented solution, check out Janosh's svelte-toc.

Changelog

6.0.1

5 months ago

6.0.2

4 months ago

6.0.0

9 months ago

6.0.0-next.0

1 year ago

6.0.0-next.1

1 year ago

6.0.0-next.2

1 year ago

6.0.0-next.3

1 year ago

6.0.0-next.4

1 year ago

6.0.0-next.5

1 year ago

6.0.0-next.6

11 months ago

5.0.2

1 year ago

5.0.1

1 year ago

5.0.0

1 year ago

3.0.3

2 years ago

4.0.0

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.3

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.4

2 years ago

2.1.0

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago