mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-01-29 17:08:01 -05:00
docs: address CodeRabbit review feedback for encoder_block.md
- Expand 'How it works' with technical details (unicode_escape encoding, validation, edge cases) - Add blank lines around tables (MD058) - Add language tags to fenced code blocks (MD040) - Replace 'Possible use case' with 3 structured use cases per docs guidelines - Separate example into its own section
This commit is contained in:
@@ -7,22 +7,31 @@ A tool that converts text containing special characters into escaped text sequen
|
||||
It takes a string of text that contains special characters (like new lines or quotation marks) and converts them into their escape sequence representations (like '\n' for new lines).
|
||||
|
||||
## How it works
|
||||
The Text Encoder examines the input text and identifies special characters. It then replaces these characters with their escape sequence equivalents, making the text safe for storage or transmission in formats that don't support raw special characters.
|
||||
The Text Encoder takes the input string and applies Python's `unicode_escape` encoding (equivalent to `codecs.encode(text, "unicode_escape").decode("utf-8")`) to transform special characters like newlines, tabs, and backslashes into their escaped forms.
|
||||
|
||||
The block relies on the input schema to ensure the value is a string; non-string inputs are rejected by validation, and any encoding failures surface as block errors. Non-ASCII characters are emitted as `\uXXXX` sequences, which is useful for ASCII-only payloads.
|
||||
|
||||
## Inputs
|
||||
|
||||
| Input | Description |
|
||||
|-------|-------------|
|
||||
| Text | The text you want to encode, which may contain special characters like new lines or quotation marks |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Output | Description |
|
||||
|--------|-------------|
|
||||
| Encoded Text | The text after processing, with all special characters converted to their escape sequences |
|
||||
|
||||
## Possible use case
|
||||
## Use Case
|
||||
- **JSON payload preparation:** Encode multiline or quoted text before embedding it in JSON string fields.
|
||||
- **Config/ENV generation:** Convert template text into escaped strings for `.env` or YAML values.
|
||||
- **Snapshot fixtures:** Produce stable escaped strings for golden files or API tests.
|
||||
|
||||
## Example
|
||||
Imagine you have a piece of text with line breaks that you need to store in a JSON file or send through an API:
|
||||
|
||||
```
|
||||
```text
|
||||
Hello
|
||||
World!
|
||||
This is a "quoted" string.
|
||||
@@ -30,7 +39,7 @@ This is a "quoted" string.
|
||||
|
||||
The Text Encoder can convert it into:
|
||||
|
||||
```
|
||||
```text
|
||||
Hello\nWorld!\nThis is a "quoted" string.
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user