filter gemtext special chars

This commit is contained in:
postscriptum 2025-07-04 16:01:53 +03:00
parent 25186136bc
commit 70e4c0d20f

View file

@ -29,8 +29,8 @@ impl Template {
self.pattern self.pattern
.replace( .replace(
"{content}", "{content}",
&if self.pattern.contains("{tags}") { &if matches!(self.format, Format::Gemtext) || self.pattern.contains("{tags}") {
content.replace("#", "") content.replace('#', "")
} else { } else {
content content
}, },
@ -60,7 +60,22 @@ impl Template {
.replace( .replace(
"{tags}", "{tags}",
&tags &tags
.map(|t| format!("\n\n{}", t.join(", "))) .map(|t| {
format!(
"\n\n{}",
// trim gemtext special chars
if matches!(self.format, Format::Gemtext) {
let mut b = Vec::with_capacity(t.len());
for this in t {
b.push(this.replace('#', ""))
}
b
} else {
t
}
.join(", ")
)
})
.unwrap_or_default(), .unwrap_or_default(),
) )
.replace("{link}", &format!("\n\n=> {link}")) .replace("{link}", &format!("\n\n=> {link}"))