Merge pull request #947 from Likio3000/codex/fix-markdown-backticks

Preserve backticks in Markdown command names
This commit is contained in:
David Peter authored and GitHub committed 2026-10-05 12:11:51 +02:00
commit 0a61e330cf
2 files changed
+50 -1

No files matched your search

+29 -1
View File
@@ -24,7 +24,19 @@ impl MarkupExporter for MarkdownExporter {
}
fn command(&self, cmd: &str) -> String {
format!("`{cmd}`")
let longest_backtick_run = cmd
.split(|character| character != '`')
.map(str::len)
.max()
.unwrap_or(0);
if longest_backtick_run == 0 {
format!("`{cmd}`")
} else {
// Use a longer delimiter and keep command backticks separate from it.
let delimiter = "`".repeat(longest_backtick_run + 1);
format!("{delimiter} {cmd} {delimiter}")
}
}
}
@@ -44,3 +56,19 @@ fn test_markdown_formatter_table_divider() {
let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);
assert_eq!(divider, "|:---|---:|:---|\n");
}
#[test]
fn test_markdown_formatter_command_with_backticks() {
let formatter = MarkdownExporter::default();
for (command, expected) in [
("echo `uname`", "`` echo `uname` ``"),
("echo ``quoted``", "``` echo ``quoted`` ```"),
("`` `quoted` ``", "``` `` `quoted` `` ```"),
("`", "`` ` ``"),
("echo ```", "```` echo ``` ````"),
(" echo `uname` ", "`` echo `uname` ``"),
] {
assert_eq!(formatter.command(command), expected, "{command:?}");
}
}
+21
View File
@@ -929,6 +929,27 @@ fn invalid_command_options_preserve_export_files() {
}
}
#[test]
fn markdown_export_preserves_backticks_and_pipes_in_command_names() {
let _settings = snapshot_settings().bind_to_scope();
assert_cmd_snapshot!(hyperfine_debug()
.arg("--style=none")
.arg("--export-markdown=-")
.arg("--command-name=echo `uname` | cat")
.arg("sleep 1"), @r"
success: true
exit_code: 0
----- stdout -----
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|:---|---:|---:|---:|---:|
| `` echo `uname` \| cat `` | 1.000 ± 0.000 | 1.000 | 1.000 | 1.00 |
----- stderr -----
");
}
#[test]
fn unused_parameters_are_shown_in_benchmark_name() {
hyperfine()