Working with Formatting
Text-like content and table cells both support visual formatting, but through different API shapes, with spans over character ranges for text and a per-cell object for tables.
Beta APIs
The Document APIs are beta. Send the EARLY-ACCESS: true header on every request shown here; without it these endpoints are unavailable. See Introduction to Documents and the Stability Guidelines.
Document content can include visual formatting such as bold font weight, colors, links, and mentions. You can format text-like content and table cells, but the two APIs use different shapes. Text-like content includes text, headers, and list items.
Key properties about formatting:
- Text-like content uses span-based formatting that applies to a range of characters.
- Tables use cell-based formatting that applies to the entire cell.
- The allowed formatting options for text and tables differ slightly. The API documentation details the supported formatting options for each type of content.
Formatting text
Text-like content exposes three parallel arrays:
formats: Applies styling to a character range.links: Applies a link to a character range.mentions: Inserts an item tag at a character position.
For formats and links, start is inclusive and end is exclusive.
When reading text content from the parts listing, each text part returns the same fields:
Formatting tables
Table cells don’t use character ranges. Instead, each cell might include a format object that styles the whole cell.
To format cells, submit an update_table_cells operation in a partsMutation on the document that contains the table. Each cell update targets one cell by rowIndex and columnIndex, both counted from 0. Include inputValue to change the cell’s value as well, or leave it out to keep the existing value. In properties, any style the list leaves out is removed from the cell.
For more on editing tables, including inserting rows, see Working with Tables.
When reading the table’s rows, each cell might include the resolved format object:
To clear a cell’s formatting, send a cell update with format set to null.