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.rsindex 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 splitlet 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.snapindex 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 [2m+[0m Staged files[2m![0m Modified files (unstaged)[2m?[0m Untracked files@@ -127,7 +127,7 @@ Symbols appear in the Status column in this order:[2m↑[0m Ahead of main[2m↓[0m Behind main[2m↕[0m Diverged from main- Remote divergence [2m\[0m [2m[0m In sync with remote+ Remote divergence [2m|[0m In sync with remote[2m⇡[0m Ahead of remote[2m⇣[0m Behind remote[2m⇅[0m Diverged from remote