diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-12-17 16:31:24 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-12-17 16:31:24 +0800 |
| commit | fc2db80952f1fc1c77c101fb76b529502016329a (patch) | |
| tree | 0b3f3e6bd5af7b6ccda00d4c399d3a3d14009e51 /src | |
| parent | e372cfff7296e907d257aa4ecbd8400d1ce3bcad (diff) | |
Escape special characters in markdown formatting
The `md` function now handles backslash escapes for specific characters
(*, <, >, `) to allow them to be displayed literally in formatted text.
This fixes rendering of help documentation that uses these characters as
symbols.
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils/display.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/utils/display.rs b/src/utils/display.rs index ca1f3b5..4610f4f 100644 --- a/src/utils/display.rs +++ b/src/utils/display.rs @@ -176,6 +176,24 @@ pub fn md(text: impl AsRef<str>) -> String { let chars: Vec<char> = text.chars().collect(); while i < chars.len() { + // Check for escape character \ + if chars[i] == '\\' && i + 1 < chars.len() { + let escaped_char = chars[i + 1]; + // Only escape specific characters + if matches!(escaped_char, '*' | '<' | '>' | '`') { + let mut escaped_text = escaped_char.to_string(); + + // Apply current color stack + for color in color_stack.iter().rev() { + escaped_text = apply_color(&escaped_text, color); + } + + result.push_str(&escaped_text); + i += 2; + continue; + } + } + // Check for color tag start [[color]] if i + 1 < chars.len() && chars[i] == '[' && chars[i + 1] == '[' { let mut j = i + 2; |
