kreuzberg 4.0.8 → 4.1.0

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 (308) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +1 -1
  4. data/ext/kreuzberg_rb/native/Cargo.lock +94 -98
  5. data/ext/kreuzberg_rb/native/Cargo.toml +4 -2
  6. data/ext/kreuzberg_rb/native/src/batch.rs +139 -0
  7. data/ext/kreuzberg_rb/native/src/config/mod.rs +10 -0
  8. data/ext/kreuzberg_rb/native/src/config/types.rs +1058 -0
  9. data/ext/kreuzberg_rb/native/src/error_handling.rs +125 -0
  10. data/ext/kreuzberg_rb/native/src/extraction.rs +79 -0
  11. data/ext/kreuzberg_rb/native/src/gc_guarded_value.rs +35 -0
  12. data/ext/kreuzberg_rb/native/src/helpers.rs +176 -0
  13. data/ext/kreuzberg_rb/native/src/lib.rs +342 -3622
  14. data/ext/kreuzberg_rb/native/src/metadata.rs +34 -0
  15. data/ext/kreuzberg_rb/native/src/plugins/mod.rs +92 -0
  16. data/ext/kreuzberg_rb/native/src/plugins/ocr_backend.rs +159 -0
  17. data/ext/kreuzberg_rb/native/src/plugins/post_processor.rs +126 -0
  18. data/ext/kreuzberg_rb/native/src/plugins/validator.rs +99 -0
  19. data/ext/kreuzberg_rb/native/src/result.rs +326 -0
  20. data/ext/kreuzberg_rb/native/src/validation.rs +4 -0
  21. data/lib/kreuzberg/config.rb +66 -0
  22. data/lib/kreuzberg/result.rb +107 -2
  23. data/lib/kreuzberg/types.rb +104 -0
  24. data/lib/kreuzberg/version.rb +1 -1
  25. data/lib/kreuzberg.rb +0 -4
  26. data/sig/kreuzberg.rbs +105 -1
  27. data/vendor/Cargo.toml +3 -3
  28. data/vendor/kreuzberg/Cargo.toml +4 -3
  29. data/vendor/kreuzberg/README.md +1 -1
  30. data/vendor/kreuzberg/src/api/config.rs +69 -0
  31. data/vendor/kreuzberg/src/api/handlers.rs +99 -2
  32. data/vendor/kreuzberg/src/api/mod.rs +14 -7
  33. data/vendor/kreuzberg/src/api/router.rs +214 -0
  34. data/vendor/kreuzberg/src/api/startup.rs +243 -0
  35. data/vendor/kreuzberg/src/api/types.rs +78 -0
  36. data/vendor/kreuzberg/src/cache/cleanup.rs +277 -0
  37. data/vendor/kreuzberg/src/cache/core.rs +428 -0
  38. data/vendor/kreuzberg/src/cache/mod.rs +21 -843
  39. data/vendor/kreuzberg/src/cache/utilities.rs +156 -0
  40. data/vendor/kreuzberg/src/chunking/boundaries.rs +301 -0
  41. data/vendor/kreuzberg/src/chunking/builder.rs +294 -0
  42. data/vendor/kreuzberg/src/chunking/config.rs +52 -0
  43. data/vendor/kreuzberg/src/chunking/core.rs +1017 -0
  44. data/vendor/kreuzberg/src/chunking/mod.rs +14 -2211
  45. data/vendor/kreuzberg/src/chunking/processor.rs +10 -0
  46. data/vendor/kreuzberg/src/chunking/validation.rs +686 -0
  47. data/vendor/kreuzberg/src/core/config/extraction/core.rs +169 -0
  48. data/vendor/kreuzberg/src/core/config/extraction/env.rs +179 -0
  49. data/vendor/kreuzberg/src/core/config/extraction/loaders.rs +204 -0
  50. data/vendor/kreuzberg/src/core/config/extraction/mod.rs +42 -0
  51. data/vendor/kreuzberg/src/core/config/extraction/types.rs +93 -0
  52. data/vendor/kreuzberg/src/core/config/formats.rs +135 -0
  53. data/vendor/kreuzberg/src/core/config/mod.rs +20 -0
  54. data/vendor/kreuzberg/src/core/config/ocr.rs +73 -0
  55. data/vendor/kreuzberg/src/core/config/page.rs +57 -0
  56. data/vendor/kreuzberg/src/core/config/pdf.rs +111 -0
  57. data/vendor/kreuzberg/src/core/config/processing.rs +312 -0
  58. data/vendor/kreuzberg/src/core/config_validation/dependencies.rs +187 -0
  59. data/vendor/kreuzberg/src/core/config_validation/mod.rs +386 -0
  60. data/vendor/kreuzberg/src/core/config_validation/sections.rs +401 -0
  61. data/vendor/kreuzberg/src/core/extractor/batch.rs +246 -0
  62. data/vendor/kreuzberg/src/core/extractor/bytes.rs +116 -0
  63. data/vendor/kreuzberg/src/core/extractor/file.rs +240 -0
  64. data/vendor/kreuzberg/src/core/extractor/helpers.rs +71 -0
  65. data/vendor/kreuzberg/src/core/extractor/legacy.rs +62 -0
  66. data/vendor/kreuzberg/src/core/extractor/mod.rs +490 -0
  67. data/vendor/kreuzberg/src/core/extractor/sync.rs +208 -0
  68. data/vendor/kreuzberg/src/core/mod.rs +4 -1
  69. data/vendor/kreuzberg/src/core/pipeline/cache.rs +60 -0
  70. data/vendor/kreuzberg/src/core/pipeline/execution.rs +89 -0
  71. data/vendor/kreuzberg/src/core/pipeline/features.rs +108 -0
  72. data/vendor/kreuzberg/src/core/pipeline/format.rs +392 -0
  73. data/vendor/kreuzberg/src/core/pipeline/initialization.rs +67 -0
  74. data/vendor/kreuzberg/src/core/pipeline/mod.rs +135 -0
  75. data/vendor/kreuzberg/src/core/pipeline/tests.rs +975 -0
  76. data/vendor/kreuzberg/src/core/server_config/env.rs +90 -0
  77. data/vendor/kreuzberg/src/core/server_config/loader.rs +202 -0
  78. data/vendor/kreuzberg/src/core/server_config/mod.rs +380 -0
  79. data/vendor/kreuzberg/src/core/server_config/tests/basic_tests.rs +124 -0
  80. data/vendor/kreuzberg/src/core/server_config/tests/env_tests.rs +216 -0
  81. data/vendor/kreuzberg/src/core/server_config/tests/file_loading_tests.rs +341 -0
  82. data/vendor/kreuzberg/src/core/server_config/tests/mod.rs +5 -0
  83. data/vendor/kreuzberg/src/core/server_config/validation.rs +17 -0
  84. data/vendor/kreuzberg/src/embeddings.rs +136 -13
  85. data/vendor/kreuzberg/src/extraction/{archive.rs → archive/mod.rs} +45 -239
  86. data/vendor/kreuzberg/src/extraction/archive/sevenz.rs +98 -0
  87. data/vendor/kreuzberg/src/extraction/archive/tar.rs +118 -0
  88. data/vendor/kreuzberg/src/extraction/archive/zip.rs +101 -0
  89. data/vendor/kreuzberg/src/extraction/html/converter.rs +592 -0
  90. data/vendor/kreuzberg/src/extraction/html/image_handling.rs +95 -0
  91. data/vendor/kreuzberg/src/extraction/html/mod.rs +53 -0
  92. data/vendor/kreuzberg/src/extraction/html/processor.rs +659 -0
  93. data/vendor/kreuzberg/src/extraction/html/stack_management.rs +103 -0
  94. data/vendor/kreuzberg/src/extraction/html/types.rs +28 -0
  95. data/vendor/kreuzberg/src/extraction/mod.rs +6 -2
  96. data/vendor/kreuzberg/src/extraction/pptx/container.rs +159 -0
  97. data/vendor/kreuzberg/src/extraction/pptx/content_builder.rs +168 -0
  98. data/vendor/kreuzberg/src/extraction/pptx/elements.rs +132 -0
  99. data/vendor/kreuzberg/src/extraction/pptx/image_handling.rs +57 -0
  100. data/vendor/kreuzberg/src/extraction/pptx/metadata.rs +160 -0
  101. data/vendor/kreuzberg/src/extraction/pptx/mod.rs +558 -0
  102. data/vendor/kreuzberg/src/extraction/pptx/parser.rs +379 -0
  103. data/vendor/kreuzberg/src/extraction/transform/content.rs +205 -0
  104. data/vendor/kreuzberg/src/extraction/transform/elements.rs +211 -0
  105. data/vendor/kreuzberg/src/extraction/transform/mod.rs +480 -0
  106. data/vendor/kreuzberg/src/extraction/transform/types.rs +27 -0
  107. data/vendor/kreuzberg/src/extractors/archive.rs +2 -0
  108. data/vendor/kreuzberg/src/extractors/bibtex.rs +2 -0
  109. data/vendor/kreuzberg/src/extractors/djot_format/attributes.rs +134 -0
  110. data/vendor/kreuzberg/src/extractors/djot_format/conversion.rs +223 -0
  111. data/vendor/kreuzberg/src/extractors/djot_format/extractor.rs +172 -0
  112. data/vendor/kreuzberg/src/extractors/djot_format/mod.rs +24 -0
  113. data/vendor/kreuzberg/src/extractors/djot_format/parsing/block_handlers.rs +271 -0
  114. data/vendor/kreuzberg/src/extractors/djot_format/parsing/content_extraction.rs +257 -0
  115. data/vendor/kreuzberg/src/extractors/djot_format/parsing/event_handlers.rs +101 -0
  116. data/vendor/kreuzberg/src/extractors/djot_format/parsing/inline_handlers.rs +201 -0
  117. data/vendor/kreuzberg/src/extractors/djot_format/parsing/mod.rs +16 -0
  118. data/vendor/kreuzberg/src/extractors/djot_format/parsing/state.rs +78 -0
  119. data/vendor/kreuzberg/src/extractors/djot_format/parsing/table_extraction.rs +68 -0
  120. data/vendor/kreuzberg/src/extractors/djot_format/parsing/text_extraction.rs +61 -0
  121. data/vendor/kreuzberg/src/extractors/djot_format/rendering.rs +452 -0
  122. data/vendor/kreuzberg/src/extractors/docbook.rs +2 -0
  123. data/vendor/kreuzberg/src/extractors/docx.rs +12 -1
  124. data/vendor/kreuzberg/src/extractors/email.rs +2 -0
  125. data/vendor/kreuzberg/src/extractors/epub/content.rs +333 -0
  126. data/vendor/kreuzberg/src/extractors/epub/metadata.rs +137 -0
  127. data/vendor/kreuzberg/src/extractors/epub/mod.rs +186 -0
  128. data/vendor/kreuzberg/src/extractors/epub/parsing.rs +86 -0
  129. data/vendor/kreuzberg/src/extractors/excel.rs +4 -0
  130. data/vendor/kreuzberg/src/extractors/fictionbook.rs +2 -0
  131. data/vendor/kreuzberg/src/extractors/frontmatter_utils.rs +466 -0
  132. data/vendor/kreuzberg/src/extractors/html.rs +80 -8
  133. data/vendor/kreuzberg/src/extractors/image.rs +8 -1
  134. data/vendor/kreuzberg/src/extractors/jats/elements.rs +350 -0
  135. data/vendor/kreuzberg/src/extractors/jats/metadata.rs +21 -0
  136. data/vendor/kreuzberg/src/extractors/{jats.rs → jats/mod.rs} +10 -412
  137. data/vendor/kreuzberg/src/extractors/jats/parser.rs +52 -0
  138. data/vendor/kreuzberg/src/extractors/jupyter.rs +2 -0
  139. data/vendor/kreuzberg/src/extractors/latex/commands.rs +93 -0
  140. data/vendor/kreuzberg/src/extractors/latex/environments.rs +157 -0
  141. data/vendor/kreuzberg/src/extractors/latex/metadata.rs +27 -0
  142. data/vendor/kreuzberg/src/extractors/latex/mod.rs +146 -0
  143. data/vendor/kreuzberg/src/extractors/latex/parser.rs +231 -0
  144. data/vendor/kreuzberg/src/extractors/latex/utilities.rs +126 -0
  145. data/vendor/kreuzberg/src/extractors/markdown.rs +39 -162
  146. data/vendor/kreuzberg/src/extractors/mod.rs +9 -1
  147. data/vendor/kreuzberg/src/extractors/odt.rs +2 -0
  148. data/vendor/kreuzberg/src/extractors/opml/core.rs +165 -0
  149. data/vendor/kreuzberg/src/extractors/opml/mod.rs +31 -0
  150. data/vendor/kreuzberg/src/extractors/opml/parser.rs +479 -0
  151. data/vendor/kreuzberg/src/extractors/orgmode.rs +2 -0
  152. data/vendor/kreuzberg/src/extractors/pdf/extraction.rs +106 -0
  153. data/vendor/kreuzberg/src/extractors/{pdf.rs → pdf/mod.rs} +25 -324
  154. data/vendor/kreuzberg/src/extractors/pdf/ocr.rs +214 -0
  155. data/vendor/kreuzberg/src/extractors/pdf/pages.rs +51 -0
  156. data/vendor/kreuzberg/src/extractors/pptx.rs +9 -2
  157. data/vendor/kreuzberg/src/extractors/rst.rs +2 -0
  158. data/vendor/kreuzberg/src/extractors/rtf/encoding.rs +116 -0
  159. data/vendor/kreuzberg/src/extractors/rtf/formatting.rs +24 -0
  160. data/vendor/kreuzberg/src/extractors/rtf/images.rs +72 -0
  161. data/vendor/kreuzberg/src/extractors/rtf/metadata.rs +216 -0
  162. data/vendor/kreuzberg/src/extractors/rtf/mod.rs +142 -0
  163. data/vendor/kreuzberg/src/extractors/rtf/parser.rs +259 -0
  164. data/vendor/kreuzberg/src/extractors/rtf/tables.rs +83 -0
  165. data/vendor/kreuzberg/src/extractors/structured.rs +2 -0
  166. data/vendor/kreuzberg/src/extractors/text.rs +4 -0
  167. data/vendor/kreuzberg/src/extractors/typst.rs +2 -0
  168. data/vendor/kreuzberg/src/extractors/xml.rs +2 -0
  169. data/vendor/kreuzberg/src/keywords/processor.rs +14 -0
  170. data/vendor/kreuzberg/src/language_detection/processor.rs +10 -0
  171. data/vendor/kreuzberg/src/lib.rs +2 -2
  172. data/vendor/kreuzberg/src/mcp/errors.rs +312 -0
  173. data/vendor/kreuzberg/src/mcp/format.rs +211 -0
  174. data/vendor/kreuzberg/src/mcp/mod.rs +9 -3
  175. data/vendor/kreuzberg/src/mcp/params.rs +196 -0
  176. data/vendor/kreuzberg/src/mcp/server.rs +39 -1438
  177. data/vendor/kreuzberg/src/mcp/tools/cache.rs +179 -0
  178. data/vendor/kreuzberg/src/mcp/tools/extraction.rs +403 -0
  179. data/vendor/kreuzberg/src/mcp/tools/mime.rs +150 -0
  180. data/vendor/kreuzberg/src/mcp/tools/mod.rs +11 -0
  181. data/vendor/kreuzberg/src/ocr/backends/easyocr.rs +96 -0
  182. data/vendor/kreuzberg/src/ocr/backends/mod.rs +7 -0
  183. data/vendor/kreuzberg/src/ocr/backends/paddleocr.rs +27 -0
  184. data/vendor/kreuzberg/src/ocr/backends/tesseract.rs +134 -0
  185. data/vendor/kreuzberg/src/ocr/hocr.rs +60 -16
  186. data/vendor/kreuzberg/src/ocr/language_registry.rs +11 -235
  187. data/vendor/kreuzberg/src/ocr/mod.rs +1 -0
  188. data/vendor/kreuzberg/src/ocr/processor/config.rs +203 -0
  189. data/vendor/kreuzberg/src/ocr/processor/execution.rs +494 -0
  190. data/vendor/kreuzberg/src/ocr/processor/mod.rs +265 -0
  191. data/vendor/kreuzberg/src/ocr/processor/validation.rs +145 -0
  192. data/vendor/kreuzberg/src/ocr/tesseract_backend.rs +41 -24
  193. data/vendor/kreuzberg/src/pdf/bindings.rs +21 -8
  194. data/vendor/kreuzberg/src/pdf/hierarchy/bounding_box.rs +289 -0
  195. data/vendor/kreuzberg/src/pdf/hierarchy/clustering.rs +199 -0
  196. data/vendor/kreuzberg/src/pdf/{hierarchy.rs → hierarchy/extraction.rs} +6 -346
  197. data/vendor/kreuzberg/src/pdf/hierarchy/mod.rs +18 -0
  198. data/vendor/kreuzberg/src/plugins/extractor/mod.rs +319 -0
  199. data/vendor/kreuzberg/src/plugins/extractor/registry.rs +434 -0
  200. data/vendor/kreuzberg/src/plugins/extractor/trait.rs +391 -0
  201. data/vendor/kreuzberg/src/plugins/mod.rs +13 -0
  202. data/vendor/kreuzberg/src/plugins/ocr.rs +11 -0
  203. data/vendor/kreuzberg/src/plugins/processor/mod.rs +365 -0
  204. data/vendor/kreuzberg/src/plugins/processor/registry.rs +37 -0
  205. data/vendor/kreuzberg/src/plugins/processor/trait.rs +284 -0
  206. data/vendor/kreuzberg/src/plugins/registry/extractor.rs +416 -0
  207. data/vendor/kreuzberg/src/plugins/registry/mod.rs +116 -0
  208. data/vendor/kreuzberg/src/plugins/registry/ocr.rs +293 -0
  209. data/vendor/kreuzberg/src/plugins/registry/processor.rs +304 -0
  210. data/vendor/kreuzberg/src/plugins/registry/validator.rs +238 -0
  211. data/vendor/kreuzberg/src/plugins/validator/mod.rs +424 -0
  212. data/vendor/kreuzberg/src/plugins/validator/registry.rs +355 -0
  213. data/vendor/kreuzberg/src/plugins/validator/trait.rs +276 -0
  214. data/vendor/kreuzberg/src/stopwords/languages/asian.rs +40 -0
  215. data/vendor/kreuzberg/src/stopwords/languages/germanic.rs +36 -0
  216. data/vendor/kreuzberg/src/stopwords/languages/mod.rs +10 -0
  217. data/vendor/kreuzberg/src/stopwords/languages/other.rs +44 -0
  218. data/vendor/kreuzberg/src/stopwords/languages/romance.rs +36 -0
  219. data/vendor/kreuzberg/src/stopwords/languages/slavic.rs +36 -0
  220. data/vendor/kreuzberg/src/stopwords/mod.rs +7 -33
  221. data/vendor/kreuzberg/src/text/quality.rs +1 -1
  222. data/vendor/kreuzberg/src/text/quality_processor.rs +10 -0
  223. data/vendor/kreuzberg/src/text/token_reduction/core/analysis.rs +238 -0
  224. data/vendor/kreuzberg/src/text/token_reduction/core/mod.rs +8 -0
  225. data/vendor/kreuzberg/src/text/token_reduction/core/punctuation.rs +54 -0
  226. data/vendor/kreuzberg/src/text/token_reduction/core/reducer.rs +384 -0
  227. data/vendor/kreuzberg/src/text/token_reduction/core/sentence_selection.rs +68 -0
  228. data/vendor/kreuzberg/src/text/token_reduction/core/word_filtering.rs +156 -0
  229. data/vendor/kreuzberg/src/text/token_reduction/filters/general.rs +377 -0
  230. data/vendor/kreuzberg/src/text/token_reduction/filters/html.rs +51 -0
  231. data/vendor/kreuzberg/src/text/token_reduction/filters/markdown.rs +285 -0
  232. data/vendor/kreuzberg/src/text/token_reduction/filters.rs +131 -246
  233. data/vendor/kreuzberg/src/types/djot.rs +209 -0
  234. data/vendor/kreuzberg/src/types/extraction.rs +301 -0
  235. data/vendor/kreuzberg/src/types/formats.rs +443 -0
  236. data/vendor/kreuzberg/src/types/metadata.rs +560 -0
  237. data/vendor/kreuzberg/src/types/mod.rs +281 -0
  238. data/vendor/kreuzberg/src/types/page.rs +182 -0
  239. data/vendor/kreuzberg/src/types/serde_helpers.rs +132 -0
  240. data/vendor/kreuzberg/src/types/tables.rs +39 -0
  241. data/vendor/kreuzberg/src/utils/quality/heuristics.rs +58 -0
  242. data/vendor/kreuzberg/src/utils/{quality.rs → quality/mod.rs} +168 -489
  243. data/vendor/kreuzberg/src/utils/quality/patterns.rs +117 -0
  244. data/vendor/kreuzberg/src/utils/quality/scoring.rs +178 -0
  245. data/vendor/kreuzberg/src/utils/string_pool/buffer_pool.rs +325 -0
  246. data/vendor/kreuzberg/src/utils/string_pool/interned.rs +102 -0
  247. data/vendor/kreuzberg/src/utils/string_pool/language_pool.rs +119 -0
  248. data/vendor/kreuzberg/src/utils/string_pool/mime_pool.rs +235 -0
  249. data/vendor/kreuzberg/src/utils/string_pool/mod.rs +41 -0
  250. data/vendor/kreuzberg/tests/api_chunk.rs +313 -0
  251. data/vendor/kreuzberg/tests/api_embed.rs +6 -9
  252. data/vendor/kreuzberg/tests/batch_orchestration.rs +1 -0
  253. data/vendor/kreuzberg/tests/concurrency_stress.rs +7 -0
  254. data/vendor/kreuzberg/tests/core_integration.rs +1 -0
  255. data/vendor/kreuzberg/tests/docx_metadata_extraction_test.rs +130 -0
  256. data/vendor/kreuzberg/tests/epub_native_extractor_tests.rs +5 -14
  257. data/vendor/kreuzberg/tests/format_integration.rs +2 -0
  258. data/vendor/kreuzberg/tests/helpers/mod.rs +1 -0
  259. data/vendor/kreuzberg/tests/html_table_test.rs +11 -11
  260. data/vendor/kreuzberg/tests/ocr_configuration.rs +16 -0
  261. data/vendor/kreuzberg/tests/ocr_errors.rs +18 -0
  262. data/vendor/kreuzberg/tests/ocr_quality.rs +9 -0
  263. data/vendor/kreuzberg/tests/ocr_stress.rs +1 -0
  264. data/vendor/kreuzberg/tests/pipeline_integration.rs +50 -0
  265. data/vendor/kreuzberg/tests/plugin_ocr_backend_test.rs +13 -0
  266. data/vendor/kreuzberg/tests/plugin_system.rs +12 -0
  267. data/vendor/kreuzberg/tests/registry_integration_tests.rs +2 -0
  268. data/vendor/kreuzberg-ffi/Cargo.toml +2 -1
  269. data/vendor/kreuzberg-ffi/benches/result_view_benchmark.rs +2 -0
  270. data/vendor/kreuzberg-ffi/kreuzberg.h +347 -178
  271. data/vendor/kreuzberg-ffi/src/config/html.rs +318 -0
  272. data/vendor/kreuzberg-ffi/src/config/loader.rs +154 -0
  273. data/vendor/kreuzberg-ffi/src/config/merge.rs +104 -0
  274. data/vendor/kreuzberg-ffi/src/config/mod.rs +385 -0
  275. data/vendor/kreuzberg-ffi/src/config/parse.rs +91 -0
  276. data/vendor/kreuzberg-ffi/src/config/serialize.rs +118 -0
  277. data/vendor/kreuzberg-ffi/src/config_builder.rs +598 -0
  278. data/vendor/kreuzberg-ffi/src/error.rs +46 -14
  279. data/vendor/kreuzberg-ffi/src/helpers.rs +10 -0
  280. data/vendor/kreuzberg-ffi/src/html_options.rs +421 -0
  281. data/vendor/kreuzberg-ffi/src/lib.rs +16 -0
  282. data/vendor/kreuzberg-ffi/src/panic_shield.rs +11 -0
  283. data/vendor/kreuzberg-ffi/src/plugins/ocr_backend.rs +2 -0
  284. data/vendor/kreuzberg-ffi/src/result.rs +148 -122
  285. data/vendor/kreuzberg-ffi/src/result_view.rs +4 -0
  286. data/vendor/kreuzberg-tesseract/Cargo.toml +2 -2
  287. metadata +200 -28
  288. data/vendor/kreuzberg/src/api/server.rs +0 -518
  289. data/vendor/kreuzberg/src/core/config.rs +0 -1914
  290. data/vendor/kreuzberg/src/core/config_validation.rs +0 -949
  291. data/vendor/kreuzberg/src/core/extractor.rs +0 -1200
  292. data/vendor/kreuzberg/src/core/pipeline.rs +0 -1223
  293. data/vendor/kreuzberg/src/core/server_config.rs +0 -1220
  294. data/vendor/kreuzberg/src/extraction/html.rs +0 -1830
  295. data/vendor/kreuzberg/src/extraction/pptx.rs +0 -3102
  296. data/vendor/kreuzberg/src/extractors/epub.rs +0 -696
  297. data/vendor/kreuzberg/src/extractors/latex.rs +0 -653
  298. data/vendor/kreuzberg/src/extractors/opml.rs +0 -635
  299. data/vendor/kreuzberg/src/extractors/rtf.rs +0 -809
  300. data/vendor/kreuzberg/src/ocr/processor.rs +0 -858
  301. data/vendor/kreuzberg/src/plugins/extractor.rs +0 -1042
  302. data/vendor/kreuzberg/src/plugins/processor.rs +0 -650
  303. data/vendor/kreuzberg/src/plugins/registry.rs +0 -1339
  304. data/vendor/kreuzberg/src/plugins/validator.rs +0 -967
  305. data/vendor/kreuzberg/src/text/token_reduction/core.rs +0 -832
  306. data/vendor/kreuzberg/src/types.rs +0 -1713
  307. data/vendor/kreuzberg/src/utils/string_pool.rs +0 -762
  308. data/vendor/kreuzberg-ffi/src/config.rs +0 -1341
