mirror of
https://github.com/storytold/designcraft.git
synced 2026-10-31 21:56:50 -06:00
Fix duplicated xref format text before an unclosed '<' in IDML export
Found while testing crates/idml/src/export/designmap.rs:208-230 (xref_format_el) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
50650f74d7
commit
e8c0a19180
@@ -206,10 +206,10 @@ fn xref_format_el(i: usize, f: &designcraft_doc::XrefFormat) -> El {
|
||||
};
|
||||
let mut rest = f.definition.as_str();
|
||||
while let Some(a) = rest.find('<') {
|
||||
let Some(b) = rest[a..].find('>') else { break };
|
||||
if a > 0 {
|
||||
block(&mut el, "CustomStringBuildingBlock", &rest[..a], "", false);
|
||||
}
|
||||
let Some(b) = rest[a..].find('>') else { break };
|
||||
let tag = rest[a + 1..a + b].trim().trim_end_matches('/').trim();
|
||||
let attr = |k: &str| tag.find(&format!("{k}=\"")).and_then(|i| tag[i + k.len() + 2..].split('"').next()).unwrap_or("").to_string();
|
||||
match tag.split_whitespace().next().unwrap_or("") {
|
||||
@@ -350,3 +350,31 @@ fn text_variable_el(v: &designcraft_doc::vars::TextVariable) -> El {
|
||||
}
|
||||
e
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::xml::Node;
|
||||
|
||||
fn custom_text(definition: &str) -> String {
|
||||
let f = designcraft_doc::XrefFormat { name: "x".into(), definition: definition.into() };
|
||||
xref_format_el(0, &f)
|
||||
.children
|
||||
.iter()
|
||||
.filter_map(|n| match n {
|
||||
Node::El(e) if e.get("BlockType") == Some("CustomStringBuildingBlock") => e.get("CustomText").map(str::to_string),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xref_format_unclosed_angle_bracket_keeps_text_once() {
|
||||
assert_eq!(custom_text("a < b"), "a < b");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xref_format_well_formed_keeps_custom_text() {
|
||||
assert_eq!(custom_text("p <pageNum /> of <chapNum />"), "p of ");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user