The table of contents block automatically generates a table of contents with links to the corresponding positions on the page from the headings used.
Lorem ipsum dolor sit amet adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Lorem ipsum dolor sit amet adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
Text can be bold or italic.
{
"toc": {
"blockSchema": {
"properties": {
"title": {
"title": "Title"
},
"hide_title": {
"title": "Hide title",
"type": "boolean"
},
"ordered": {
"title": "Ordered",
"type": "boolean"
},
"levels": {
"title": "Entries",
"isMulti": true,
"choices": [
[
"h1",
"h1"
],
[
"h2",
"h2"
],
[
"h3",
"h3"
],
[
"h4",
"h4"
],
[
"h5",
"h5"
],
[
"h6",
"h6"
]
]
}
}
}
}
}
{
"@type": "toc",
"title": "On this page",
"hide_title": false,
"ordered": false,
"levels": [
"h2",
"h3"
]
}
function TocBlock({ block, content }) {
const entries = [];
if (content?.blocks && content?.blocks_layout?.items) {
for (const id of content.blocks_layout.items) {
const b = content.blocks[id];
if (!b) continue;
if (b['@type'] === 'heading' && b.heading) {
entries.push({ id, level: parseInt((b.tag || 'h2').slice(1)), text: b.heading });
} else if (b['@type'] === 'slate' && b.value?.[0]?.type?.match(/^h[1-6]$/)) {
const level = parseInt(b.value[0].type.slice(1));
const text = b.plaintext || b.value[0].children?.map(c => c.text).join('') || '';
if (text.trim()) entries.push({ id, level, text });
}
}
}
return (
<nav data-block-uid={block['@uid']} className="toc-block">
{entries.length > 0 ? (
<ul>
{entries.map(e => (
<li key={e.id} style={{ marginLeft: `${(e.level - 2) * 1.5}em` }}>
<a href={`#${e.id}`}>{e.text}</a>
</li>
))}
</ul>
) : (
<p>Table of Contents</p>
)}
</nav>
);
}<template>
<nav :data-block-uid="block['@uid']" class="toc-block">
<ul v-if="entries.length">
<li v-for="e in entries" :key="e.id" :style="{ marginLeft: (e.level - 2) * 1.5 + 'em' }">
<a :href="`#${e.id}`">{{ e.text }}</a>
</li>
</ul>
<p v-else>Table of Contents</p>
</nav>
</template>
<script setup>
import { computed } from 'vue';
const props = defineProps({ block: Object, content: Object });
const entries = computed(() => {
const result = [];
const c = props.content;
if (!c?.blocks || !c?.blocks_layout?.items) return result;
for (const id of c.blocks_layout.items) {
const b = c.blocks[id];
if (!b) continue;
if (b['@type'] === 'heading' && b.heading) {
result.push({ id, level: parseInt((b.tag || 'h2').slice(1)), text: b.heading });
} else if (b['@type'] === 'slate' && b.value?.[0]?.type?.match(/^h[1-6]$/)) {
const level = parseInt(b.value[0].type.slice(1));
const text = b.plaintext || b.value[0].children?.map(c => c.text).join('') || '';
if (text.trim()) result.push({ id, level, text });
}
}
return result;
});
</script><script>
export let block;
export let content = {};
$: entries = (() => {
const result = [];
if (!content?.blocks || !content?.blocks_layout?.items) return result;
for (const id of content.blocks_layout.items) {
const b = content.blocks[id];
if (!b) continue;
if (b['@type'] === 'heading' && b.heading) {
result.push({ id, level: parseInt((b.tag || 'h2').slice(1)), text: b.heading });
} else if (b['@type'] === 'slate' && b.value?.[0]?.type?.match(/^h[1-6]$/)) {
const level = parseInt(b.value[0].type.slice(1));
const text = b.plaintext || b.value[0].children?.map(c => c.text).join('') || '';
if (text.trim()) result.push({ id, level, text });
}
}
return result;
})();
</script>
<nav data-block-uid={block['@uid']} class="toc-block">
{#if entries.length > 0}
<ul>
{#each entries as e (e.id)}
<li style="margin-left: {(e.level - 2) * 1.5}em">
<a href="#{e.id}">{e.text}</a>
</li>
{/each}
</ul>
{:else}
<p>Table of Contents</p>
{/if}
</nav>
{
"toc": {
"blockSchema": {
"properties": {
"title": {
"title": "Title"
},
"hide_title": {
"title": "Hide title",
"type": "boolean"
},
"ordered": {
"title": "Ordered",
"type": "boolean"
},
"levels": {
"title": "Entries",
"isMulti": true,
"choices": [
[
"h1",
"h1"
],
[
"h2",
"h2"
],
[
"h3",
"h3"
],
[
"h4",
"h4"
],
[
"h5",
"h5"
],
[
"h6",
"h6"
]
]
}
}
}
}
}
{
"@type": "toc",
"title": "On this page",
"hide_title": false,
"ordered": false,
"levels": [
"h2",
"h3"
]
}
function TocBlock({ block, content }) {
const entries = [];
if (content?.blocks && content?.blocks_layout?.items) {
for (const id of content.blocks_layout.items) {
const b = content.blocks[id];
if (!b) continue;
if (b['@type'] === 'heading' && b.heading) {
entries.push({ id, level: parseInt((b.tag || 'h2').slice(1)), text: b.heading });
} else if (b['@type'] === 'slate' && b.value?.[0]?.type?.match(/^h[1-6]$/)) {
const level = parseInt(b.value[0].type.slice(1));
const text = b.plaintext || b.value[0].children?.map(c => c.text).join('') || '';
if (text.trim()) entries.push({ id, level, text });
}
}
}
return (
<nav data-block-uid={block['@uid']} className="toc-block">
{entries.length > 0 ? (
<ul>
{entries.map(e => (
<li key={e.id} style={{ marginLeft: `${(e.level - 2) * 1.5}em` }}>
<a href={`#${e.id}`}>{e.text}</a>
</li>
))}
</ul>
) : (
<p>Table of Contents</p>
)}
</nav>
);
}<template>
<nav :data-block-uid="block['@uid']" class="toc-block">
<ul v-if="entries.length">
<li v-for="e in entries" :key="e.id" :style="{ marginLeft: (e.level - 2) * 1.5 + 'em' }">
<a :href="`#${e.id}`">{{ e.text }}</a>
</li>
</ul>
<p v-else>Table of Contents</p>
</nav>
</template>
<script setup>
import { computed } from 'vue';
const props = defineProps({ block: Object, content: Object });
const entries = computed(() => {
const result = [];
const c = props.content;
if (!c?.blocks || !c?.blocks_layout?.items) return result;
for (const id of c.blocks_layout.items) {
const b = c.blocks[id];
if (!b) continue;
if (b['@type'] === 'heading' && b.heading) {
result.push({ id, level: parseInt((b.tag || 'h2').slice(1)), text: b.heading });
} else if (b['@type'] === 'slate' && b.value?.[0]?.type?.match(/^h[1-6]$/)) {
const level = parseInt(b.value[0].type.slice(1));
const text = b.plaintext || b.value[0].children?.map(c => c.text).join('') || '';
if (text.trim()) result.push({ id, level, text });
}
}
return result;
});
</script><script>
export let block;
export let content = {};
$: entries = (() => {
const result = [];
if (!content?.blocks || !content?.blocks_layout?.items) return result;
for (const id of content.blocks_layout.items) {
const b = content.blocks[id];
if (!b) continue;
if (b['@type'] === 'heading' && b.heading) {
result.push({ id, level: parseInt((b.tag || 'h2').slice(1)), text: b.heading });
} else if (b['@type'] === 'slate' && b.value?.[0]?.type?.match(/^h[1-6]$/)) {
const level = parseInt(b.value[0].type.slice(1));
const text = b.plaintext || b.value[0].children?.map(c => c.text).join('') || '';
if (text.trim()) result.push({ id, level, text });
}
}
return result;
})();
</script>
<nav data-block-uid={block['@uid']} class="toc-block">
{#if entries.length > 0}
<ul>
{#each entries as e (e.id)}
<li style="margin-left: {(e.level - 2) * 1.5}em">
<a href="#{e.id}">{e.text}</a>
</li>
{/each}
</ul>
{:else}
<p>Table of Contents</p>
{/if}
</nav>
{
"toc": {
"blockSchema": {
"properties": {
"title": {
"title": "Title"
},
"hide_title": {
"title": "Hide title",
"type": "boolean"
},
"ordered": {
"title": "Ordered",
"type": "boolean"
},
"levels": {
"title": "Entries",
"isMulti": true,
"choices": [
[
"h1",
"h1"
],
[
"h2",
"h2"
],
[
"h3",
"h3"
],
[
"h4",
"h4"
],
[
"h5",
"h5"
],
[
"h6",
"h6"
]
]
}
}
}
}
}
{
"@type": "toc",
"title": "On this page",
"hide_title": false,
"ordered": false,
"levels": [
"h2",
"h3"
]
}
function TocBlock({ block, content }) {
const entries = [];
if (content?.blocks && content?.blocks_layout?.items) {
for (const id of content.blocks_layout.items) {
const b = content.blocks[id];
if (!b) continue;
if (b['@type'] === 'heading' && b.heading) {
entries.push({ id, level: parseInt((b.tag || 'h2').slice(1)), text: b.heading });
} else if (b['@type'] === 'slate' && b.value?.[0]?.type?.match(/^h[1-6]$/)) {
const level = parseInt(b.value[0].type.slice(1));
const text = b.plaintext || b.value[0].children?.map(c => c.text).join('') || '';
if (text.trim()) entries.push({ id, level, text });
}
}
}
return (
<nav data-block-uid={block['@uid']} className="toc-block">
{entries.length > 0 ? (
<ul>
{entries.map(e => (
<li key={e.id} style={{ marginLeft: `${(e.level - 2) * 1.5}em` }}>
<a href={`#${e.id}`}>{e.text}</a>
</li>
))}
</ul>
) : (
<p>Table of Contents</p>
)}
</nav>
);
}<template>
<nav :data-block-uid="block['@uid']" class="toc-block">
<ul v-if="entries.length">
<li v-for="e in entries" :key="e.id" :style="{ marginLeft: (e.level - 2) * 1.5 + 'em' }">
<a :href="`#${e.id}`">{{ e.text }}</a>
</li>
</ul>
<p v-else>Table of Contents</p>
</nav>
</template>
<script setup>
import { computed } from 'vue';
const props = defineProps({ block: Object, content: Object });
const entries = computed(() => {
const result = [];
const c = props.content;
if (!c?.blocks || !c?.blocks_layout?.items) return result;
for (const id of c.blocks_layout.items) {
const b = c.blocks[id];
if (!b) continue;
if (b['@type'] === 'heading' && b.heading) {
result.push({ id, level: parseInt((b.tag || 'h2').slice(1)), text: b.heading });
} else if (b['@type'] === 'slate' && b.value?.[0]?.type?.match(/^h[1-6]$/)) {
const level = parseInt(b.value[0].type.slice(1));
const text = b.plaintext || b.value[0].children?.map(c => c.text).join('') || '';
if (text.trim()) result.push({ id, level, text });
}
}
return result;
});
</script><script>
export let block;
export let content = {};
$: entries = (() => {
const result = [];
if (!content?.blocks || !content?.blocks_layout?.items) return result;
for (const id of content.blocks_layout.items) {
const b = content.blocks[id];
if (!b) continue;
if (b['@type'] === 'heading' && b.heading) {
result.push({ id, level: parseInt((b.tag || 'h2').slice(1)), text: b.heading });
} else if (b['@type'] === 'slate' && b.value?.[0]?.type?.match(/^h[1-6]$/)) {
const level = parseInt(b.value[0].type.slice(1));
const text = b.plaintext || b.value[0].children?.map(c => c.text).join('') || '';
if (text.trim()) result.push({ id, level, text });
}
}
return result;
})();
</script>
<nav data-block-uid={block['@uid']} class="toc-block">
{#if entries.length > 0}
<ul>
{#each entries as e (e.id)}
<li style="margin-left: {(e.level - 2) * 1.5}em">
<a href="#{e.id}">{e.text}</a>
</li>
{/each}
</ul>
{:else}
<p>Table of Contents</p>
{/if}
</nav>