<div class='type'>Function</div>


<a id='references'></a>


<h2 id="withannotation-tag-annotation">withAnnotation</h2>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
inline fun <R : Any> Builder.withAnnotation(
    tag: String,
    annotation: String,
    crossinline block: Builder.() -> R,
): R
```


Pushes an annotation to the `AnnotatedString.Builder`, executes `block` and then pops the
annotation.

#### Parameters

| | |
| --- | --- |
| tag | the tag used to distinguish annotations |
| annotation | the string annotation attached on this AnnotatedString |
| block | function to be executed |


#### Returns

| | |
| --- | --- |
|  | result of the `block` |






<hr class="docs-overload-divider">


<h2 id="withannotation-ttsannotation">withAnnotation</h2>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
inline fun <R : Any> Builder.withAnnotation(
    ttsAnnotation: TtsAnnotation,
    crossinline block: Builder.() -> R,
): R
```


Pushes an `TtsAnnotation` to the `AnnotatedString.Builder`, executes `block` and then pops the
annotation.

#### Parameters

| | |
| --- | --- |
| ttsAnnotation | an object that stores text to speech metadata that intended for the TTS engine. |
| block | function to be executed |


#### Returns

| | |
| --- | --- |
|  | result of the `block` |




<div class='sourceset sourceset-common'>Common</div>


> **Deprecated** Use LinkAnnotation API for links instead



<hr class="docs-overload-divider">


<h2 id="withannotation-urlannotation">withAnnotation</h2>

```kotlin
@ExperimentalTextApi
inline fun <R : Any> Builder.withAnnotation(
    urlAnnotation: UrlAnnotation,
    crossinline block: Builder.() -> R,
): R
```


Pushes an `UrlAnnotation` to the `AnnotatedString.Builder`, executes `block` and then pops the
annotation.

#### Parameters

| | |
| --- | --- |
| urlAnnotation | A `UrlAnnotation` object that stores the URL being linked to. |
| block | function to be executed |


#### Returns

| | |
| --- | --- |
|  | result of the `block` |