kreuzberg 4.0.0.pre.rc.6 → 4.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -6
  3. data/.rubocop.yaml +534 -1
  4. data/Gemfile +2 -1
  5. data/Gemfile.lock +11 -11
  6. data/README.md +5 -10
  7. data/examples/async_patterns.rb +0 -1
  8. data/ext/kreuzberg_rb/extconf.rb +0 -10
  9. data/ext/kreuzberg_rb/native/Cargo.toml +15 -23
  10. data/ext/kreuzberg_rb/native/build.rs +2 -0
  11. data/ext/kreuzberg_rb/native/include/ieeefp.h +1 -1
  12. data/ext/kreuzberg_rb/native/include/msvc_compat/strings.h +1 -1
  13. data/ext/kreuzberg_rb/native/include/strings.h +2 -2
  14. data/ext/kreuzberg_rb/native/include/unistd.h +1 -1
  15. data/ext/kreuzberg_rb/native/src/lib.rs +16 -75
  16. data/kreuzberg.gemspec +14 -57
  17. data/lib/kreuzberg/cache_api.rb +0 -1
  18. data/lib/kreuzberg/cli.rb +2 -2
  19. data/lib/kreuzberg/config.rb +2 -9
  20. data/lib/kreuzberg/errors.rb +7 -75
  21. data/lib/kreuzberg/extraction_api.rb +0 -1
  22. data/lib/kreuzberg/setup_lib_path.rb +0 -1
  23. data/lib/kreuzberg/version.rb +1 -1
  24. data/lib/kreuzberg.rb +0 -21
  25. data/pkg/kreuzberg-4.0.0.rc1.gem +0 -0
  26. data/sig/kreuzberg.rbs +3 -55
  27. data/spec/binding/cli_proxy_spec.rb +4 -2
  28. data/spec/binding/cli_spec.rb +11 -12
  29. data/spec/examples.txt +104 -0
  30. data/spec/fixtures/config.yaml +1 -0
  31. data/spec/spec_helper.rb +1 -1
  32. data/vendor/kreuzberg/Cargo.toml +42 -112
  33. data/vendor/kreuzberg/README.md +2 -2
  34. data/vendor/kreuzberg/build.rs +4 -18
  35. data/vendor/kreuzberg/src/bin/profile_extract.rs +455 -0
  36. data/vendor/kreuzberg/src/cache/mod.rs +3 -27
  37. data/vendor/kreuzberg/src/core/batch_mode.rs +0 -60
  38. data/vendor/kreuzberg/src/core/extractor.rs +81 -202
  39. data/vendor/kreuzberg/src/core/io.rs +2 -4
  40. data/vendor/kreuzberg/src/core/mime.rs +12 -2
  41. data/vendor/kreuzberg/src/core/mod.rs +1 -4
  42. data/vendor/kreuzberg/src/core/pipeline.rs +33 -111
  43. data/vendor/kreuzberg/src/embeddings.rs +16 -125
  44. data/vendor/kreuzberg/src/error.rs +1 -1
  45. data/vendor/kreuzberg/src/extraction/docx.rs +1 -1
  46. data/vendor/kreuzberg/src/extraction/image.rs +13 -13
  47. data/vendor/kreuzberg/src/extraction/libreoffice.rs +1 -0
  48. data/vendor/kreuzberg/src/extraction/mod.rs +5 -9
  49. data/vendor/kreuzberg/src/extraction/office_metadata/mod.rs +0 -2
  50. data/vendor/kreuzberg/src/extraction/pandoc/batch.rs +275 -0
  51. data/vendor/kreuzberg/src/extraction/pandoc/mime_types.rs +178 -0
  52. data/vendor/kreuzberg/src/extraction/pandoc/mod.rs +491 -0
  53. data/vendor/kreuzberg/src/extraction/pandoc/server.rs +496 -0
  54. data/vendor/kreuzberg/src/extraction/pandoc/subprocess.rs +1188 -0
  55. data/vendor/kreuzberg/src/extraction/pandoc/version.rs +162 -0
  56. data/vendor/kreuzberg/src/extractors/archive.rs +0 -21
  57. data/vendor/kreuzberg/src/extractors/docx.rs +128 -16
  58. data/vendor/kreuzberg/src/extractors/email.rs +0 -14
  59. data/vendor/kreuzberg/src/extractors/excel.rs +20 -19
  60. data/vendor/kreuzberg/src/extractors/html.rs +154 -137
  61. data/vendor/kreuzberg/src/extractors/image.rs +4 -7
  62. data/vendor/kreuzberg/src/extractors/mod.rs +9 -106
  63. data/vendor/kreuzberg/src/extractors/pandoc.rs +201 -0
  64. data/vendor/kreuzberg/src/extractors/pdf.rs +15 -12
  65. data/vendor/kreuzberg/src/extractors/pptx.rs +3 -17
  66. data/vendor/kreuzberg/src/extractors/structured.rs +0 -14
  67. data/vendor/kreuzberg/src/extractors/text.rs +5 -23
  68. data/vendor/kreuzberg/src/extractors/xml.rs +0 -7
  69. data/vendor/kreuzberg/src/keywords/rake.rs +1 -0
  70. data/vendor/kreuzberg/src/lib.rs +1 -4
  71. data/vendor/kreuzberg/src/mcp/mod.rs +1 -1
  72. data/vendor/kreuzberg/src/mcp/server.rs +3 -5
  73. data/vendor/kreuzberg/src/ocr/processor.rs +2 -18
  74. data/vendor/kreuzberg/src/pdf/error.rs +1 -1
  75. data/vendor/kreuzberg/src/pdf/table.rs +44 -17
  76. data/vendor/kreuzberg/src/pdf/text.rs +3 -0
  77. data/vendor/kreuzberg/src/plugins/extractor.rs +5 -8
  78. data/vendor/kreuzberg/src/plugins/ocr.rs +11 -2
  79. data/vendor/kreuzberg/src/plugins/processor.rs +1 -2
  80. data/vendor/kreuzberg/src/plugins/registry.rs +0 -13
  81. data/vendor/kreuzberg/src/plugins/validator.rs +8 -9
  82. data/vendor/kreuzberg/src/stopwords/mod.rs +2 -2
  83. data/vendor/kreuzberg/src/types.rs +12 -42
  84. data/vendor/kreuzberg/tests/batch_orchestration.rs +5 -19
  85. data/vendor/kreuzberg/tests/batch_processing.rs +3 -15
  86. data/vendor/kreuzberg/tests/chunking_offset_demo.rs +92 -0
  87. data/vendor/kreuzberg/tests/concurrency_stress.rs +1 -17
  88. data/vendor/kreuzberg/tests/config_features.rs +0 -18
  89. data/vendor/kreuzberg/tests/config_loading_tests.rs +39 -15
  90. data/vendor/kreuzberg/tests/core_integration.rs +7 -24
  91. data/vendor/kreuzberg/tests/csv_integration.rs +81 -71
  92. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +25 -23
  93. data/vendor/kreuzberg/tests/pandoc_integration.rs +503 -0
  94. data/vendor/kreuzberg/tests/pipeline_integration.rs +1 -0
  95. data/vendor/kreuzberg/tests/plugin_postprocessor_test.rs +1 -0
  96. data/vendor/kreuzberg/tests/registry_integration_tests.rs +22 -1
  97. data/vendor/kreuzberg/tests/security_validation.rs +1 -12
  98. metadata +25 -90
  99. data/.rubocop.yml +0 -538
  100. data/ext/kreuzberg_rb/native/Cargo.lock +0 -6535
  101. data/lib/kreuzberg/error_context.rb +0 -32
  102. data/vendor/kreuzberg/benches/otel_overhead.rs +0 -48
  103. data/vendor/kreuzberg/src/extraction/markdown.rs +0 -213
  104. data/vendor/kreuzberg/src/extraction/office_metadata/odt_properties.rs +0 -287
  105. data/vendor/kreuzberg/src/extractors/bibtex.rs +0 -469
  106. data/vendor/kreuzberg/src/extractors/docbook.rs +0 -502
  107. data/vendor/kreuzberg/src/extractors/epub.rs +0 -707
  108. data/vendor/kreuzberg/src/extractors/fictionbook.rs +0 -491
  109. data/vendor/kreuzberg/src/extractors/fictionbook.rs.backup2 +0 -738
  110. data/vendor/kreuzberg/src/extractors/jats.rs +0 -1051
  111. data/vendor/kreuzberg/src/extractors/jupyter.rs +0 -367
  112. data/vendor/kreuzberg/src/extractors/latex.rs +0 -652
  113. data/vendor/kreuzberg/src/extractors/markdown.rs +0 -700
  114. data/vendor/kreuzberg/src/extractors/odt.rs +0 -628
  115. data/vendor/kreuzberg/src/extractors/opml.rs +0 -634
  116. data/vendor/kreuzberg/src/extractors/orgmode.rs +0 -528
  117. data/vendor/kreuzberg/src/extractors/rst.rs +0 -576
  118. data/vendor/kreuzberg/src/extractors/rtf.rs +0 -810
  119. data/vendor/kreuzberg/src/extractors/security.rs +0 -484
  120. data/vendor/kreuzberg/src/extractors/security_tests.rs +0 -367
  121. data/vendor/kreuzberg/src/extractors/typst.rs +0 -650
  122. data/vendor/kreuzberg/src/panic_context.rs +0 -154
  123. data/vendor/kreuzberg/tests/api_extract_multipart.rs +0 -52
  124. data/vendor/kreuzberg/tests/bibtex_parity_test.rs +0 -421
  125. data/vendor/kreuzberg/tests/docbook_extractor_tests.rs +0 -498
  126. data/vendor/kreuzberg/tests/docx_vs_pandoc_comparison.rs +0 -370
  127. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +0 -275
  128. data/vendor/kreuzberg/tests/fictionbook_extractor_tests.rs +0 -228
  129. data/vendor/kreuzberg/tests/html_table_test.rs +0 -551
  130. data/vendor/kreuzberg/tests/instrumentation_test.rs +0 -139
  131. data/vendor/kreuzberg/tests/jats_extractor_tests.rs +0 -639
  132. data/vendor/kreuzberg/tests/jupyter_extractor_tests.rs +0 -704
  133. data/vendor/kreuzberg/tests/latex_extractor_tests.rs +0 -496
  134. data/vendor/kreuzberg/tests/markdown_extractor_tests.rs +0 -490
  135. data/vendor/kreuzberg/tests/odt_extractor_tests.rs +0 -695
  136. data/vendor/kreuzberg/tests/opml_extractor_tests.rs +0 -616
  137. data/vendor/kreuzberg/tests/orgmode_extractor_tests.rs +0 -822
  138. data/vendor/kreuzberg/tests/rst_extractor_tests.rs +0 -692
  139. data/vendor/kreuzberg/tests/rtf_extractor_tests.rs +0 -776
  140. data/vendor/kreuzberg/tests/typst_behavioral_tests.rs +0 -1259
  141. data/vendor/kreuzberg/tests/typst_extractor_tests.rs +0 -647
  142. data/vendor/rb-sys/.cargo-ok +0 -1
  143. data/vendor/rb-sys/.cargo_vcs_info.json +0 -6
  144. data/vendor/rb-sys/Cargo.lock +0 -393
  145. data/vendor/rb-sys/Cargo.toml +0 -70
  146. data/vendor/rb-sys/Cargo.toml.orig +0 -57
  147. data/vendor/rb-sys/LICENSE-APACHE +0 -190
  148. data/vendor/rb-sys/LICENSE-MIT +0 -21
  149. data/vendor/rb-sys/bin/release.sh +0 -21
  150. data/vendor/rb-sys/build/features.rs +0 -108
  151. data/vendor/rb-sys/build/main.rs +0 -246
  152. data/vendor/rb-sys/build/stable_api_config.rs +0 -153
  153. data/vendor/rb-sys/build/version.rs +0 -48
  154. data/vendor/rb-sys/readme.md +0 -36
  155. data/vendor/rb-sys/src/bindings.rs +0 -21
  156. data/vendor/rb-sys/src/hidden.rs +0 -11
  157. data/vendor/rb-sys/src/lib.rs +0 -34
  158. data/vendor/rb-sys/src/macros.rs +0 -371
  159. data/vendor/rb-sys/src/memory.rs +0 -53
  160. data/vendor/rb-sys/src/ruby_abi_version.rs +0 -38
  161. data/vendor/rb-sys/src/special_consts.rs +0 -31
  162. data/vendor/rb-sys/src/stable_api/compiled.c +0 -179
  163. data/vendor/rb-sys/src/stable_api/compiled.rs +0 -257
  164. data/vendor/rb-sys/src/stable_api/ruby_2_6.rs +0 -316
  165. data/vendor/rb-sys/src/stable_api/ruby_2_7.rs +0 -316
  166. data/vendor/rb-sys/src/stable_api/ruby_3_0.rs +0 -324
  167. data/vendor/rb-sys/src/stable_api/ruby_3_1.rs +0 -317
  168. data/vendor/rb-sys/src/stable_api/ruby_3_2.rs +0 -315
  169. data/vendor/rb-sys/src/stable_api/ruby_3_3.rs +0 -326
  170. data/vendor/rb-sys/src/stable_api/ruby_3_4.rs +0 -327
  171. data/vendor/rb-sys/src/stable_api.rs +0 -261
  172. data/vendor/rb-sys/src/symbol.rs +0 -31
  173. data/vendor/rb-sys/src/tracking_allocator.rs +0 -332
  174. data/vendor/rb-sys/src/utils.rs +0 -89
  175. data/vendor/rb-sys/src/value_type.rs +0 -7
