Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

Handle escaped pipes in markdown table cells

Maximilian Roose14da39d285f
diff --git a/src/md_help.rs b/src/md_help.rs
index 6a419899c..b9ec6cd9b 100644
--- a/src/md_help.rs
+++ b/src/md_help.rs
@@ -83,11 +83,19 @@ fn render_table(lines: &[&str]) -> String {
let mut rows: Vec<Vec<String>> = Vec::new();
let mut separator_idx: Option<usize> = None;
+ // Placeholder for escaped pipes (use a character sequence unlikely to appear)
+ const ESCAPED_PIPE_PLACEHOLDER: &str = "\x00PIPE\x00";
+
for (idx, line) in lines.iter().enumerate() {
let trimmed = line.trim();
// Remove leading/trailing pipes and split
let inner = trimmed.trim_start_matches('|').trim_end_matches('|');
- let cells: Vec<String> = inner.split('|').map(|s| s.trim().to_string()).collect();
+ // Replace escaped pipes before splitting, then restore after
+ let inner_escaped = inner.replace("\\|", ESCAPED_PIPE_PLACEHOLDER);
+ let cells: Vec<String> = inner_escaped
+ .split('|')
+ .map(|s| s.trim().replace(ESCAPED_PIPE_PLACEHOLDER, "|").to_string())
+ .collect();
// Check if this is the separator row (contains only dashes and colons)
if cells
@@ -401,4 +409,21 @@ mod tests {
"\u{1b}[1mbold\u{1b}[0m and \u{1b}[2mcode\u{1b}[0m"
);
}
+
+ #[test]
+ fn test_render_table_escaped_pipe() {
+ // In markdown tables, \| represents a literal pipe character
+ let lines = vec![
+ "| Category | Symbol | Meaning |",
+ "| --- | --- | --- |",
+ "| Remote | `\\|` | In sync |",
+ ];
+ let result = render_table(&lines);
+ // The \| should be rendered as | (pipe character)
+ assert!(result.contains("|"), "Escaped pipe should render as |");
+ assert!(
+ !result.contains("\\|"),
+ "Escaped sequence should not appear literally"
+ );
+ }
}
diff --git a/tests/snapshots/integration__integration_tests__help__help_list_long.snap b/tests/snapshots/integration__integration_tests__help__help_list_long.snap
index fe4e644af..37f7042bc 100644
--- a/tests/snapshots/integration__integration_tests__help__help_list_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_list_long.snap
@@ -113,7 +113,7 @@ Any CI dot appears dimmed when there are unpushed local changes (stale status).
Symbols appear in the Status column in this order:
Category Symbol Meaning
- ───────────────── ────── ────────────────────────────────────────────── ───────────────────
+ ───────────────── ────── ──────────────────────────────────────────────
Working tree + Staged files
! Modified files (unstaged)
? Untracked files
@@ -127,7 +127,7 @@ Symbols appear in the Status column in this order:
↑ Ahead of main
↓ Behind main
↕ Diverged from main
- Remote divergence \  In sync with remote
+ Remote divergence | In sync with remote
⇡ Ahead of remote
⇣ Behind remote
⇅ Diverged from remote