diff --git a/src/table_structs.rs b/src/table_structs.rs index 2fe83d8..1bca5c2 100644 --- a/src/table_structs.rs +++ b/src/table_structs.rs @@ -116,9 +116,11 @@ pub(crate) static STR_TO_TARGET_FULL: phf::Map<&'static str, TableTargets> = phf }; /// The regex for finding and replacing all stars with a custom DD -pub(crate) static RE: Lazy = regex_static::lazy_regex!(r"★+"); -// / The regex for finding all (+/-) and replacing them with mathmode -// pub(crate) static RE: Lazy = regex_static::lazy_regex!(r"\([+-]*\)"); +pub(crate) static RE_STARS: Lazy = regex_static::lazy_regex!(r"★+"); +/// The regex for finding and replacing all +/- stars with a custom DD +pub(crate) static RE_PLUS_STARS: Lazy = regex_static::lazy_regex!(r"([\+-])(★+)"); +/// The regex for finding all (+/-) and replacing them with mathmode +pub(crate) static RE_MATHS: Lazy = regex_static::lazy_regex!(r"\([\+-]+\)"); impl From<&str> for TableGenerationTarget { fn from(value: &str) -> Self { diff --git a/src/tablegen.rs b/src/tablegen.rs index 4496d93..6f6a39f 100644 --- a/src/tablegen.rs +++ b/src/tablegen.rs @@ -10,7 +10,10 @@ use std::{ }; use crate::{ - table_structs::{TableArgs, TableGenerationTarget, TableTargets, RE, STR_TO_TARGET_FULL}, + table_structs::{ + TableArgs, TableGenerationTarget, TableTargets, RE_MATHS, RE_PLUS_STARS, RE_STARS, + STR_TO_TARGET_FULL, + }, table_types::{ClassesArray, GenericArray, RecordClass, WriteTable}, Config, }; @@ -141,7 +144,7 @@ pub fn export_tsv( /// Replace all instances of unrepresentable utf8 or non escaped characters with latex ones pub fn make_latex_string(arg: &str) -> String { - let temp = arg + let res = arg .replace('🩸', "\\blood") .replace('⚡', "\\gauge") .replace('☽', "\\slash") @@ -153,9 +156,13 @@ pub fn make_latex_string(arg: &str) -> String { .replace('🗘', "\\reload") .replace('½', "\\sfrac{1}{2}") .replace('&', "\\&"); - let res = RE.replace_all(&temp, |caps: &Captures| { + let res = RE_PLUS_STARS.replace_all(&res, |caps: &Captures| { + format!("\\ddmod{{{}}}{{{}}}", &caps[1], caps[2].chars().count()) + }); + let res = RE_STARS.replace_all(&res, |caps: &Captures| { format!("\\ddlvl{{{}}}", caps[0].chars().count()) }); + let res = RE_MATHS.replace_all(&res, |caps: &Captures| format!("${}$", &caps[0])); res.to_string() }