You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/guide/text-formatting.md
+25-4Lines changed: 25 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Text Formatting
2
2
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.
4
4
5
5
## Overview
6
6
@@ -57,12 +57,12 @@ echo() {
57
57
}
58
58
```
59
59
60
-
**Behavior:**
60
+
**Behavior (Shell Script):**
61
61
62
62
- 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.
63
63
- 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.
64
64
65
-
**Example:**
65
+
**Example (Shell Script):**
66
66
67
67
```shell
68
68
# 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
74
74
# Output: This is a [color=red]red[color] message with [bold]bold text[bold].
75
75
```
76
76
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`.
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
+
77
98
### Jetpack Compose (`String.toStyleMarkup()`)
78
99
79
100
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`):
137
158
- 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.
138
159
- 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.
139
160
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