Skip to content
Myr

markdown.rs

This file

Path

src/export/markdown.rs

46 lines · 1.2 KiB · Rust

Last changed by

Use insta for exporter testsDavid Peterbefore adoption7a9d04d

History of this file

Take it

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 {27        format!("`{cmd}`")28    }29}3031/// Check Markdown-based data row formatting32#[test]33fn test_markdown_formatter_table_data() {34    let formatter = MarkdownExporter::default();3536    assert_eq!(formatter.table_row(&["a", "b", "c"]), "| a | b | c |\n");37}3839/// Check Markdown-based horizontal line formatting40#[test]41fn test_markdown_formatter_table_divider() {42    let formatter = MarkdownExporter::default();4344    let divider = formatter.table_divider(&[Alignment::Left, Alignment::Right, Alignment::Left]);45    assert_eq!(divider, "|:---|---:|:---|\n");46}