createSectionHeading

fun Heading.Companion.createSectionHeading(title: InlineContent?, localizationKey: String, context: Context, depth: Int = 1, customId: String? = null, canBreakPage: Boolean = true, canTrackLocation: Boolean = false, includeInTableOfContents: Boolean = false): Heading?

Creates an auto-generated Heading for a structural section of the document (e.g. table of contents, bibliography).

The heading title is resolved from:

  1. A user-provided title, if not null and not empty.

  2. A localized fallback from localizationKey, if title is null.

  3. If neither resolves to text, the heading is still created with empty text when customId is set (to serve as a referenceable anchor), or omitted (null) otherwise.

An explicitly empty title means no heading should be displayed at all.

The resulting heading is marked with Heading.excludeFromTableOfContents to prevent self-referencing in the document's table of contents.

Return

a Heading node, or null if title is explicitly empty or no title could be resolved and no customId is provided

Parameters

title

user-provided title content. If null, the default localized title from localizationKey is used. If empty, no heading is created.

localizationKey

key to look up the default localized title if title is null

context

context for localization

depth

depth of the heading (1-6)

customId

optional custom ID for cross-referencing. If set and no title is resolved, the heading is still created with empty text to act as an anchor

canBreakPage

whether the heading can trigger an automatic page break

canTrackLocation

whether the heading's position should be tracked and numbered. Implicitly enabled when includeInTableOfContents is true.

includeInTableOfContents

whether this heading should be indexed in the document's table of contents. Implicitly enables canTrackLocation.