use clap::Args;
use core::str::FromStr;
#[derive(Clone)]
pub enum TableStyle {
Tabular,
Longtabu,
Booktabs,
}
impl FromStr for TableStyle {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"tabular" => Ok(TableStyle::Tabular),
"longtabu" => Ok(TableStyle::Longtabu),
"booktabs" => Ok(TableStyle::Booktabs),
_ => Err(format!(
"Invalid table style: {s}. Supported: tabular, longtabu, booktabs"
)),
}
}
}
#[derive(Clone)]
pub enum CodeStyle {
Verbatim,
Listings,
Minted,
}
impl FromStr for CodeStyle {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"verbatim" => Ok(CodeStyle::Verbatim),
"listings" => Ok(CodeStyle::Listings),
"minted" => Ok(CodeStyle::Minted),
_ => Err(format!(
"Invalid code style: {s}. Supported: verbatim, listings, minted"
)),
}
}
}
#[derive(Args)]
pub struct LatexConfig {
#[clap(long, default_value_t = 80)]
pub width: usize,
#[clap(long, default_value = "tabular")]
pub table_style: TableStyle,
#[clap(long, default_value = "verbatim")]
pub code_style: CodeStyle,
}
impl LatexConfig {
pub fn to_printer_config(&self) -> markdown_ppp::latex_printer::config::Config {
let table_style = match self.table_style {
TableStyle::Tabular => markdown_ppp::latex_printer::config::TableStyle::Tabular,
TableStyle::Longtabu => markdown_ppp::latex_printer::config::TableStyle::Longtabu,
TableStyle::Booktabs => markdown_ppp::latex_printer::config::TableStyle::Booktabs,
};
let code_style = match self.code_style {
CodeStyle::Verbatim => markdown_ppp::latex_printer::config::CodeBlockStyle::Verbatim,
CodeStyle::Listings => markdown_ppp::latex_printer::config::CodeBlockStyle::Listings,
CodeStyle::Minted => markdown_ppp::latex_printer::config::CodeBlockStyle::Minted,
};
markdown_ppp::latex_printer::config::Config::default()
.with_width(self.width)
.with_table_style(table_style)
.with_code_block_style(code_style)
}
}