Basic usage
To annotate text within a block:Text annotations
Text annotations highlight a range of characters within a RichText field.Range positions
Thestart and end positions are calculated based only on the text content, ignoring HTML formatting:
RichText identifier
TherichTextIdentifier specifies which RichText instance to annotate:
- Paragraph block:
content - Quote block citation:
citation - Quote block content:
value
Example: Annotating text
Block annotations
Annotate an entire block by settingselector to block:
Styling block annotations
Block annotations require custom CSS:.is-annotated-by-{source}
API reference
addAnnotation
Adds a new annotation. Parameters:string
required
Unique identifier for the annotation source (e.g., your plugin name)
string
required
Client ID of the block to annotate
string
Identifier of the RichText field (required for text annotations)
object
Text range to annotate (required for text annotations)Properties:
start(number): Start positionend(number): End position
string
default:"range"
Annotation type:
range for text or block for entire blockWorking with positions
Usewp.richText.create to help determine correct positions:
Complete example
A spellcheck plugin that annotates misspelled words:Limitations
- Text annotations only work with RichText fields
- Positions must be calculated carefully based on text content only
- Block annotations require custom CSS
- The API is experimental and may change