refactor(vm, frontend): internally tag template enum, finish remap frontend
This commit is contained in:
@@ -21,7 +21,6 @@ serde_with = "3.8.1"
|
||||
textwrap = { version = "0.16.1", default-features = false }
|
||||
thiserror = "1.0.61"
|
||||
|
||||
onig = { git = "https://github.com/rust-onig/rust-onig", revision = "fa90c0e97e90a056af89f183b23cd417b59ee6a2" }
|
||||
tracing = "0.1.40"
|
||||
quote = "1.0.36"
|
||||
prettyplease = "0.2.20"
|
||||
|
||||
@@ -205,7 +205,7 @@ pub fn generate_database(
|
||||
//
|
||||
// https://regex101.com/r/WFpjHV/1
|
||||
//
|
||||
let null_matcher = regex::Regex::new(r#"(?:(?:,?\n)\s*"\w+":\snull)+(,?)"#).unwrap();
|
||||
let null_matcher = regex::Regex::new(r#"(?:,\n\s*"\w+":\snull)+(,?)|(?:(?:\n)?\s*"\w+":\snull),"#).unwrap();
|
||||
let json = null_matcher.replace_all(&json, "$1");
|
||||
write!(&mut database_file, "{json}")?;
|
||||
database_file.flush()?;
|
||||
|
||||
@@ -1,60 +1,28 @@
|
||||
use onig::{Captures, Regex, RegexOptions, Syntax};
|
||||
use regex::{Captures, Regex};
|
||||
|
||||
pub fn strip_color(s: &str) -> String {
|
||||
let color_regex = Regex::with_options(
|
||||
r#"<color=(#?\w+)>((:?(?!<color=(?:#?\w+)>).)+?)</color>"#,
|
||||
RegexOptions::REGEX_OPTION_MULTILINE | RegexOptions::REGEX_OPTION_CAPTURE_GROUP,
|
||||
Syntax::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut new = s.to_owned();
|
||||
loop {
|
||||
new = color_regex.replace_all(&new, |caps: &Captures| caps.at(2).unwrap_or("").to_string());
|
||||
if !color_regex.is_match(&new) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
new
|
||||
let color_re = Regex::new(r"<color=.*?>|</color>").unwrap();
|
||||
color_re.replace_all(s, "").to_string()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn color_to_heml(s: &str) -> String {
|
||||
let color_regex = Regex::with_options(
|
||||
r#"<color=(#?\w+)>((:?(?!<color=(?:#?\w+)>).)+?)</color>"#,
|
||||
RegexOptions::REGEX_OPTION_MULTILINE | RegexOptions::REGEX_OPTION_CAPTURE_GROUP,
|
||||
Syntax::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut new = s.to_owned();
|
||||
loop {
|
||||
new = color_regex.replace_all(&new, |caps: &Captures| {
|
||||
format!(
|
||||
r#"<div style="color: {};">{}</div>"#,
|
||||
caps.at(1).unwrap_or(""),
|
||||
caps.at(2).unwrap_or("")
|
||||
)
|
||||
});
|
||||
if !color_regex.is_match(&new) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
new
|
||||
pub fn color_to_html(s: &str) -> String {
|
||||
// not currently used
|
||||
// onig regex: r#"<color=(#?\w+)>((:?(?!<color=(?:#?\w+)>).)+?)</color>"#
|
||||
let color_re_start = Regex::new(r#"<color=(?<color>#?\w+)>"#).unwrap();
|
||||
let color_re_end = Regex::new("</color>").unwrap();
|
||||
let start_replaced = color_re_start.replace_all(s, |caps: &Captures| {
|
||||
format!(
|
||||
r#"<div style="color: {};">"#,
|
||||
caps.name("color").unwrap().as_str()
|
||||
)
|
||||
});
|
||||
let replaced = color_re_end.replace_all(&start_replaced, "</div>");
|
||||
replaced.to_string()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn strip_link(s: &str) -> String {
|
||||
let link_regex = Regex::with_options(
|
||||
r#"<link=(\w+)>(.+?)</link>"#,
|
||||
RegexOptions::REGEX_OPTION_MULTILINE | RegexOptions::REGEX_OPTION_CAPTURE_GROUP,
|
||||
Syntax::default(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut new = s.to_owned();
|
||||
loop {
|
||||
new = link_regex.replace_all(&new, |caps: &Captures| caps.at(2).unwrap_or("").to_string());
|
||||
if !link_regex.is_match(&new) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
new
|
||||
let link_re = Regex::new(r"<link=.*?>|</link>").unwrap();
|
||||
link_re.replace_all(s, "").to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user