editContent
Reads and edits content of the specified type from the user's design.
Parameters
options
EditContentOptions
RequiredOptions for configuring how a design is read.
contentType
ContentType
RequiredThe type of content to edit from the user's design
This must be "richtext"
.
target
string
RequiredThis must be "current_page"
.
callback
EditContentCallback
RequiredA callback for operating on the read content.
Parameters
session
object
RequiredThe result of reading the content in the design.
contents
RichtextContentRange[]
RequiredThe individual content items returned by a query.
deleted
boolean
RequiredIndicates whether the object containing this richtext range has been deleted.
formatParagraph
function
RequiredFormats all of the paragraphs that overlap the given bounds.
- The
\n
character indicates the end of a paragraph. - All paragraphs that overlap the provided bounds will be formatted in their entirety.
Parameters
bounds
Bounds
RequiredThe segment of the range on which to apply the formatting.
index
number
RequiredThe starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
RequiredThe number of characters in the segment, starting from the index.
formatting
RichtextFormatting
RequiredThe formatting to apply to the paragraph(s).
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
fontRef
FontRef
OptionalA unique identifier that points to a font asset in Canva's backend.
fontSize
number
OptionalThe size of the text, in pixels.
- In the Canva editor, this number is shown as points (pts), not pixels.
Minimum: 1
Maximum: 100
textAlign
string
OptionalThe alignment of the text.
Default value: "start"
Available values:
"start"
"center"
"end"
"justify"
listLevel
number
OptionalThe list indentation level of the paragraph.
listMarker
string
OptionalThe appearance of list item markers.
This property only has an effect if listLevel
is greater than 0.
Default value: "none"
Available values:
"none"
"disc"
"circle"
"square"
"decimal"
"lower-alpha"
"lower-roman"
"checked"
"unchecked"
Returns
void
formatText
function
RequiredFormats a region of text with inline formatting properties.
Parameters
bounds
Bounds
RequiredThe segment of the range on which to apply the formatting.
index
number
RequiredThe starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
RequiredThe number of characters in the segment, starting from the index.
formatting
InlineFormatting
RequiredThe formatting to apply to the text.
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
Returns
void
appendText
function
RequiredAppends the specified characters to the end of the range.
Parameters
characters
string
RequiredThe characters to append to the richtext range.
formatting
InlineFormatting
OptionalOptions for formatting inline richtext.
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
Returns
bounds
Bounds
A segment of a richtext range.
index
number
The starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
The number of characters in the segment, starting from the index.
replaceText
function
RequiredReplaces a region of text with the specified characters.
Parameters
bounds
Bounds
RequiredThe segment of the range to replace.
index
number
RequiredThe starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
RequiredThe number of characters in the segment, starting from the index.
characters
string
RequiredThe replacement characters.
formatting
InlineFormatting
OptionalThe formatting to apply to the replaced text.
color
string
OptionalThe color of the text as a hex code.
The hex code must include all six characters and be prefixed with a #
symbol.
Example
"#ff0099"
fontWeight
FontWeight
OptionalThe weight (thickness) of the font.
The available font weights depend on the font.
Default value: "normal"
Available values:
"normal"
"thin"
"extralight"
"light"
"medium"
"semibold"
"bold"
"ultrabold"
"heavy"
fontStyle
string
OptionalThe style of the font.
Default value: "normal"
Available values:
"normal"
"italic"
decoration
string
OptionalThe decoration of the text.
Default value: "none"
Available values:
"none"
"underline"
strikethrough
string
OptionalThe strikethrough of the text.
Default value: "none"
Available values:
"none"
"strikethrough"
link
string
OptionalAn external URL that the text links to.
Returns
bounds
Bounds
The bounds of the replacement characters within the updated range.
index
number
The starting position of the segment.
This is zero-based, meaning the first character of the range is at index 0.
length
number
The number of characters in the segment, starting from the index.
readPlaintext
function
RequiredReturns the current state of the richtext as plaintext.
Returns
string
readTextRegions
function
RequiredReturns the current state of the richtext as one or more text regions. Each region is an object that contains the text content and its formatting.
Returns
text
string
The plaintext content of the region.
formatting
Partial<RichtextFormatting>
OptionalThe formatting of the region.
sync
function
RequiredCommits any changes made to the items in the contents
array.
An app must call this method for any changes to be reflected in the user's design.
Returns
Promise<void>
Returns
void
or Promise<void>
Returns
Promise<void>