Skip to content
Myr

markdown.rs

This file

Path

src/export/markdown.rs

74 lines · 2.1 KiB · Rust

Last changed by

Merge pull request #947 from Likio3000/codex/fix-markdown-backticksDavid Peterbefore adoption0a61e33

History of this file

Take it

The walk stopped after 200 commits: lines older than ca9e29a point at it.

Fix pipeline!David Peterbefore adoptionca9e29a

lines 1–26why, one step back
1use crate::export::markup::MarkupExporter;
23use super::markup::Alignment;45#[derive(Default)]6pub struct MarkdownExporter {}78impl MarkupExporter for MarkdownExporter {9 fn table_row(&self, cells: &[&str]) -> String {10 format!("| {} |\n", cells.join(" | "))11 }1213 fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String {14 format!(15 "|{}\n",16 cell_aligmnents17 .iter()18 .map(|a| match a {19 Alignment::Left => ":---|",20 Alignment::Right => "---:|",21 })22 .collect::<String>()23 )24 }2526 fn command(&self, cmd: &str) -> String {

Merge pull request #947 from Likio3000/codex/fix-markdown-backticksDavid Peterbefore adoption0a61e33

lines 27–39why, one step back
27 let longest_backtick_run = cmd
28 .split(|character| character != '`')29 .map(str::len)30 .max()31 .unwrap_or(0);3233 if longest_backtick_run == 0 {34 format!("`{cmd}`")35 } else {36 // Use a longer delimiter and keep command backticks separate from it.37 let delimiter = "`".repeat(longest_backtick_run + 1);38 format!("{delimiter} {cmd} {delimiter}")39 }

Fix pipeline!David Peterbefore adoptionca9e29a

lines 40–57why, one step back
40 }
41}4243/// Check Markdown-based data row formatting44#[test]45fn test_markdown_formatter_table_data() {46 let formatter = MarkdownExporter::default();4748 assert_eq!(formatter.table_row(&["a", "b", "c"]), "| a | b | c |\n");49}5051/// Check Markdown-based horizontal line formatting52#[test]53fn test_markdown_formatter_table_divider() {54 let formatter = MarkdownExporter::default();5556 let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);57 assert_eq!(divider, "|:---|---:|:---|\n");

Merge pull request #947 from Likio3000/codex/fix-markdown-backticksDavid Peterbefore adoption0a61e33

lines 58–73why, one step back
58}
5960#[test]61fn test_markdown_formatter_command_with_backticks() {62 let formatter = MarkdownExporter::default();6364 for (command, expected) in [65 ("echo `uname`", "`` echo `uname` ``"),66 ("echo ``quoted``", "``` echo ``quoted`` ```"),67 ("`` `quoted` ``", "``` `` `quoted` `` ```"),68 ("`", "`` ` ``"),69 ("echo ```", "```` echo ``` ````"),70 (" echo `uname` ", "`` echo `uname` ``"),71 ] {72 assert_eq!(formatter.command(command), expected, "{command:?}");73 }

Fix pipeline!David Peterbefore adoptionca9e29a

line 74why, one step back
74}