Parse/render
<text:h>— paragraph withtext:outline-level.
Module textHeading | Source packages/front/office/odf/src/text/heading.js | Deps xml, textParagraph | Worker-safe yes
Model:
{ type: 'heading', outlineLevel: 1..10, styleName?, runs: [<run>...], _extras? }
Runs are exactly textParagraph's runs — same kinds, same fields:
| Kind | Extra field | ODF element |
|---|---|---|
text |
value |
(inline text) |
span |
value, styleName?, bold?, italic?, strike?, monospace?, runs?, _extras? |
<text:span> |
space |
count |
<text:s text:c="N"/> |
tab |
— | <text:tab/> |
line-break |
— | <text:line-break/> |
link |
href, runs, _extras? |
<text:a> |
The span emphasis flags and the link run kind — including the write-side
precedence rule (an explicit styleName wins; the flags are consulted only
when styleName is absent) — are defined once, in
text/paragraph. This module adds no run semantics of its own.
Resolve
const heading = runtime.resolve('textHeading');
// → { parseHeading, renderHeading, heading }
API
| Method | Description |
|---|---|
parseHeading(el, ctx?) |
Converts a <text:h> node into the model (re-uses paragraph run parsing). ctx is forwarded verbatim. |
renderHeading(h, ctx?) |
Builds a <text:h> node. ctx is forwarded verbatim. |
heading(text, { outlineLevel?, styleName? }) |
Helper — builds a single-text-run heading. |
Examples
const hd = heading.heading('Chapter 1', { outlineLevel: 1, styleName: 'H1' });
heading.renderHeading(hd);
Notes
- Run parsing/rendering is delegated to
textParagraph;outlineLeveldefaults to1when thetext:outline-levelattribute is missing or non-positive. - Attributes — as for paragraphs, every
<text:h>attribute other thantext:style-nameandtext:outline-level(text:is-list-header,xml:id, …) is preserved verbatim in_extras.attrsand re-emitted on write. The outline level is typed once (outlineLevel), never carried in_extras.attrs, so a changedoutlineLevelis what gets written. heading()mirrorstextParagraph.paragraph()'s helper shape, adding the requiredoutlineLevel.ctxpass-through — the optional trailingctx(thetextStyleRegistrystyle seam built byodt: a resolver on read, a registry on write) is forwarded unchanged toparseParagraph/renderParagraph. Called without actx— as theodp/odspaths do — behaviour is unchanged: emphasis flags degrade to a plain unstyled<text:span>with the text intact. See text/paragraph § thectxstyle seam.