Nodos
Table of contents
Un marcador para un índice, por delante de los renderizadores que lo construyan.
The kind is part of the document schema and both renderers accept it. What is missing is downstream rather than in the authoring: the element places the marker and carries its title, and building the entries from the surrounding section titles is a renderer's job.
- Helpers
- TableOfContents
- Clase de nodo
- tableOfContents
- Categoría
- Estructura
- Se resuelve
- By the renderer
- Hijos
- None. The entries would come from the sections beside it.
| Opción | Tipo | Qué hace |
|---|---|---|
id | string | Stable address for the node. Engines target it and build artifacts diff on it, so treat a rename as a breaking change. Optional: a node without one takes an id from where it sits, which is what keeps branches and loops from forcing you to invent names. Two nodes claiming one id is an error rather than a race. |
title | string | Heading for the list. Renderers fall back to their own wording. |
derivers | DeriverInvocation[] | Values the engine computes before the node resolves, written to derived.* and readable from a template token. Built with derive(). These survive publishing and run per document — use them for anything computed from request data. useDeriver runs one during the build instead. |
Escribir uno
import { TableOfContents } from "docxcelerate/template";
export const Contents: TableOfContents = () => (
<TableOfContents id="contents" title="What is in this document" />
);
Se compone como cualquier otro nodo, y se resuelve igual en compilaciones de
vista previa, en compilaciones del motor y en pruebas. Colocado directamente en
una plantilla no necesita componente propio — <TableOfContents id="contents" title="…" /> es todo.
Lo que falta está aguas abajo
El elemento coloca el marcador y lleva su título. Construir las entradas a partir de los títulos de sección que lo rodean es tarea de un renderizador, y ni la vista previa del navegador ni el empaquetador DOCX lo hacen todavía: ambos imprimen el título y paran.
Por qué colocar una ya
Cuesta una línea, y empieza a imprimir entradas el día en que los renderizadores las construyan. La alternativa — una lista de títulos de sección mantenida a mano dentro de un párrafo — estará equivocada en dos versiones.
Si prefieres no publicar un nodo que solo imprime un encabezado, déjalo fuera. Añadirlo más adelante es igual de barato.
Variantes
A titled marker
src/nodes/table-of-contents/basic.node.tsx The element, and the title it carries into the document.
import { TableOfContents } from "docxcelerate/template";
/**
* A heading standing in for the contents of the document around it.
*
* The shipped renderers print the title and stop — the entries themselves are
* a renderer's job, and neither the browser preview nor the DOCX packer builds
* them yet.
*/
export const Contents: TableOfContents = () => (
<TableOfContents id="contents" title="What is in this letter" />
); En qué se resuelve
El nodo tal como aparece en el DocumentModel: el JSON que recibe un renderizador. Sin estilos, sin maquetación.
{
"id": "contents",
"kind": "tableOfContents",
"title": "What is in this letter"
} Notas
titlees opcional; los renderizadores recurren a su propia redacción.- El nodo no contiene hijos y no lee nada en tiempo de compilación.