orgmode.rs
1 use super::markup::Alignment; 2 use crate::export::markup::MarkupExporter; 3 4 #[derive(Default)] 5 pub struct OrgmodeExporter {} 6 7 impl MarkupExporter for OrgmodeExporter { 8 fn table_row(&self, cells: &[&str]) -> String { 9 format!( 10 "| {} | {} |\n", 11 cells.first().unwrap(), 12 &cells[1..].join(" | ") 13 ) 14 } 15 16 fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String { 17 format!("|{}--|\n", "--+".repeat(cell_aligmnents.len() - 1)) 18 } 19 20 fn command(&self, cmd: &str) -> String { 21 format!("={cmd}=") 22 } 23 } 24 25 /// Check Emacs org-mode data row formatting 26 #[test] 27 fn test_orgmode_formatter_table_data() { 28 let exporter = OrgmodeExporter::default(); 29 30 let actual = exporter.table_row(&["a", "b", "c"]); 31 let expect = "| a | b | c |\n"; 32 33 assert_eq!(expect, actual); 34 } 35 36 /// Check Emacs org-mode horizontal line formatting 37 #[test] 38 fn test_orgmode_formatter_table_line() { 39 let exporter = OrgmodeExporter::default(); 40 41 let actual = exporter.table_divider(&[ 42 Alignment::Left, 43 Alignment::Left, 44 Alignment::Left, 45 Alignment::Left, 46 Alignment::Left, 47 ]); 48 let expect = "|--+--+--+--+--|\n"; 49 50 assert_eq!(expect, actual); 51 }