Skip to content

Commit b4c1733

Browse files
committed
update
1 parent 41860c0 commit b4c1733

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

docs/en/guide/text-formatting.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Text Formatting
22

3-
This document describes a custom text formatting syntax used in both shell scripts and Jetpack Compose UI development. This syntax allows you to add color and style to your text output using simple tags.
3+
This document describes a custom text formatting syntax used in both shell scripts, module configuration files, and Jetpack Compose UI development. This syntax allows you to add color and style to your text output using simple tags.
44

55
## Overview
66

@@ -57,12 +57,12 @@ echo() {
5757
}
5858
```
5959

60-
**Behavior:**
60+
**Behavior (Shell Script):**
6161

6262
- If the environment variable `MMRL` is set to `"true"`, the `echo` command will print the message as-is, including all formatting tags. This might be useful for debugging or for systems that can interpret these tags directly.
6363
- If `MMRL` is not set to `"true"` (or is set to any other value), the function strips out all custom formatting tags using `sed` before printing the message. The output will be plain text.
6464

65-
**Example:**
65+
**Example (Shell Script):**
6666

6767
```shell
6868
# With MMRL not "true" (default behavior)
@@ -74,6 +74,27 @@ MMRL="true" echo "This is a [color=red]red[color] message with [bold]bold text[b
7474
# Output: This is a [color=red]red[color] message with [bold]bold text[bold].
7575
```
7676

77+
### Module Config (`config.json` in module root)
78+
79+
The custom formatting tags can be used within the `description` field of a module's `config.json` file.
80+
81+
**Note:** Only the `description` field supports this formatting API. It cannot be used with other fields like those in `module.prop`.
82+
83+
```json
84+
{
85+
"name": {
86+
"en": "Systemless module",
87+
"de": "Systemloses Modul"
88+
},
89+
"description": {
90+
"en": "[bg=red]Hello[bg], [color=primary]World[color]!",
91+
"de": "Hallo, [color=green]Welt[color]!"
92+
}
93+
}
94+
```
95+
96+
When an application (like a module manager that supports this format) reads this `config.json`, it would be responsible for parsing the `description` string and rendering the formatted text in its UI, likely using a mechanism similar to the Jetpack Compose `toStyleMarkup()` function.
97+
7798
### Jetpack Compose (`String.toStyleMarkup()`)
7899

79100
The Kotlin extension function `toStyleMarkup()` converts a string containing these formatting tags into an `AnnotatedString`, which can be used to display styled text in Jetpack Compose.
@@ -137,4 +158,4 @@ In the Jetpack Compose implementation (`toStyleMarkup`):
137158
- Styles are applied segment by segment. When a tag is encountered, the style it defines (e.g., `currentColor`, `isBold`) is set and applied to subsequent text until another relevant tag changes it or the string ends.
138159
- There isn't explicit "closing" tag logic like `[/bold]`. Instead, a new tag like `[color=green]` would change the current color from whatever it was previously. For boolean styles like `bold`, `italic`, `underline`, the provided Kotlin code currently only sets them to `true`. To turn them _off_, you would need to modify the parsing logic to handle specific "off" tags (e.g., `[bold=false]`) or a general reset tag if that functionality is desired. The current parser only activates these styles.
139160

140-
For the shell script, the `sed` command simply removes any recognized tag pattern. It does not interpret nesting or apply styles.
161+
For the shell script, the `sed` command simply removes any recognized tag pattern. It does not interpret nesting or apply styles. The same applies to how an application might parse the `config.json`'s `description` field – it would depend on its specific parsing implementation, but would likely follow the Jetpack Compose behavior if aiming for consistency.

0 commit comments

Comments
 (0)