@@ -41,8 +41,11 @@ pub mod mime;
41
41
  pub mod pipeline;
42
42
  pub mod server_config;
43
43
 
44
+ #[cfg(feature = "pdf")]
45
+ pub use config::HierarchyConfig;
44
46
  pub use config::{
45
- ChunkingConfig, ExtractionConfig, ImageExtractionConfig, LanguageDetectionConfig, OcrConfig, TokenReductionConfig,
47
+ ChunkingConfig, EmbeddingConfig, EmbeddingModelType, ExtractionConfig, ImageExtractionConfig,
48
+ LanguageDetectionConfig, OcrConfig, OutputFormat, PageConfig, PostProcessorConfig, TokenReductionConfig,
46
49
  };
47
50
  pub use config_validation::{
48
51
  validate_binarization_method, validate_chunking_params, validate_confidence, validate_dpi, validate_language_code,
@@ -0,0 +1,60 @@
1
+ //! Processor caching to reduce lock contention.
2
+ //!
3
+ //! This module manages the caching of post-processors by processing stage,
4
+ //! eliminating repeated registry lock acquisitions.
5
+
6
+ use crate::Result;
7
+ use crate::plugins::{PostProcessor, ProcessingStage};
8
+ use once_cell::sync::Lazy;
9
+ use std::sync::Arc;
10
+ use std::sync::RwLock as StdRwLock;
11
+
12
+ /// Cached post-processors for each stage to reduce lock contention.
13
+ ///
14
+ /// This cache is populated once during the first pipeline run and reused
15
+ /// for all subsequent extractions, eliminating 3 of 4 registry lock acquisitions
16
+ /// per extraction.
17
+ pub(super) struct ProcessorCache {
18
+ pub(super) early: Arc<Vec<Arc<dyn PostProcessor>>>,
19
+ pub(super) middle: Arc<Vec<Arc<dyn PostProcessor>>>,
20
+ pub(super) late: Arc<Vec<Arc<dyn PostProcessor>>>,
21
+ }
22
+
23
+ impl ProcessorCache {
24
+ /// Create a new processor cache by fetching from the registry.
25
+ pub(super) fn new() -> Result<Self> {
26
+ let processor_registry = crate::plugins::registry::get_post_processor_registry();
27
+ let registry = processor_registry
28
+ .read()
29
+ .map_err(|e| crate::KreuzbergError::Other(format!("Post-processor registry lock poisoned: {}", e)))?;
30
+
31
+ Ok(Self {
32
+ early: Arc::new(registry.get_for_stage(ProcessingStage::Early)),
33
+ middle: Arc::new(registry.get_for_stage(ProcessingStage::Middle)),
34
+ late: Arc::new(registry.get_for_stage(ProcessingStage::Late)),
35
+ })
36
+ }
37
+
38
+ /// Get processors for a specific stage from cache.
39
+ #[allow(dead_code)]
40
+ pub(super) fn get_for_stage(&self, stage: ProcessingStage) -> Arc<Vec<Arc<dyn PostProcessor>>> {
41
+ match stage {
42
+ ProcessingStage::Early => Arc::clone(&self.early),
43
+ ProcessingStage::Middle => Arc::clone(&self.middle),
44
+ ProcessingStage::Late => Arc::clone(&self.late),
45
+ }
46
+ }
47
+ }
48
+
49
+ /// Lazy processor cache - initialized on first use, then cached.
50
+ pub(super) static PROCESSOR_CACHE: Lazy<StdRwLock<Option<ProcessorCache>>> = Lazy::new(|| StdRwLock::new(None));
51
+
52
+ /// Clear the processor cache (primarily for testing when registry changes).
53
+ #[allow(dead_code)]
54
+ pub fn clear_processor_cache() -> Result<()> {
55
+ let mut cache = PROCESSOR_CACHE
56
+ .write()
57
+ .map_err(|e| crate::KreuzbergError::Other(format!("Processor cache lock poisoned: {}", e)))?;
58
+ *cache = None;
59
+ Ok(())
60
+ }
@@ -0,0 +1,89 @@
1
+ //! Core processor execution logic.
2
+ //!
3
+ //! This module handles the execution of post-processors and validators
4
+ //! in the correct order.
5
+
6
+ use crate::core::config::ExtractionConfig;
7
+ use crate::plugins::ProcessingStage;
8
+ use crate::types::ExtractionResult;
9
+ use crate::{KreuzbergError, Result};
10
+
11
+ /// Execute all registered post-processors by stage.
12
+ pub(super) async fn execute_processors(
13
+ result: &mut ExtractionResult,
14
+ config: &ExtractionConfig,
15
+ pp_config: &Option<&crate::core::config::PostProcessorConfig>,
16
+ early_processors: std::sync::Arc<Vec<std::sync::Arc<dyn crate::plugins::PostProcessor>>>,
17
+ middle_processors: std::sync::Arc<Vec<std::sync::Arc<dyn crate::plugins::PostProcessor>>>,
18
+ late_processors: std::sync::Arc<Vec<std::sync::Arc<dyn crate::plugins::PostProcessor>>>,
19
+ ) -> Result<()> {
20
+ for (_stage, processors_arc) in [
21
+ (ProcessingStage::Early, early_processors),
22
+ (ProcessingStage::Middle, middle_processors),
23
+ (ProcessingStage::Late, late_processors),
24
+ ] {
25
+ for processor in processors_arc.iter() {
26
+ let processor_name = processor.name();
27
+
28
+ let should_run = should_processor_run(pp_config, processor_name);
29
+
30
+ if should_run && processor.should_process(result, config) {
31
+ match processor.process(result, config).await {
32
+ Ok(_) => {}
33
+ Err(err @ KreuzbergError::Io(_))
34
+ | Err(err @ KreuzbergError::LockPoisoned(_))
35
+ | Err(err @ KreuzbergError::Plugin { .. }) => {
36
+ return Err(err);
37
+ }
38
+ Err(err) => {
39
+ result.metadata.additional.insert(
40
+ format!("processing_error_{processor_name}"),
41
+ serde_json::Value::String(err.to_string()),
42
+ );
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ Ok(())
49
+ }
50
+
51
+ /// Determine if a processor should run based on configuration.
52
+ fn should_processor_run(pp_config: &Option<&crate::core::config::PostProcessorConfig>, processor_name: &str) -> bool {
53
+ if let Some(config) = pp_config {
54
+ if let Some(ref enabled_set) = config.enabled_set {
55
+ enabled_set.contains(processor_name)
56
+ } else if let Some(ref disabled_set) = config.disabled_set {
57
+ !disabled_set.contains(processor_name)
58
+ } else if let Some(ref enabled) = config.enabled_processors {
59
+ enabled.iter().any(|name| name == processor_name)
60
+ } else if let Some(ref disabled) = config.disabled_processors {
61
+ !disabled.iter().any(|name| name == processor_name)
62
+ } else {
63
+ true
64
+ }
65
+ } else {
66
+ true
67
+ }
68
+ }
69
+
70
+ /// Execute all registered validators.
71
+ pub(super) async fn execute_validators(result: &ExtractionResult, config: &ExtractionConfig) -> Result<()> {
72
+ let validator_registry = crate::plugins::registry::get_validator_registry();
73
+ let validators = {
74
+ let registry = validator_registry
75
+ .read()
76
+ .map_err(|e| crate::KreuzbergError::Other(format!("Validator registry lock poisoned: {}", e)))?;
77
+ registry.get_all()
78
+ };
79
+
80
+ if !validators.is_empty() {
81
+ for validator in validators {
82
+ if validator.should_validate(result, config) {
83
+ validator.validate(result, config).await?;
84
+ }
85
+ }
86
+ }
87
+
88
+ Ok(())
89
+ }
@@ -0,0 +1,108 @@
1
+ //! Feature processing logic.
2
+ //!
3
+ //! This module handles feature-specific processing like chunking,
4
+ //! embedding generation, and language detection.
5
+
6
+ use crate::Result;
7
+ use crate::core::config::ExtractionConfig;
8
+ use crate::types::ExtractionResult;
9
+
10
+ /// Execute chunking if configured.
11
+ pub(super) fn execute_chunking(result: &mut ExtractionResult, config: &ExtractionConfig) -> Result<()> {
12
+ #[cfg(feature = "chunking")]
13
+ if let Some(ref chunking_config) = config.chunking {
14
+ let chunk_config = crate::chunking::ChunkingConfig {
15
+ max_characters: chunking_config.max_chars,
16
+ overlap: chunking_config.max_overlap,
17
+ trim: true,
18
+ chunker_type: crate::chunking::ChunkerType::Text,
19
+ };
20
+
21
+ let page_boundaries = result.metadata.pages.as_ref().and_then(|ps| ps.boundaries.as_deref());
22
+
23
+ match crate::chunking::chunk_text(&result.content, &chunk_config, page_boundaries) {
24
+ Ok(chunking_result) => {
25
+ result.chunks = Some(chunking_result.chunks);
26
+
27
+ if let Some(ref chunks) = result.chunks {
28
+ result.metadata.additional.insert(
29
+ "chunk_count".to_string(),
30
+ serde_json::Value::Number(serde_json::Number::from(chunks.len())),
31
+ );
32
+ }
33
+
34
+ #[cfg(feature = "embeddings")]
35
+ if let Some(ref embedding_config) = chunking_config.embedding
36
+ && let Some(ref mut chunks) = result.chunks
37
+ {
38
+ match crate::embeddings::generate_embeddings_for_chunks(chunks, embedding_config) {
39
+ Ok(()) => {
40
+ result
41
+ .metadata
42
+ .additional
43
+ .insert("embeddings_generated".to_string(), serde_json::Value::Bool(true));
44
+ }
45
+ Err(e) => {
46
+ result
47
+ .metadata
48
+ .additional
49
+ .insert("embedding_error".to_string(), serde_json::Value::String(e.to_string()));
50
+ }
51
+ }
52
+ }
53
+
54
+ #[cfg(not(feature = "embeddings"))]
55
+ if chunking_config.embedding.is_some() {
56
+ result.metadata.additional.insert(
57
+ "embedding_error".to_string(),
58
+ serde_json::Value::String("Embeddings feature not enabled".to_string()),
59
+ );
60
+ }
61
+ }
62
+ Err(e) => {
63
+ result
64
+ .metadata
65
+ .additional
66
+ .insert("chunking_error".to_string(), serde_json::Value::String(e.to_string()));
67
+ }
68
+ }
69
+ }
70
+
71
+ #[cfg(not(feature = "chunking"))]
72
+ if config.chunking.is_some() {
73
+ result.metadata.additional.insert(
74
+ "chunking_error".to_string(),
75
+ serde_json::Value::String("Chunking feature not enabled".to_string()),
76
+ );
77
+ }
78
+
79
+ Ok(())
80
+ }
81
+
82
+ /// Execute language detection if configured.
83
+ pub(super) fn execute_language_detection(result: &mut ExtractionResult, config: &ExtractionConfig) -> Result<()> {
84
+ #[cfg(feature = "language-detection")]
85
+ if let Some(ref lang_config) = config.language_detection {
86
+ match crate::language_detection::detect_languages(&result.content, lang_config) {
87
+ Ok(detected) => {
88
+ result.detected_languages = detected;
89
+ }
90
+ Err(e) => {
91
+ result.metadata.additional.insert(
92
+ "language_detection_error".to_string(),
93
+ serde_json::Value::String(e.to_string()),
94
+ );
95
+ }
96
+ }
97
+ }
98
+
99
+ #[cfg(not(feature = "language-detection"))]
100
+ if config.language_detection.is_some() {
101
+ result.metadata.additional.insert(
102
+ "language_detection_error".to_string(),
103
+ serde_json::Value::String("Language detection feature not enabled".to_string()),
104
+ );
105
+ }
106
+
107
+ Ok(())
108
+ }
@@ -0,0 +1,392 @@
1
+ //! Output format conversion for extraction results.
2
+ //!
3
+ //! This module handles conversion of extraction results to various output formats
4
+ //! (Plain, Djot, Markdown, HTML) with proper error handling and metadata recording.
5
+
6
+ use crate::core::config::OutputFormat;
7
+ use crate::types::ExtractionResult;
8
+
9
+ /// Apply output format conversion to the extraction result.
10
+ ///
11
+ /// This function converts the result's content field based on the configured output format:
12
+ /// - `Plain`: No conversion (default)
13
+ /// - `Djot`: Use djot_content if available, otherwise keep plain text
14
+ /// - `Markdown`: Convert to Markdown format (uses djot as it's similar)
15
+ /// - `Html`: Convert to HTML format
16
+ ///
17
+ /// Skips conversion if content was already formatted during extraction (e.g., HTML extractor
18
+ /// already produced djot or markdown output).
19
+ ///
20
+ /// # Arguments
21
+ ///
22
+ /// * `result` - The extraction result to modify
23
+ /// * `output_format` - The desired output format
24
+ pub fn apply_output_format(result: &mut ExtractionResult, output_format: OutputFormat) {
25
+ // Check if content was already formatted during extraction
26
+ let already_formatted = match result.mime_type.as_str() {
27
+ "text/markdown" if output_format == OutputFormat::Markdown => true,
28
+ "text/djot" if output_format == OutputFormat::Djot => true,
29
+ _ => false,
30
+ };
31
+
32
+ if already_formatted {
33
+ return; // Skip re-conversion
34
+ }
35
+
36
+ match output_format {
37
+ OutputFormat::Plain => {
38
+ // Default - no conversion needed
39
+ }
40
+ OutputFormat::Djot => {
41
+ // Convert the extraction result to djot markup
42
+ match crate::extractors::djot_format::extraction_result_to_djot(result) {
43
+ Ok(djot_markup) => {
44
+ result.content = djot_markup;
45
+ }
46
+ Err(e) => {
47
+ // Keep original content on error, record error in metadata
48
+ result.metadata.additional.insert(
49
+ "output_format_error".to_string(),
50
+ serde_json::Value::String(format!("Failed to convert to djot: {}", e)),
51
+ );
52
+ }
53
+ }
54
+ }
55
+ OutputFormat::Markdown => {
56
+ // Djot is syntactically similar to Markdown, so we use djot output as a
57
+ // reasonable approximation. Full Markdown conversion would require a
58
+ // dedicated converter that handles the syntactic differences (e.g.,
59
+ // emphasis markers are swapped: djot uses _ for emphasis and * for strong,
60
+ // while CommonMark uses * for emphasis and ** for strong).
61
+ if result.djot_content.is_some() {
62
+ match crate::extractors::djot_format::extraction_result_to_djot(result) {
63
+ Ok(djot_markup) => {
64
+ result.content = djot_markup;
65
+ }
66
+ Err(e) => {
67
+ // Keep original content on error, record error in metadata
68
+ result.metadata.additional.insert(
69
+ "output_format_error".to_string(),
70
+ serde_json::Value::String(format!("Failed to convert to markdown: {}", e)),
71
+ );
72
+ }
73
+ }
74
+ }
75
+ // For non-djot documents, content remains as-is
76
+ }
77
+ OutputFormat::Html => {
78
+ // Convert to HTML format
79
+ if result.djot_content.is_some() {
80
+ // First generate djot markup, then convert to HTML
81
+ match crate::extractors::djot_format::extraction_result_to_djot(result) {
82
+ Ok(djot_markup) => {
83
+ match crate::extractors::djot_format::djot_to_html(&djot_markup) {
84
+ Ok(html) => {
85
+ result.content = html;
86
+ }
87
+ Err(e) => {
88
+ // Keep original content on error, record error in metadata
89
+ result.metadata.additional.insert(
90
+ "output_format_error".to_string(),
91
+ serde_json::Value::String(format!("Failed to convert djot to HTML: {}", e)),
92
+ );
93
+ }
94
+ }
95
+ }
96
+ Err(e) => {
97
+ // Keep original content on error, record error in metadata
98
+ result.metadata.additional.insert(
99
+ "output_format_error".to_string(),
100
+ serde_json::Value::String(format!("Failed to generate djot for HTML conversion: {}", e)),
101
+ );
102
+ }
103
+ }
104
+ } else {
105
+ // For non-djot documents, wrap plain text in basic HTML
106
+ let escaped_content = html_escape(&result.content);
107
+ result.content = format!("<pre>{}</pre>", escaped_content);
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ /// Escape HTML special characters in a string.
114
+ fn html_escape(s: &str) -> String {
115
+ s.replace('&', "&amp;")
116
+ .replace('<', "&lt;")
117
+ .replace('>', "&gt;")
118
+ .replace('"', "&quot;")
119
+ .replace('\'', "&#39;")
120
+ }
121
+
122
+ #[cfg(test)]
123
+ mod tests {
124
+ use super::*;
125
+ use crate::types::Metadata;
126
+
127
+ #[test]
128
+ fn test_apply_output_format_plain() {
129
+ let mut result = ExtractionResult {
130
+ content: "Hello World".to_string(),
131
+ mime_type: "text/plain".to_string(),
132
+ metadata: Metadata::default(),
133
+ tables: vec![],
134
+ detected_languages: None,
135
+ chunks: None,
136
+ images: None,
137
+ pages: None,
138
+ djot_content: None,
139
+ elements: None,
140
+ };
141
+
142
+ apply_output_format(&mut result, OutputFormat::Plain);
143
+
144
+ // Plain format should not modify content
145
+ assert_eq!(result.content, "Hello World");
146
+ }
147
+
148
+ #[test]
149
+ fn test_apply_output_format_djot_with_djot_content() {
150
+ use crate::types::{BlockType, DjotContent, FormattedBlock, InlineElement, InlineType};
151
+
152
+ let mut result = ExtractionResult {
153
+ content: "Hello World".to_string(),
154
+ mime_type: "text/djot".to_string(),
155
+ metadata: Metadata::default(),
156
+ tables: vec![],
157
+ detected_languages: None,
158
+ chunks: None,
159
+ images: None,
160
+ pages: None,
161
+ elements: None,
162
+ djot_content: Some(DjotContent {
163
+ plain_text: "Hello World".to_string(),
164
+ blocks: vec![FormattedBlock {
165
+ block_type: BlockType::Heading,
166
+ level: Some(1),
167
+ inline_content: vec![InlineElement {
168
+ element_type: InlineType::Text,
169
+ content: "Hello World".to_string(),
170
+ attributes: None,
171
+ metadata: None,
172
+ }],
173
+ attributes: None,
174
+ language: None,
175
+ code: None,
176
+ children: vec![],
177
+ }],
178
+ metadata: Metadata::default(),
179
+ tables: vec![],
180
+ images: vec![],
181
+ links: vec![],
182
+ footnotes: vec![],
183
+ attributes: std::collections::HashMap::new(),
184
+ }),
185
+ };
186
+
187
+ apply_output_format(&mut result, OutputFormat::Djot);
188
+
189
+ // The content should still be present (the function preserves content)
190
+ assert!(!result.content.is_empty());
191
+ }
192
+
193
+ #[test]
194
+ fn test_apply_output_format_djot_without_djot_content() {
195
+ let mut result = ExtractionResult {
196
+ content: "Hello World".to_string(),
197
+ mime_type: "text/plain".to_string(),
198
+ metadata: Metadata::default(),
199
+ tables: vec![],
200
+ detected_languages: None,
201
+ chunks: None,
202
+ images: None,
203
+ pages: None,
204
+ djot_content: None,
205
+ elements: None,
206
+ };
207
+
208
+ apply_output_format(&mut result, OutputFormat::Djot);
209
+
210
+ // Without djot_content, content is converted to djot paragraphs
211
+ // extraction_result_to_djot creates paragraphs from plain text
212
+ assert!(result.content.contains("Hello World"));
213
+ }
214
+
215
+ #[test]
216
+ fn test_apply_output_format_html() {
217
+ let mut result = ExtractionResult {
218
+ content: "Hello World".to_string(),
219
+ mime_type: "text/plain".to_string(),
220
+ metadata: Metadata::default(),
221
+ tables: vec![],
222
+ detected_languages: None,
223
+ chunks: None,
224
+ images: None,
225
+ pages: None,
226
+ djot_content: None,
227
+ elements: None,
228
+ };
229
+
230
+ apply_output_format(&mut result, OutputFormat::Html);
231
+
232
+ // For non-djot documents, HTML wraps content in <pre> tags
233
+ assert!(result.content.contains("<pre>"));
234
+ assert!(result.content.contains("Hello World"));
235
+ assert!(result.content.contains("</pre>"));
236
+ }
237
+
238
+ #[test]
239
+ fn test_apply_output_format_html_escapes_special_chars() {
240
+ let mut result = ExtractionResult {
241
+ content: "<script>alert('XSS')</script>".to_string(),
242
+ mime_type: "text/plain".to_string(),
243
+ metadata: Metadata::default(),
244
+ tables: vec![],
245
+ detected_languages: None,
246
+ chunks: None,
247
+ images: None,
248
+ pages: None,
249
+ djot_content: None,
250
+ elements: None,
251
+ };
252
+
253
+ apply_output_format(&mut result, OutputFormat::Html);
254
+
255
+ // HTML special characters should be escaped
256
+ assert!(result.content.contains("&lt;"));
257
+ assert!(result.content.contains("&gt;"));
258
+ assert!(!result.content.contains("<script>"));
259
+ }
260
+
261
+ #[test]
262
+ fn test_apply_output_format_markdown() {
263
+ let mut result = ExtractionResult {
264
+ content: "Hello World".to_string(),
265
+ mime_type: "text/plain".to_string(),
266
+ metadata: Metadata::default(),
267
+ tables: vec![],
268
+ detected_languages: None,
269
+ chunks: None,
270
+ images: None,
271
+ pages: None,
272
+ djot_content: None,
273
+ elements: None,
274
+ };
275
+
276
+ apply_output_format(&mut result, OutputFormat::Markdown);
277
+
278
+ // For non-djot documents without djot_content, markdown keeps content as-is
279
+ assert_eq!(result.content, "Hello World");
280
+ }
281
+
282
+ #[test]
283
+ fn test_apply_output_format_preserves_metadata() {
284
+ let mut additional = std::collections::HashMap::new();
285
+ additional.insert("custom_key".to_string(), serde_json::json!("custom_value"));
286
+ let metadata = Metadata {
287
+ title: Some("Test Title".to_string()),
288
+ additional,
289
+ ..Default::default()
290
+ };
291
+
292
+ let mut result = ExtractionResult {
293
+ content: "Hello World".to_string(),
294
+ mime_type: "text/plain".to_string(),
295
+ metadata,
296
+ tables: vec![],
297
+ detected_languages: None,
298
+ chunks: None,
299
+ images: None,
300
+ pages: None,
301
+ djot_content: None,
302
+ elements: None,
303
+ };
304
+
305
+ apply_output_format(&mut result, OutputFormat::Djot);
306
+
307
+ // Metadata should be preserved
308
+ assert_eq!(result.metadata.title, Some("Test Title".to_string()));
309
+ assert_eq!(
310
+ result.metadata.additional.get("custom_key"),
311
+ Some(&serde_json::json!("custom_value"))
312
+ );
313
+ }
314
+
315
+ #[test]
316
+ fn test_apply_output_format_preserves_tables() {
317
+ use crate::types::Table;
318
+
319
+ let table = Table {
320
+ cells: vec![vec!["A".to_string(), "B".to_string()]],
321
+ markdown: "| A | B |".to_string(),
322
+ page_number: 1,
323
+ };
324
+
325
+ let mut result = ExtractionResult {
326
+ content: "Hello World".to_string(),
327
+ mime_type: "text/plain".to_string(),
328
+ metadata: Metadata::default(),
329
+ tables: vec![table],
330
+ detected_languages: None,
331
+ chunks: None,
332
+ images: None,
333
+ pages: None,
334
+ djot_content: None,
335
+ elements: None,
336
+ };
337
+
338
+ apply_output_format(&mut result, OutputFormat::Html);
339
+
340
+ // Tables should be preserved
341
+ assert_eq!(result.tables.len(), 1);
342
+ assert_eq!(result.tables[0].cells[0][0], "A");
343
+ }
344
+
345
+ #[test]
346
+ fn test_apply_output_format_preserves_djot_content() {
347
+ use crate::types::{BlockType, DjotContent, FormattedBlock, InlineElement, InlineType};
348
+
349
+ let djot_content = DjotContent {
350
+ plain_text: "test".to_string(),
351
+ blocks: vec![FormattedBlock {
352
+ block_type: BlockType::Paragraph,
353
+ level: None,
354
+ inline_content: vec![InlineElement {
355
+ element_type: InlineType::Text,
356
+ content: "test".to_string(),
357
+ attributes: None,
358
+ metadata: None,
359
+ }],
360
+ attributes: None,
361
+ language: None,
362
+ code: None,
363
+ children: vec![],
364
+ }],
365
+ metadata: Metadata::default(),
366
+ tables: vec![],
367
+ images: vec![],
368
+ links: vec![],
369
+ footnotes: vec![],
370
+ attributes: std::collections::HashMap::new(),
371
+ };
372
+
373
+ let mut result = ExtractionResult {
374
+ content: "test".to_string(),
375
+ mime_type: "text/djot".to_string(),
376
+ metadata: Metadata::default(),
377
+ tables: vec![],
378
+ detected_languages: None,
379
+ chunks: None,
380
+ images: None,
381
+ pages: None,
382
+ elements: None,
383
+ djot_content: Some(djot_content),
384
+ };
385
+
386
+ apply_output_format(&mut result, OutputFormat::Djot);
387
+
388
+ // djot_content should still be present after format application
389
+ assert!(result.djot_content.is_some());
390
+ assert_eq!(result.djot_content.as_ref().unwrap().blocks.len(), 1);
391
+ }
392
+ }