Skip to content
Open
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
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Alef-generated binding and e2e files — collapsed in GitHub PR diffs
packages/csharp/** linguist-generated=true
packages/dart/** linguist-generated=true
packages/elixir/** linguist-generated=true
packages/gleam/** linguist-generated=true
packages/go/** linguist-generated=true
packages/java/** linguist-generated=true
packages/kotlin/** linguist-generated=true
packages/php/** linguist-generated=true
packages/python/** linguist-generated=true
packages/r/** linguist-generated=true
packages/ruby/** linguist-generated=true
packages/swift/** linguist-generated=true
packages/typescript/** linguist-generated=true
packages/wasm/** linguist-generated=true
packages/zig/** linguist-generated=true
crates/kreuzberg-ffi/** linguist-generated=true
crates/kreuzberg-node/** linguist-generated=true
crates/kreuzberg-php/** linguist-generated=true
crates/kreuzberg-py/** linguist-generated=true
crates/kreuzberg-wasm/** linguist-generated=true
e2e/** linguist-generated=true
149 changes: 147 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions alef.toml
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ types = [
"GzipExtractor",
"HtmlExtractor",
"HwpExtractor",
"HwpxExtractor",
"ImageExtractor",
"JatsExtractor",
"JupyterExtractor",
Expand Down
3 changes: 3 additions & 0 deletions crates/kreuzberg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ office = [
"html",
]
hwp = ["dep:cfb", "dep:flate2"]
hwpx = ["dep:unhwp"]
iwork = ["dep:zip", "dep:snap"]
email = ["dep:mail-parser", "dep:cfb", "dep:outlook-pst", "dep:tempfile", "dep:chrono"]
html = ["dep:html-to-markdown-rs", "dep:v_htmlescape"]
Expand Down Expand Up @@ -208,6 +209,7 @@ formats = [
"excel",
"office",
"hwp",
"hwpx",
"iwork",
"email",
"html",
Expand Down Expand Up @@ -369,6 +371,7 @@ tower-http = { version = "0.6", features = [
], optional = true }
tracing = { workspace = true }
tracing-opentelemetry = { version = "0.32", optional = true }
unhwp = { version = "0.2.4", default-features = false, features = ["hwpx"], optional = true }
unicode-normalization = { version = "0.1.25", optional = true }
urlencoding = "2"
utoipa = { version = "5.4", features = ["axum_extras"], optional = true }
Expand Down
7 changes: 7 additions & 0 deletions crates/kreuzberg/src/core/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub(crate) const SOURCE_CODE_MIME_TYPE: &str = "text/x-source-code";

pub(crate) const EXCEL_MIME_TYPE: &str = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

pub(crate) const HWPX_MIME_TYPE: &str = "application/haansofthwpx";
pub(crate) const IWORK_PAGES_MIME_TYPE: &str = "application/x-iwork-pages-sffpages";
pub(crate) const IWORK_NUMBERS_MIME_TYPE: &str = "application/x-iwork-numbers-sffnumbers";
pub(crate) const IWORK_KEYNOTE_MIME_TYPE: &str = "application/x-iwork-keynote-sffkey";
Expand Down Expand Up @@ -783,6 +784,12 @@ fn detect_office_format_from_zip(content: &[u8]) -> Option<&'static str> {
const NUMBERS_MARKER: &[u8] = b"Index/CalculationEngine.iwa";
const KEYNOTE_MARKER: &[u8] = b"Index/Presentation.iwa";

// HWPX: ZIP of OWPML XML, contains Contents/content.hpf manifest
const HWPX_MARKER: &[u8] = b"Contents/content.hpf";
if contains_subsequence(content, HWPX_MARKER) {
return Some(HWPX_MIME_TYPE);
}

// Check iWork first (before generic Office) since iWork ZIPs also contain XML
if contains_subsequence(content, PAGES_MARKER) {
return Some(IWORK_PAGES_MIME_TYPE);
Expand Down
23 changes: 18 additions & 5 deletions crates/kreuzberg/src/extractors/hwp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl DocumentExtractor for HwpExtractor {
}

fn supported_mime_types(&self) -> &[&str] {
&["application/x-hwp", "application/haansofthwpx"]
&["application/x-hwp"]
}

fn priority(&self) -> i32 {
Expand All @@ -106,10 +106,7 @@ mod tests {
assert_eq!(extractor.name(), "hwp-extractor");
assert_eq!(extractor.version(), env!("CARGO_PKG_VERSION"));
assert_eq!(extractor.priority(), 50);
assert_eq!(
extractor.supported_mime_types(),
&["application/x-hwp", "application/haansofthwpx"]
);
assert_eq!(extractor.supported_mime_types(), &["application/x-hwp"]);
}

#[test]
Expand All @@ -118,4 +115,20 @@ mod tests {
assert!(extractor.initialize().is_ok());
assert!(extractor.shutdown().is_ok());
}

#[test]
fn test_hwpx_mime_not_routed_to_hwp_extractor() {
use crate::KreuzbergError;
use crate::plugins::registry::DocumentExtractorRegistry;
use std::sync::Arc;

let mut registry = DocumentExtractorRegistry::new();
registry.register(Arc::new(HwpExtractor::new())).unwrap();

let result = registry.get("application/haansofthwpx");
assert!(
matches!(result, Err(KreuzbergError::UnsupportedFormat(_))),
"application/haansofthwpx must not be routed to HwpExtractor"
);
}
}
Loading