Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tempfile = "3.27.0"
thiserror = "2.0.18"
uuid = { version = "1.24.0", features = ["v4"] }
zip = { version = "8.6.0", default-features = false, features = ["deflate"] }
quick-xml = "0.41"
quick-xml = "0.42"
anyhow = "1"
tracing = "0.1"
proptest = "1.5"
Expand Down
13 changes: 6 additions & 7 deletions crates/easydoc-math/src/omml_to_latex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl OmmlConverter {
}
}
Ok(Event::Text(t)) => {
let text = String::from_utf8_lossy(&t).into_owned();
let text = t.as_ref().to_owned();
if !text.is_empty() {
parts.push(text);
}
Expand Down Expand Up @@ -424,7 +424,7 @@ impl OmmlConverter {
}
}
Ok(Event::Text(t)) if in_text => {
let raw = String::from_utf8_lossy(&t);
let raw = t.as_ref();
let mut mapped = String::with_capacity(raw.len());
for c in raw.chars() {
let mut char_buf = [0u8; 4];
Expand Down Expand Up @@ -1376,11 +1376,10 @@ fn is_omath(e: &BytesStart) -> bool {
/// Get the local name (stripping `m:` prefix) from a start event.
fn local_name(e: &BytesStart) -> String {
let qname = e.name();
let raw = qname.as_ref();
let s = String::from_utf8_lossy(raw);
let s: &str = qname.as_ref();
match s.strip_prefix(OMML_NS_PREFIX) {
Some(stripped) => stripped.to_owned(),
None => s.into_owned(),
None => s.to_owned(),
}
}

Expand All @@ -1396,9 +1395,9 @@ fn dispatch_empty(stag: &str, e: &BytesStart) -> Option<String> {
fn attr_val(e: &BytesStart, name: &str) -> Option<String> {
let prefixed = format!("{OMML_NS_PREFIX}{name}");
for attr in e.attributes().flatten() {
let key = String::from_utf8_lossy(attr.key.as_ref());
let key: &str = attr.key.as_ref();
if key == prefixed || key == name {
return Some(String::from_utf8_lossy(&attr.value).into_owned());
return Some(attr.value.into_owned());
}
}
None
Expand Down
8 changes: 4 additions & 4 deletions crates/easydoc-mcp/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,25 +715,25 @@ fn collect_image_entries(xml: &str) -> Vec<(String, String)> {
loop {
match reader.read_event_into(&mut buf) {
Ok(quick_xml::events::Event::Empty(ref tag)) => {
if tag.name().as_ref() == b"Relationship" {
if tag.name().as_ref() == "Relationship" {
let mut id = None;
let mut target = None;
let mut is_image = false;
for attr in tag.attributes().flatten() {
match attr.key.as_ref() {
b"Id" => {
"Id" => {
id = attr
.normalized_value(quick_xml::XmlVersion::Implicit1_0)
.ok()
.map(std::borrow::Cow::into_owned);
}
b"Target" => {
"Target" => {
target = attr
.normalized_value(quick_xml::XmlVersion::Implicit1_0)
.ok()
.map(std::borrow::Cow::into_owned);
}
b"Type" => {
"Type" => {
if let Ok(val) =
attr.normalized_value(quick_xml::XmlVersion::Implicit1_0)
&& val.ends_with("/image")
Expand Down
8 changes: 4 additions & 4 deletions crates/easydoc-reader/src/extractor/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,26 @@ impl Relationships {
Ok(Event::Eof) => break,
Ok(Event::Empty(ref tag)) => {
let name = tag.name();
if name.as_ref() == b"Relationship" {
if name.as_ref() == "Relationship" {
let mut id = None;
let mut target = None;
let mut rel_type = RelType::Other;

for attr in tag.attributes().flatten() {
match attr.key.as_ref() {
b"Id" => {
"Id" => {
id = attr
.normalized_value(quick_xml::XmlVersion::Implicit1_0)
.ok()
.map(Cow::into_owned);
}
b"Target" => {
"Target" => {
target = attr
.normalized_value(quick_xml::XmlVersion::Implicit1_0)
.ok()
.map(Cow::into_owned);
}
b"Type" => {
"Type" => {
if let Ok(val) =
attr.normalized_value(quick_xml::XmlVersion::Implicit1_0)
{
Expand Down
34 changes: 17 additions & 17 deletions crates/easydoc-reader/src/extractor/numbering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,26 @@ impl Numbering {
let name = start.name();
let local = name.as_ref();
match local {
b"w:abstractNum" => {
current_abstract_id = extract_u32_attr(start, b"w:abstractNumId");
"w:abstractNum" => {
current_abstract_id = extract_u32_attr(start, "w:abstractNumId");
}
b"w:lvl" => {
current_ilvl = extract_u8_attr(start, b"w:ilvl");
"w:lvl" => {
current_ilvl = extract_u8_attr(start, "w:ilvl");
current_num_fmt = None;
current_start = None;
}
b"w:numFmt" => {
"w:numFmt" => {
current_num_fmt = extract_val_attr(start);
}
b"w:start" => {
"w:start" => {
current_start =
extract_val_attr(start).and_then(|v| v.parse::<u32>().ok());
}
b"w:num" => {
current_num_id = extract_u32_attr(start, b"w:numId");
"w:num" => {
current_num_id = extract_u32_attr(start, "w:numId");
in_num = true;
}
b"w:abstractNumId" if in_num => {
"w:abstractNumId" if in_num => {
// This is inside <w:num> -- read the val attribute.
if let (Some(abstract_id), Some(num_id)) =
(extract_val_attr_u32(start), current_num_id)
Expand All @@ -110,14 +110,14 @@ impl Numbering {
let name = empty.name();
let local = name.as_ref();
match local {
b"w:numFmt" => {
"w:numFmt" => {
current_num_fmt = extract_val_attr(empty);
}
b"w:start" => {
"w:start" => {
current_start =
extract_val_attr(empty).and_then(|v| v.parse::<u32>().ok());
}
b"w:abstractNumId" if in_num => {
"w:abstractNumId" if in_num => {
if let (Some(abstract_id), Some(num_id)) =
(extract_val_attr_u32(empty), current_num_id)
{
Expand All @@ -131,7 +131,7 @@ impl Numbering {
let name = end.name();
let local = name.as_ref();
match local {
b"w:lvl" => {
"w:lvl" => {
// Finalize the level we were parsing.
if let (Some(abstract_id), Some(ilvl)) =
(current_abstract_id, current_ilvl)
Expand All @@ -154,7 +154,7 @@ impl Numbering {
current_num_fmt = None;
current_start = None;
}
b"w:num" => {
"w:num" => {
current_num_id = None;
in_num = false;
}
Expand Down Expand Up @@ -187,7 +187,7 @@ impl Numbering {
}

/// Extracts a `u32` value from a named attribute (e.g. `w:abstractNumId="0"`).
fn extract_u32_attr(tag: &quick_xml::events::BytesStart, attr_name: &[u8]) -> Option<u32> {
fn extract_u32_attr(tag: &quick_xml::events::BytesStart, attr_name: &str) -> Option<u32> {
for attr in tag.attributes().flatten() {
if attr.key.as_ref() == attr_name {
let val = attr
Expand All @@ -200,7 +200,7 @@ fn extract_u32_attr(tag: &quick_xml::events::BytesStart, attr_name: &[u8]) -> Op
}

/// Extracts a `u8` value from a named attribute (e.g. `w:ilvl="0"`).
fn extract_u8_attr(tag: &quick_xml::events::BytesStart, attr_name: &[u8]) -> Option<u8> {
fn extract_u8_attr(tag: &quick_xml::events::BytesStart, attr_name: &str) -> Option<u8> {
for attr in tag.attributes().flatten() {
if attr.key.as_ref() == attr_name {
let val = attr
Expand All @@ -215,7 +215,7 @@ fn extract_u8_attr(tag: &quick_xml::events::BytesStart, attr_name: &[u8]) -> Opt
/// Extracts the `w:val` attribute as a `String`.
fn extract_val_attr(tag: &quick_xml::events::BytesStart) -> Option<String> {
for attr in tag.attributes().flatten() {
if attr.key.as_ref() == b"w:val" {
if attr.key.as_ref() == "w:val" {
return attr
.normalized_value(quick_xml::XmlVersion::Implicit1_0)
.ok()
Expand Down
Loading
Loading