mirror of
https://github.com/storytold/deckcraft.git
synced 2026-11-22 13:57:53 -06:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
988d721d7d |
Generated
+10
@@ -986,6 +986,15 @@ dependencies = [
|
|||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "craft-xml"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://github.com/storytold/craft-libs?rev=ea24422ae9859dc5da398d0462bc87f8e02e0d10#ea24422ae9859dc5da398d0462bc87f8e02e0d10"
|
||||||
|
dependencies = [
|
||||||
|
"quick-xml 0.41.0",
|
||||||
|
"thiserror 2.0.21",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crc32fast"
|
name = "crc32fast"
|
||||||
version = "1.5.2"
|
version = "1.5.2"
|
||||||
@@ -1219,6 +1228,7 @@ dependencies = [
|
|||||||
name = "deckcraft-pptx"
|
name = "deckcraft-pptx"
|
||||||
version = "0.19.0"
|
version = "0.19.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"craft-xml",
|
||||||
"deckcraft-color",
|
"deckcraft-color",
|
||||||
"deckcraft-engine",
|
"deckcraft-engine",
|
||||||
"deckcraft-geom",
|
"deckcraft-geom",
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ rust-version = "1.95"
|
|||||||
repository = "https://github.com/storytold/deckcraft"
|
repository = "https://github.com/storytold/deckcraft"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
|
# XML writer primitives; parser admission and OOXML policy stay app-local.
|
||||||
|
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "ea24422ae9859dc5da398d0462bc87f8e02e0d10", version = "0.1.0" }
|
||||||
# internal
|
# internal
|
||||||
deckcraft-geom = { path = "crates/geom" }
|
deckcraft-geom = { path = "crates/geom" }
|
||||||
deckcraft-color = { path = "crates/color" }
|
deckcraft-color = { path = "crates/color" }
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ description = "DeckCraft PPTX: Office Open XML (PresentationML/DrawingML) import
|
|||||||
workspace = true
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
craft-xml.workspace = true
|
||||||
deckcraft-model = { workspace = true }
|
deckcraft-model = { workspace = true }
|
||||||
deckcraft-geom = { workspace = true }
|
deckcraft-geom = { workspace = true }
|
||||||
deckcraft-color = { workspace = true }
|
deckcraft-color = { workspace = true }
|
||||||
|
|||||||
+33
-39
@@ -354,45 +354,8 @@ fn decode_utf16(bytes: &[u8]) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Is `c` allowed in XML 1.0 text?
|
// Preserve the public writer helpers while sharing the XML 1.0 escaping rules.
|
||||||
fn xml_char(c: char) -> bool {
|
pub use craft_xml::{esc, esc_attr};
|
||||||
matches!(c, '\t' | '\n' | '\r') || (c >= ' ' && c != '\u{FFFE}' && c != '\u{FFFF}')
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Escape text content (and drop characters XML 1.0 forbids).
|
|
||||||
pub fn esc(s: &str) -> String {
|
|
||||||
let mut o = String::with_capacity(s.len());
|
|
||||||
for c in s.chars() {
|
|
||||||
match c {
|
|
||||||
'&' => o.push_str("&"),
|
|
||||||
'<' => o.push_str("<"),
|
|
||||||
'>' => o.push_str(">"),
|
|
||||||
'\r' => o.push_str(" "),
|
|
||||||
c if xml_char(c) => o.push(c),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
o
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Escape an attribute value.
|
|
||||||
pub fn esc_attr(s: &str) -> String {
|
|
||||||
let mut o = String::with_capacity(s.len());
|
|
||||||
for c in s.chars() {
|
|
||||||
match c {
|
|
||||||
'&' => o.push_str("&"),
|
|
||||||
'<' => o.push_str("<"),
|
|
||||||
'>' => o.push_str(">"),
|
|
||||||
'"' => o.push_str("""),
|
|
||||||
'\n' => o.push_str(" "),
|
|
||||||
'\r' => o.push_str(" "),
|
|
||||||
'\t' => o.push_str("	"),
|
|
||||||
c if xml_char(c) => o.push(c),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
o
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A string builder for XML parts.
|
/// A string builder for XML parts.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
@@ -542,6 +505,37 @@ mod tests {
|
|||||||
assert_eq!(esc_attr("\"x\"\n"), ""x" ");
|
assert_eq!(esc_attr("\"x\"\n"), ""x" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn shared_escaping_preserves_xml_wire_bytes() {
|
||||||
|
let text = "&<>\"'\t\n\r\0\u{b}\u{fffe}\u{ffff}é😀 ";
|
||||||
|
assert_eq!(esc(text), "&<>\"'\t\n é😀&#13;");
|
||||||
|
assert_eq!(esc_attr(text), "&<>"'	 é😀&#13;");
|
||||||
|
assert_eq!(esc(""), "");
|
||||||
|
assert_eq!(esc_attr(""), "");
|
||||||
|
for code in 0..32 {
|
||||||
|
let c = char::from_u32(code).unwrap();
|
||||||
|
let text = c.to_string();
|
||||||
|
match c {
|
||||||
|
'\t' => {
|
||||||
|
assert_eq!(esc(&text), "\t");
|
||||||
|
assert_eq!(esc_attr(&text), "	");
|
||||||
|
}
|
||||||
|
'\n' => {
|
||||||
|
assert_eq!(esc(&text), "\n");
|
||||||
|
assert_eq!(esc_attr(&text), " ");
|
||||||
|
}
|
||||||
|
'\r' => {
|
||||||
|
assert_eq!(esc(&text), " ");
|
||||||
|
assert_eq!(esc_attr(&text), " ");
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
assert_eq!(esc(&text), "");
|
||||||
|
assert_eq!(esc_attr(&text), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn roundtrip_serialize() {
|
fn roundtrip_serialize() {
|
||||||
let d = parse(b"<p:sp a=\"1\"><p:t>x & y</p:t><e/></p:sp>").unwrap();
|
let d = parse(b"<p:sp a=\"1\"><p:t>x & y</p:t><e/></p:sp>").unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user