2022-05-15 21:47:45 +02:00
|
|
|
use super::markup::Alignment;
|
|
|
|
|
use crate::export::markup::MarkupExporter;
|
2022-03-21 21:45:24 +01:00
|
|
|
|
|
|
|
|
#[derive(Default)]
|
2022-05-15 21:47:45 +02:00
|
|
|
pub struct OrgmodeExporter {}
|
2022-03-21 21:45:24 +01:00
|
|
|
|
2022-05-15 21:47:45 +02:00
|
|
|
impl MarkupExporter for OrgmodeExporter {
|
|
|
|
|
fn table_row(&self, cells: &[&str]) -> String {
|
2022-03-21 21:45:24 +01:00
|
|
|
format!(
|
|
|
|
|
"| {} | {} |\n",
|
2022-05-15 21:47:45 +02:00
|
|
|
cells.first().unwrap(),
|
2026-10-02 11:05:02 +02:00
|
|
|
cells[1..].join(" | ")
|
2022-03-21 21:45:24 +01:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-15 21:47:45 +02:00
|
|
|
fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String {
|
|
|
|
|
format!("|{}--|\n", "--+".repeat(cell_aligmnents.len() - 1))
|
2022-03-21 21:45:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn command(&self, cmd: &str) -> String {
|
2024-05-31 13:26:35 -07:00
|
|
|
format!("={cmd}=")
|
2022-03-21 21:45:24 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Check Emacs org-mode data row formatting
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_orgmode_formatter_table_data() {
|
2022-05-15 21:47:45 +02:00
|
|
|
let exporter = OrgmodeExporter::default();
|
2022-03-21 21:45:24 +01:00
|
|
|
|
2022-05-15 21:47:45 +02:00
|
|
|
let actual = exporter.table_row(&["a", "b", "c"]);
|
2022-03-21 21:45:24 +01:00
|
|
|
let expect = "| a | b | c |\n";
|
|
|
|
|
|
|
|
|
|
assert_eq!(expect, actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Check Emacs org-mode horizontal line formatting
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_orgmode_formatter_table_line() {
|
2022-05-15 21:47:45 +02:00
|
|
|
let exporter = OrgmodeExporter::default();
|
2022-03-21 21:45:24 +01:00
|
|
|
|
2022-05-15 21:47:45 +02:00
|
|
|
let actual = exporter.table_divider(&[
|
|
|
|
|
Alignment::Left,
|
|
|
|
|
Alignment::Left,
|
|
|
|
|
Alignment::Left,
|
|
|
|
|
Alignment::Left,
|
|
|
|
|
Alignment::Left,
|
|
|
|
|
]);
|
2022-03-21 21:45:24 +01:00
|
|
|
let expect = "|--+--+--+--+--|\n";
|
|
|
|
|
|
|
|
|
|
assert_eq!(expect, actual);
|
|
|
|
|
}
|