# `gradio_highlightedtextbox`
Editable Gradio textarea supporting highlighting
## Installation
```bash
pip install gradio_highlightedtextbox
```
## Usage
```python
import gradio as gr
from gradio_highlightedtextbox import HighlightedTextbox
def convert_tagged_text_to_highlighted_text(
tagged_text: str,
tag_id: str | list[str],
tag_open: str | list[str],
tag_close: str | list[str],
) -> list[tuple[str, str | None]]:
return HighlightedTextbox.tagged_text_to_tuples(
tagged_text, tag_id, tag_open, tag_close
)
def convert_highlighted_text_to_tagged_text(
highlighted_text: dict[str, str | list[tuple[str, str | None]]],
tag_id: str | list[str],
tag_open: str | list[str],
tag_close: str | list[str],
) -> str:
return HighlightedTextbox.tuples_to_tagged_text(
highlighted_text["data"], tag_id, tag_open, tag_close
)
def show_info(
highlighted_text: dict[str, str | list[tuple[str, str | None]]],
tag_id: str | list[str],
tag_open: str | list[str],
tag_close: str | list[str],
msg: str,
) -> None:
gr.Info(
f"{msg}: {HighlightedTextbox.tuples_to_tagged_text(highlighted_text['data'], tag_id, tag_open, tag_close)}"
)
initial_text = "It is not something to be ashamed of: it is no different from the personal fears and dislikes of other things that
name | type | default | description |
---|---|---|---|
value |
```python list[tuple[str, str | None]] | Callable | None ``` | "" |
default text to provide in textbox. If callable, the function will be called whenever the app loads to set the initial value of the component. |
color_map |
```python dict[str, str] | None ``` | None |
dictionary mapping labels to colors. |
show_legend |
```python bool ``` | False |
if True, will display legend. |
show_legend_label |
```python bool ``` | False |
if True, will display legend label. |
legend_label |
```python str ``` | "" |
label to display above legend. |
combine_adjacent |
```python bool ``` | False |
if True, will combine adjacent spans with the same label. |
adjacent_separator |
```python str ``` | "" |
separator to use when combining adjacent spans. |
label |
```python str | None ``` | None |
component name in interface. |
info |
```python str | None ``` | None |
None |
every |
```python float | None ``` | None |
If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute. |
show_label |
```python bool | None ``` | None |
if True, will display label. |
container |
```python bool ``` | True |
If True, will place the component in a container - providing some extra padding around the border. |
scale |
```python int | None ``` | None |
relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer. |
min_width |
```python int ``` | 160 |
minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first. |
visible |
```python bool ``` | True |
If False, component will be hidden. |
elem_id |
```python str | None ``` | None |
An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. |
autofocus |
```python bool ``` | False |
None |
autoscroll |
```python bool ``` | True |
If True, will automatically scroll to the bottom of the textbox when the value changes, unless the user scrolls up. If False, will not scroll to the bottom of the textbox when the value changes. |
interactive |
```python bool ``` | True |
if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output. |
elem_classes |
```python list[str] | str | None ``` | None |
An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles. |
render |
```python bool ``` | True |
If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later. |
show_copy_button |
```python bool ``` | False |
If True, includes a copy button to copy the text in the textbox. Only applies if show_label is True. |
show_remove_tags_button |
```python bool ``` | False |
If True, includes a button to remove all tags from the text. |