@@ -1,528 +0,0 @@
1
- //! Native Org Mode extractor using the `org` library.
2
- //!
3
- //! This extractor provides comprehensive Org Mode document parsing and extraction.
4
- //! It extracts:
5
- //!
6
- //! - **Metadata**: #+TITLE, #+AUTHOR, #+DATE, #+KEYWORDS from document preamble
7
- //! - **Properties**: :PROPERTIES: drawers with additional metadata
8
- //! - **Headings**: Multi-level headings with proper hierarchy (* to *****)
9
- //! - **Content**: Paragraphs and text blocks
10
- //! - **Lists**: Ordered, unordered, and nested lists
11
- //! - **Code blocks**: #+BEGIN_SRC...#+END_SRC with language specification
12
- //! - **Tables**: Pipe tables (| cell | cell |) converted to Table structs
13
- //! - **Inline formatting**: *bold*, /italic/, =code=, ~verbatim~, [[links]]
14
- //!
15
- //! Requires the `office` feature.
16
-
17
- #[cfg(feature = "office")]
18
- use crate::Result;
19
- #[cfg(feature = "office")]
20
- use crate::core::config::ExtractionConfig;
21
- #[cfg(feature = "office")]
22
- use crate::plugins::{DocumentExtractor, Plugin};
23
- #[cfg(feature = "office")]
24
- use crate::types::{ExtractionResult, Metadata, Table};
25
- #[cfg(feature = "office")]
26
- use async_trait::async_trait;
27
- #[cfg(feature = "office")]
28
- use std::collections::HashMap;
29
-
30
- #[cfg(feature = "office")]
31
- use org::Org;
32
-
33
- /// Org Mode document extractor.
34
- ///
35
- /// Provides native Rust-based Org Mode extraction using the `org` library,
36
- /// extracting structured content and metadata.
37
- #[cfg(feature = "office")]
38
- pub struct OrgModeExtractor;
39
-
40
- #[cfg(feature = "office")]
41
- impl OrgModeExtractor {
42
- /// Create a new Org Mode extractor.
43
- pub fn new() -> Self {
44
- Self
45
- }
46
-
47
- /// Extract metadata and content from Org document in a single pass.
48
- ///
49
- /// Combines metadata extraction from directives and full document parsing
50
- /// into one efficient operation. Looks for:
51
- /// - #+TITLE: → title
52
- /// - #+AUTHOR: → author/authors
53
- /// - #+DATE: → date
54
- /// - #+KEYWORDS: → keywords
55
- /// - Other #+DIRECTIVE: entries
56
- ///
57
- /// Also extracts document structure and content in parallel.
58
- fn extract_metadata_and_content(org_text: &str, org: &Org) -> (Metadata, String) {
59
- let mut metadata = Metadata::default();
60
- let mut additional = HashMap::new();
61
-
62
- for line in org_text.lines().take(100) {
63
- let trimmed = line.trim();
64
-
65
- if let Some(rest) = trimmed.strip_prefix("#+TITLE:") {
66
- let value = rest.trim().to_string();
67
- additional.insert("title".to_string(), serde_json::json!(value));
68
- } else if let Some(rest) = trimmed.strip_prefix("#+AUTHOR:") {
69
- let value = rest.trim().to_string();
70
- additional.insert("author".to_string(), serde_json::json!(&value));
71
- additional.insert("authors".to_string(), serde_json::json!(vec![value]));
72
- } else if let Some(rest) = trimmed.strip_prefix("#+DATE:") {
73
- let value = rest.trim().to_string();
74
- metadata.date = Some(value.clone());
75
- additional.insert("date".to_string(), serde_json::json!(value));
76
- } else if let Some(rest) = trimmed.strip_prefix("#+KEYWORDS:") {
77
- let value = rest.trim();
78
- let keywords: Vec<&str> = value.split(',').map(|s| s.trim()).collect();
79
- additional.insert("keywords".to_string(), serde_json::json!(keywords));
80
- } else if let Some(rest) = trimmed.strip_prefix("#+")
81
- && let Some((key, val)) = rest.split_once(':')
82
- {
83
- let key_lower = key.trim().to_lowercase();
84
- let value = val.trim();
85
- if !key_lower.is_empty() && !value.is_empty() {
86
- additional.insert(format!("directive_{}", key_lower), serde_json::json!(value));
87
- }
88
- }
89
- }
90
-
91
- metadata.additional = additional;
92
-
93
- let content = Self::extract_content(org);
94
-
95
- (metadata, content)
96
- }
97
-
98
- /// Extract all content from an Org document using tree-based parsing.
99
- ///
100
- /// Uses org's tree-based API to recursively traverse the document structure:
101
- /// - Headings with proper hierarchy
102
- /// - Paragraphs
103
- /// - Lists (both ordered and unordered)
104
- /// - Code blocks with language info
105
- /// - Tables as structured data
106
- /// - Inline formatting markers
107
- fn extract_content(org: &Org) -> String {
108
- let mut content = String::new();
109
- Self::extract_org_tree(org, &mut content);
110
- content.trim().to_string()
111
- }
112
-
113
- /// Recursively walk the Org tree and extract content.
114
- ///
115
- /// Processes:
116
- /// - Heading text from `org.heading()`
117
- /// - Content lines from `org.content_as_ref()`
118
- /// - Subtrees from `org.subtrees_as_ref()`
119
- fn extract_org_tree(org: &Org, content: &mut String) {
120
- let heading = org.heading();
121
- if !heading.is_empty() {
122
- content.push_str("# ");
123
- content.push_str(heading);
124
- content.push('\n');
125
- }
126
-
127
- let lines = org.content_as_ref();
128
- if !lines.is_empty() {
129
- for line in lines {
130
- let trimmed = line.trim();
131
- if !trimmed.is_empty() {
132
- content.push_str(trimmed);
133
- content.push('\n');
134
- }
135
- }
136
- content.push('\n');
137
- }
138
-
139
- let subtrees = org.subtrees_as_ref();
140
- for subtree in subtrees {
141
- Self::extract_org_tree(subtree, content);
142
- }
143
- }
144
-
145
- /// Extract tables from an Org document.
146
- ///
147
- /// Recursively walks the tree and extracts table elements,
148
- /// converting them to Table structs with markdown format.
149
- fn extract_tables(org: &Org) -> Vec<Table> {
150
- let mut tables = Vec::new();
151
- Self::extract_tables_from_tree(org, &mut tables);
152
- tables
153
- }
154
-
155
- /// Recursively extract tables from an Org tree node and its subtrees.
156
- fn extract_tables_from_tree(org: &Org, tables: &mut Vec<Table>) {
157
- let lines = org.content_as_ref();
158
- if !lines.is_empty() {
159
- let mut in_table = false;
160
- let mut current_table: Vec<Vec<String>> = Vec::new();
161
-
162
- for line in lines {
163
- let trimmed = line.trim();
164
-
165
- if trimmed.starts_with('|') && trimmed.ends_with('|') {
166
- in_table = true;
167
-
168
- let cells: Vec<String> = trimmed
169
- .split('|')
170
- .map(|cell| cell.trim().to_string())
171
- .filter(|cell| !cell.is_empty())
172
- .collect();
173
-
174
- if !cells.is_empty() {
175
- current_table.push(cells);
176
- }
177
- } else if in_table {
178
- if !current_table.is_empty() {
179
- let markdown = Self::cells_to_markdown(&current_table);
180
- tables.push(Table {
181
- cells: current_table.clone(),
182
- markdown,
183
- page_number: 1,
184
- });
185
- current_table.clear();
186
- }
187
- in_table = false;
188
- }
189
- }
190
-
191
- if !current_table.is_empty() {
192
- let markdown = Self::cells_to_markdown(&current_table);
193
- tables.push(Table {
194
- cells: current_table,
195
- markdown,
196
- page_number: 1,
197
- });
198
- }
199
- }
200
-
201
- let subtrees = org.subtrees_as_ref();
202
- for subtree in subtrees {
203
- Self::extract_tables_from_tree(subtree, tables);
204
- }
205
- }
206
-
207
- /// Convert table cells to markdown format.
208
- fn cells_to_markdown(cells: &[Vec<String>]) -> String {
209
- if cells.is_empty() {
210
- return String::new();
211
- }
212
-
213
- let mut md = String::new();
214
-
215
- for (row_idx, row) in cells.iter().enumerate() {
216
- md.push('|');
217
- for cell in row {
218
- md.push(' ');
219
- md.push_str(cell);
220
- md.push_str(" |");
221
- }
222
- md.push('\n');
223
-
224
- if row_idx == 0 && cells.len() > 1 {
225
- md.push('|');
226
- for _ in row {
227
- md.push_str(" --- |");
228
- }
229
- md.push('\n');
230
- }
231
- }
232
-
233
- md
234
- }
235
- }
236
-
237
- #[cfg(feature = "office")]
238
- impl Default for OrgModeExtractor {
239
- fn default() -> Self {
240
- Self::new()
241
- }
242
- }
243
-
244
- #[cfg(feature = "office")]
245
- impl Plugin for OrgModeExtractor {
246
- fn name(&self) -> &str {
247
- "orgmode-extractor"
248
- }
249
-
250
- fn version(&self) -> String {
251
- env!("CARGO_PKG_VERSION").to_string()
252
- }
253
-
254
- fn initialize(&self) -> Result<()> {
255
- Ok(())
256
- }
257
-
258
- fn shutdown(&self) -> Result<()> {
259
- Ok(())
260
- }
261
-
262
- fn description(&self) -> &str {
263
- "Native Rust extractor for Org Mode documents with comprehensive metadata extraction"
264
- }
265
-
266
- fn author(&self) -> &str {
267
- "Kreuzberg Team"
268
- }
269
- }
270
-
271
- #[cfg(feature = "office")]
272
- #[async_trait]
273
- impl DocumentExtractor for OrgModeExtractor {
274
- #[cfg_attr(
275
- feature = "otel",
276
- tracing::instrument(
277
- skip(self, content, _config),
278
- fields(
279
- extractor.name = self.name(),
280
- content.size_bytes = content.len(),
281
- )
282
- )
283
- )]
284
- async fn extract_bytes(
285
- &self,
286
- content: &[u8],
287
- mime_type: &str,
288
- _config: &ExtractionConfig,
289
- ) -> Result<ExtractionResult> {
290
- let org_text = String::from_utf8_lossy(content).into_owned();
291
-
292
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
293
- let org = Org::from_vec(&lines)?;
294
-
295
- let (metadata, extracted_content) = Self::extract_metadata_and_content(&org_text, &org);
296
-
297
- let tables = Self::extract_tables(&org);
298
-
299
- Ok(ExtractionResult {
300
- content: extracted_content,
301
- mime_type: mime_type.to_string(),
302
- metadata,
303
- tables,
304
- detected_languages: None,
305
- chunks: None,
306
- images: None,
307
- })
308
- }
309
-
310
- fn supported_mime_types(&self) -> &[&str] {
311
- &["text/x-org", "text/org", "application/x-org"]
312
- }
313
-
314
- fn priority(&self) -> i32 {
315
- 50
316
- }
317
- }
318
-
319
- #[cfg(all(test, feature = "office"))]
320
- mod tests {
321
- use super::*;
322
-
323
- #[test]
324
- fn test_orgmode_extractor_plugin_interface() {
325
- let extractor = OrgModeExtractor::new();
326
- assert_eq!(extractor.name(), "orgmode-extractor");
327
- assert_eq!(extractor.version(), env!("CARGO_PKG_VERSION"));
328
- assert_eq!(extractor.priority(), 50);
329
- assert!(!extractor.supported_mime_types().is_empty());
330
- }
331
-
332
- #[test]
333
- fn test_orgmode_extractor_supports_text_x_org() {
334
- let extractor = OrgModeExtractor::new();
335
- assert!(extractor.supported_mime_types().contains(&"text/x-org"));
336
- }
337
-
338
- #[test]
339
- fn test_orgmode_extractor_default() {
340
- let extractor = OrgModeExtractor;
341
- assert_eq!(extractor.name(), "orgmode-extractor");
342
- }
343
-
344
- #[test]
345
- fn test_orgmode_extractor_initialize_shutdown() {
346
- let extractor = OrgModeExtractor::new();
347
- assert!(extractor.initialize().is_ok());
348
- assert!(extractor.shutdown().is_ok());
349
- }
350
-
351
- #[test]
352
- fn test_extract_metadata_with_title() {
353
- let org_text = "#+TITLE: Test Document\n\nContent here.";
354
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
355
- let org = Org::from_vec(&lines).expect("Failed to parse org");
356
- let (metadata, _) = OrgModeExtractor::extract_metadata_and_content(org_text, &org);
357
-
358
- assert!(metadata.additional.get("title").and_then(|v| v.as_str()).is_some());
359
- }
360
-
361
- #[test]
362
- fn test_extract_metadata_with_author() {
363
- let org_text = "#+AUTHOR: John Doe\n\nContent here.";
364
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
365
- let org = Org::from_vec(&lines).expect("Failed to parse org");
366
- let (metadata, _) = OrgModeExtractor::extract_metadata_and_content(org_text, &org);
367
-
368
- assert!(metadata.additional.get("author").and_then(|v| v.as_str()).is_some());
369
- }
370
-
371
- #[test]
372
- fn test_extract_metadata_with_date() {
373
- let org_text = "#+DATE: 2024-01-15\n\nContent here.";
374
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
375
- let org = Org::from_vec(&lines).expect("Failed to parse org");
376
- let (metadata, _) = OrgModeExtractor::extract_metadata_and_content(org_text, &org);
377
-
378
- assert_eq!(metadata.date, Some("2024-01-15".to_string()));
379
- }
380
-
381
- #[test]
382
- fn test_extract_metadata_with_keywords() {
383
- let org_text = "#+KEYWORDS: rust, org-mode, parsing\n\nContent here.";
384
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
385
- let org = Org::from_vec(&lines).expect("Failed to parse org");
386
- let (metadata, _) = OrgModeExtractor::extract_metadata_and_content(org_text, &org);
387
-
388
- let keywords = metadata.additional.get("keywords").and_then(|v| v.as_array());
389
- assert!(keywords.is_some());
390
- }
391
-
392
- #[test]
393
- fn test_extract_content_with_headings() {
394
- let org_text = "* Heading 1\n\nSome content.\n\n** Heading 2\n\nMore content.";
395
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
396
- let org = Org::from_vec(&lines).expect("Failed to parse org");
397
- let content = OrgModeExtractor::extract_content(&org);
398
-
399
- assert!(content.contains("Heading 1"));
400
- assert!(content.contains("Heading 2"));
401
- assert!(content.contains("Some content"));
402
- assert!(content.contains("More content"));
403
- }
404
-
405
- #[test]
406
- fn test_extract_content_with_paragraphs() {
407
- let org_text = "First paragraph.\n\nSecond paragraph.";
408
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
409
- let org = Org::from_vec(&lines).expect("Failed to parse org");
410
- let content = OrgModeExtractor::extract_content(&org);
411
-
412
- assert!(content.contains("First paragraph"));
413
- assert!(content.contains("Second paragraph"));
414
- }
415
-
416
- #[test]
417
- fn test_extract_content_with_lists() {
418
- let org_text = "- Item 1\n- Item 2\n- Item 3";
419
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
420
- let org = Org::from_vec(&lines).expect("Failed to parse org");
421
- let content = OrgModeExtractor::extract_content(&org);
422
-
423
- assert!(content.contains("Item 1"));
424
- assert!(content.contains("Item 2"));
425
- assert!(content.contains("Item 3"));
426
- }
427
-
428
- #[test]
429
- fn test_cells_to_markdown_format() {
430
- let cells = vec![
431
- vec!["Name".to_string(), "Age".to_string()],
432
- vec!["Alice".to_string(), "30".to_string()],
433
- vec!["Bob".to_string(), "25".to_string()],
434
- ];
435
-
436
- let markdown = OrgModeExtractor::cells_to_markdown(&cells);
437
- assert!(markdown.contains("Name"));
438
- assert!(markdown.contains("Age"));
439
- assert!(markdown.contains("Alice"));
440
- assert!(markdown.contains("Bob"));
441
- assert!(markdown.contains("---"));
442
- }
443
-
444
- #[test]
445
- fn test_orgmode_extractor_supported_mime_types() {
446
- let extractor = OrgModeExtractor::new();
447
- let supported = extractor.supported_mime_types();
448
- assert!(supported.contains(&"text/x-org"));
449
- }
450
-
451
- #[test]
452
- fn test_link_with_description() {
453
- let org_text = r#"* Links Test
454
-
455
- [[http://att.com/][AT&T]]
456
- "#;
457
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
458
- let org = Org::from_vec(&lines).expect("Failed to parse org");
459
- let content = OrgModeExtractor::extract_content(&org);
460
-
461
- assert!(content.contains("AT&T"), "Should contain link description 'AT&T'");
462
- }
463
-
464
- #[test]
465
- fn test_link_without_description() {
466
- let org_text = r#"* Links Test
467
-
468
- [[https://example.com]]
469
- "#;
470
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
471
- let org = Org::from_vec(&lines).expect("Failed to parse org");
472
- let content = OrgModeExtractor::extract_content(&org);
473
-
474
- assert!(
475
- content.contains("example.com"),
476
- "Should contain link path when no description provided"
477
- );
478
- }
479
-
480
- #[test]
481
- fn test_link_with_ampersand_in_description() {
482
- let org_text = r#"* Company Links
483
-
484
- [[http://att.com/][AT&T Company]]
485
- "#;
486
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
487
- let org = Org::from_vec(&lines).expect("Failed to parse org");
488
- let content = OrgModeExtractor::extract_content(&org);
489
-
490
- assert!(
491
- content.contains("AT&T"),
492
- "Should preserve ampersand in link description"
493
- );
494
- }
495
-
496
- #[test]
497
- fn test_multiple_links_with_mixed_descriptions() {
498
- let org_text = r#"* Multiple Links
499
-
500
- [[https://example.com][Example Link]]
501
-
502
- [[https://example.org]]
503
-
504
- [[mailto:test@example.com][Contact]]
505
- "#;
506
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
507
- let org = Org::from_vec(&lines).expect("Failed to parse org");
508
- let content = OrgModeExtractor::extract_content(&org);
509
-
510
- assert!(content.contains("Example Link"));
511
- assert!(content.contains("example.org"));
512
- assert!(content.contains("Contact"));
513
- }
514
-
515
- #[test]
516
- fn test_link_description_priority_over_url() {
517
- let org_text = r#"[[http://att.com/][AT&T]]"#;
518
- let lines: Vec<String> = org_text.lines().map(|s| s.to_string()).collect();
519
- let org = Org::from_vec(&lines).expect("Failed to parse org");
520
- let content = OrgModeExtractor::extract_content(&org);
521
-
522
- assert!(content.contains("AT&T"), "Description should be prioritized over URL");
523
- assert!(
524
- content.contains("[AT&T]"),
525
- "Link should be formatted as [description] when description exists"
526
- );
527
- }
528
- }