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
@@ -0,0 +1,659 @@
1
+ //! HTML processing pipeline with optional image extraction.
2
+ //!
3
+ //! This module provides the main processing functions that tie together
4
+ //! HTML conversion, image extraction, and metadata handling.
5
+
6
+ use super::converter::{convert_html_to_markdown, resolve_conversion_options};
7
+ use super::image_handling::inline_image_to_extracted;
8
+ use super::stack_management::check_wasm_size_limit;
9
+ #[cfg(not(target_arch = "wasm32"))]
10
+ use super::stack_management::{html_requires_large_stack, run_on_dedicated_stack};
11
+ use super::types::HtmlExtractionResult;
12
+ use crate::core::config::OutputFormat as KreuzbergOutputFormat;
13
+ use crate::error::{KreuzbergError, Result};
14
+ use html_to_markdown_rs::{ConversionOptions, InlineImageConfig as LibInlineImageConfig, convert_with_inline_images};
15
+
16
+ /// Convert HTML with inline image extraction.
17
+ ///
18
+ /// Internal helper that performs the actual image extraction.
19
+ fn convert_inline_images_with_options(
20
+ html: &str,
21
+ options: ConversionOptions,
22
+ image_config: LibInlineImageConfig,
23
+ ) -> Result<html_to_markdown_rs::HtmlExtraction> {
24
+ convert_with_inline_images(html, Some(options), image_config, None)
25
+ .map_err(|e| KreuzbergError::parsing(format!("Failed to convert HTML to Markdown with images: {}", e)))
26
+ }
27
+
28
+ /// Convert HTML with inline images using a dedicated stack.
29
+ ///
30
+ /// On native platforms, uses a dedicated thread with larger stack size.
31
+ #[cfg(not(target_arch = "wasm32"))]
32
+ fn convert_inline_images_with_large_stack(
33
+ html: String,
34
+ options: ConversionOptions,
35
+ image_config: LibInlineImageConfig,
36
+ ) -> Result<html_to_markdown_rs::HtmlExtraction> {
37
+ run_on_dedicated_stack(move || convert_inline_images_with_options(&html, options, image_config))
38
+ }
39
+
40
+ /// Process HTML with optional image extraction and output format support.
41
+ ///
42
+ /// This is the main entry point for HTML processing. It handles:
43
+ /// - Size limit validation (WASM builds)
44
+ /// - Stack management for large documents (native builds)
45
+ /// - Image extraction if requested
46
+ /// - Warning collection
47
+ /// - Output format selection (markdown or djot)
48
+ ///
49
+ /// # WASM Limitations
50
+ ///
51
+ /// In WASM builds, HTML files larger than 2MB will be rejected to prevent stack overflow.
52
+ ///
53
+ /// # Arguments
54
+ ///
55
+ /// * `html` - The HTML string to process
56
+ /// * `options` - Optional conversion options
57
+ /// * `extract_images` - Whether to extract inline images
58
+ /// * `max_image_size` - Maximum size in bytes for extracted images
59
+ /// * `output_format` - Desired output format (markdown or djot)
60
+ ///
61
+ /// # Returns
62
+ ///
63
+ /// An HtmlExtractionResult containing the markdown/djot content, extracted images, and any warnings
64
+ pub fn process_html(
65
+ html: &str,
66
+ options: Option<ConversionOptions>,
67
+ extract_images: bool,
68
+ max_image_size: u64,
69
+ output_format: KreuzbergOutputFormat,
70
+ ) -> Result<HtmlExtractionResult> {
71
+ check_wasm_size_limit(html)?;
72
+
73
+ if extract_images {
74
+ let options = resolve_conversion_options(options.clone(), output_format);
75
+ let mut img_config = LibInlineImageConfig::new(max_image_size);
76
+ img_config.filename_prefix = Some("inline-image".to_string());
77
+
78
+ #[cfg(not(target_arch = "wasm32"))]
79
+ let extraction = if html_requires_large_stack(html.len()) {
80
+ convert_inline_images_with_large_stack(html.to_string(), options, img_config)?
81
+ } else {
82
+ convert_inline_images_with_options(html, options, img_config)?
83
+ };
84
+
85
+ #[cfg(target_arch = "wasm32")]
86
+ let extraction = convert_inline_images_with_options(html, options, img_config)?;
87
+
88
+ let images = extraction
89
+ .inline_images
90
+ .into_iter()
91
+ .map(inline_image_to_extracted)
92
+ .collect();
93
+
94
+ let warnings = extraction.warnings.into_iter().map(|w| w.message).collect();
95
+
96
+ Ok(HtmlExtractionResult {
97
+ markdown: extraction.markdown,
98
+ images,
99
+ warnings,
100
+ })
101
+ } else {
102
+ let content = convert_html_to_markdown(html, options, Some(output_format))?;
103
+
104
+ Ok(HtmlExtractionResult {
105
+ markdown: content,
106
+ images: Vec::new(),
107
+ warnings: Vec::new(),
108
+ })
109
+ }
110
+ }
111
+
112
+ #[cfg(test)]
113
+ mod tests {
114
+ use super::*;
115
+ use crate::types::{ImageType, LinkType, StructuredDataType, TextDirection};
116
+
117
+ #[test]
118
+ fn test_process_html_without_images() {
119
+ let html = "<h1>Test</h1><p>Content</p>";
120
+ let result = process_html(html, None, false, 1024 * 1024, KreuzbergOutputFormat::Markdown).unwrap();
121
+ assert!(result.markdown.contains("# Test"));
122
+ assert!(result.markdown.contains("Content"));
123
+ assert!(result.images.is_empty());
124
+ assert!(result.warnings.is_empty());
125
+ }
126
+
127
+ #[test]
128
+ fn test_html_with_inline_image() {
129
+ let html = r#"<p>Image: <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" alt="Test"></p>"#;
130
+ let mut options = ConversionOptions::default();
131
+ options.preprocessing.enabled = false;
132
+ let result = process_html(html, Some(options), true, 1024 * 1024, KreuzbergOutputFormat::Markdown).unwrap();
133
+ assert_eq!(result.images.len(), 1);
134
+ assert_eq!(result.images[0].format, "png");
135
+ }
136
+
137
+ #[test]
138
+ fn test_process_html_empty_string() {
139
+ let result = process_html("", None, false, 1024, KreuzbergOutputFormat::Markdown).unwrap();
140
+ assert!(result.markdown.is_empty() || result.markdown.trim().is_empty());
141
+ assert!(result.images.is_empty());
142
+ }
143
+
144
+ /// Test extraction of large HTML document (1MB+) for performance
145
+ /// Generates HTML with 10,000+ elements and validates extraction
146
+ /// completes within reasonable time (<30s) with no panics.
147
+ #[test]
148
+ fn test_large_html_performance() {
149
+ let mut html = String::with_capacity(2_000_000);
150
+ html.push_str(
151
+ r#"<!DOCTYPE html>
152
+ <html>
153
+ <head>
154
+ <title>Large HTML Performance Test</title>
155
+ <meta name="description" content="Testing extraction performance on large documents">
156
+ </head>
157
+ <body>
158
+ <h1>Large Document Test</h1>"#,
159
+ );
160
+
161
+ for i in 0..10000 {
162
+ html.push_str(&format!(
163
+ "<article><h2>Article {}</h2><p>Content block {} with expanded text content to increase document size. \
164
+ This article contains multiple paragraphs describing various topics. \
165
+ The goal is to create sufficient HTML content to test performance on large documents. \
166
+ Here are some additional details: Section A covers fundamentals, Section B covers implementation, \
167
+ and Section C covers optimization. Each section has multiple subsections.</p>\
168
+ <p>Additional content paragraph {} to further expand the document.</p></article>\n",
169
+ i, i, i
170
+ ));
171
+ }
172
+ html.push_str("</body></html>");
173
+
174
+ let html_size_bytes = html.len();
175
+ assert!(
176
+ html_size_bytes > 1_000_000,
177
+ "Generated HTML should be >1MB (got {} bytes)",
178
+ html_size_bytes
179
+ );
180
+
181
+ let start = std::time::Instant::now();
182
+
183
+ let result = process_html(&html, None, false, 1024 * 1024, KreuzbergOutputFormat::Markdown);
184
+
185
+ let duration = start.elapsed();
186
+
187
+ assert!(
188
+ result.is_ok(),
189
+ "Large HTML extraction should succeed. Error: {:?}",
190
+ result.err()
191
+ );
192
+
193
+ let result = result.unwrap();
194
+ assert!(!result.markdown.is_empty(), "Markdown should be generated");
195
+
196
+ assert!(
197
+ duration.as_secs() < 30,
198
+ "Large HTML extraction took too long: {:.2}s (must be <30s)",
199
+ duration.as_secs_f64()
200
+ );
201
+ }
202
+
203
+ /// Test WASM size boundary conditions
204
+ /// Tests HTML exactly at and around the 2MB limit to ensure
205
+ /// proper error handling and boundary detection.
206
+ #[test]
207
+ fn test_wasm_size_limit_boundary() {
208
+ let mut html_under = String::from(
209
+ r#"<!DOCTYPE html>
210
+ <html>
211
+ <head><title>Just Under Limit</title></head>
212
+ <body><h1>Content</h1>"#,
213
+ );
214
+
215
+ let target_size = 1_800_000;
216
+ while html_under.len() < target_size {
217
+ html_under.push_str("<p>Padding content for size testing. This is test data to reach the target document size. Lorem ipsum dolor sit amet.</p>\n");
218
+ }
219
+ html_under.truncate(target_size);
220
+ html_under.push_str("</body></html>");
221
+
222
+ assert!(
223
+ html_under.len() < 2 * 1024 * 1024,
224
+ "HTML should be under 2MB limit (got {} bytes)",
225
+ html_under.len()
226
+ );
227
+
228
+ let result = process_html(&html_under, None, false, 1024, KreuzbergOutputFormat::Markdown);
229
+ #[cfg(target_arch = "wasm32")]
230
+ assert!(result.is_ok(), "HTML under 2MB should be accepted in WASM");
231
+ #[cfg(not(target_arch = "wasm32"))]
232
+ assert!(result.is_ok(), "HTML under 2MB should always be accepted");
233
+
234
+ let mut html_over = String::from(
235
+ r#"<!DOCTYPE html>
236
+ <html>
237
+ <head><title>Over Limit</title></head>
238
+ <body><h1>Content</h1>"#,
239
+ );
240
+
241
+ let target_size = 2_200_000;
242
+ while html_over.len() < target_size {
243
+ html_over.push_str("<p>Oversized content for boundary testing. This section generates large HTML to exceed limits. Lorem ipsum dolor sit amet.</p>\n");
244
+ }
245
+ html_over.truncate(target_size);
246
+ html_over.push_str("</body></html>");
247
+
248
+ assert!(
249
+ html_over.len() > 2 * 1024 * 1024,
250
+ "HTML should be over 2MB limit (got {} bytes)",
251
+ html_over.len()
252
+ );
253
+
254
+ let result = process_html(&html_over, None, false, 1024, KreuzbergOutputFormat::Markdown);
255
+ #[cfg(target_arch = "wasm32")]
256
+ {
257
+ assert!(result.is_err(), "HTML over 2MB should be rejected in WASM with error");
258
+ let error_msg = format!("{:?}", result.err());
259
+ assert!(
260
+ error_msg.contains("2MB") || error_msg.contains("WASM"),
261
+ "Error message should clearly indicate WASM size limit"
262
+ );
263
+ }
264
+ #[cfg(not(target_arch = "wasm32"))]
265
+ {
266
+ if let Err(e) = result {
267
+ let msg = format!("{:?}", e);
268
+ assert!(
269
+ !msg.contains("WASM") && !msg.contains("2MB"),
270
+ "Native builds should not enforce WASM size limit"
271
+ );
272
+ }
273
+ }
274
+ }
275
+
276
+ /// Test thread safety of HTML extraction with concurrent access
277
+ /// Validates that extracting the same HTML from multiple threads
278
+ /// does not cause panics, data races, or corruption.
279
+ #[test]
280
+ fn test_concurrent_html_extraction() {
281
+ use std::sync::Arc;
282
+
283
+ let html = Arc::new(
284
+ r#"<!DOCTYPE html>
285
+ <html lang="en">
286
+ <head>
287
+ <title>Concurrent Test Article</title>
288
+ <meta name="description" content="Testing concurrent extraction">
289
+ <meta name="author" content="Test Author">
290
+ <meta property="og:title" content="OG Title">
291
+ <meta property="og:description" content="OG Description">
292
+ <meta name="twitter:card" content="summary">
293
+ <script type="application/ld+json">
294
+ {
295
+ "@context": "https://schema.org",
296
+ "@type": "Article",
297
+ "headline": "Concurrent Test",
298
+ "author": "Test Author"
299
+ }
300
+ </script>
301
+ </head>
302
+ <body>
303
+ <h1>Concurrent Extraction Test</h1>
304
+ <h2>Section 1</h2>
305
+ <p>Content 1</p>
306
+ <h2>Section 2</h2>
307
+ <p>Content 2</p>
308
+ <a href="https://example.com">External Link</a>
309
+ <a href="/about">Internal Link</a>
310
+ <img src="https://example.com/image.jpg" alt="Test Image">
311
+ </body>
312
+ </html>"#,
313
+ );
314
+
315
+ let handles: Vec<_> = (0..10)
316
+ .map(|thread_id| {
317
+ let html = Arc::clone(&html);
318
+ std::thread::spawn(move || {
319
+ let result =
320
+ super::super::converter::convert_html_to_markdown_with_metadata(html.as_ref(), None, None);
321
+
322
+ assert!(
323
+ result.is_ok(),
324
+ "Thread {} extraction failed: {:?}",
325
+ thread_id,
326
+ result.err()
327
+ );
328
+
329
+ let (markdown, metadata) = result.unwrap();
330
+
331
+ assert!(
332
+ !markdown.is_empty(),
333
+ "Thread {} markdown should not be empty",
334
+ thread_id
335
+ );
336
+
337
+ if let Some(meta) = metadata {
338
+ assert_eq!(
339
+ meta.title,
340
+ Some("Concurrent Test Article".to_string()),
341
+ "Thread {} should extract correct title",
342
+ thread_id
343
+ );
344
+
345
+ assert!(!meta.headers.is_empty(), "Thread {} should extract headers", thread_id);
346
+ assert!(!meta.links.is_empty(), "Thread {} should extract links", thread_id);
347
+ assert!(!meta.images.is_empty(), "Thread {} should extract images", thread_id);
348
+ assert!(
349
+ !meta.open_graph.is_empty(),
350
+ "Thread {} should extract OG metadata",
351
+ thread_id
352
+ );
353
+ }
354
+
355
+ true
356
+ })
357
+ })
358
+ .collect();
359
+
360
+ let all_succeeded = handles.into_iter().enumerate().all(|(i, handle)| {
361
+ let result = handle.join();
362
+ assert!(result.is_ok(), "Thread {} panicked: {:?}", i, result.err());
363
+ result.unwrap()
364
+ });
365
+
366
+ assert!(all_succeeded, "All concurrent extraction threads should succeed");
367
+ }
368
+
369
+ /// Comprehensive test of a complete HTML document with ALL metadata types.
370
+ /// Validates that all metadata extraction works together correctly.
371
+ #[test]
372
+ fn test_metadata_comprehensive() {
373
+ let html = "<html lang=\"en\" dir=\"ltr\"><head>\
374
+ <meta charset=\"UTF-8\">\
375
+ <title>Complete Metadata Example</title>\
376
+ <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
377
+ <meta name=\"description\" content=\"Comprehensive metadata extraction test page\">\
378
+ <meta name=\"keywords\" content=\"metadata, extraction, rust, web\">\
379
+ <meta name=\"author\" content=\"Test Author\">\
380
+ <meta name=\"robots\" content=\"index, follow\">\
381
+ <meta property=\"og:title\" content=\"OG Title\">\
382
+ <meta property=\"og:description\" content=\"OG Description\">\
383
+ <meta property=\"og:image\" content=\"https://example.com/og-image.jpg\">\
384
+ <meta property=\"og:url\" content=\"https://example.com/article\">\
385
+ <meta property=\"og:type\" content=\"article\">\
386
+ <meta property=\"og:site_name\" content=\"Example Site\">\
387
+ <meta name=\"twitter:card\" content=\"summary_large_image\">\
388
+ <meta name=\"twitter:title\" content=\"Tweet Title\">\
389
+ <meta name=\"twitter:description\" content=\"Tweet Description\">\
390
+ <meta name=\"twitter:image\" content=\"https://example.com/tweet.jpg\">\
391
+ <meta name=\"twitter:site\" content=\"@example\">\
392
+ <link rel=\"canonical\" href=\"https://example.com/article/complete\">\
393
+ <base href=\"https://example.com/\">\
394
+ <script type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"Article\",\"headline\":\"Complete Metadata Example\",\"author\":\"Test Author\",\"datePublished\":\"2024-01-01\"}</script>\
395
+ </head><body>\
396
+ <header><h1 id=\"page-title\">Complete Metadata Example</h1><p>Test</p></header>\
397
+ <nav><a href=\"#intro\">Intro</a><a href=\"https://external.com\">External</a></nav>\
398
+ <main>\
399
+ <section id=\"intro\"><h2>Introduction</h2><p>Purpose.</p><img src=\"https://example.com/intro.jpg\" alt=\"Intro image\" title=\"Intro\"></section>\
400
+ <section id=\"content\">\
401
+ <h3>Content</h3><h4>Sub</h4><p>Details.</p>\
402
+ <h3>Gallery</h3>\
403
+ <img src=\"/images/photo1.jpg\" alt=\"Photo 1\" width=\"400\" height=\"300\">\
404
+ <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\" alt=\"Data URI\">\
405
+ <img src=\"./relative/image.gif\" alt=\"Relative\">\
406
+ </section>\
407
+ <section id=\"links\">\
408
+ <h3>Links</h3>\
409
+ <a href=\"#top\">Top</a>\
410
+ <a href=\"/about\" title=\"About\">Internal</a>\
411
+ <a href=\"mailto:contact@example.com\">Email</a>\
412
+ <a href=\"tel:+1-555-1234\">Phone</a>\
413
+ </section>\
414
+ </main>\
415
+ <footer><p>2024 Example</p></footer>\
416
+ </body></html>";
417
+
418
+ let (markdown, metadata) =
419
+ super::super::converter::convert_html_to_markdown_with_metadata(html, None, None).unwrap();
420
+ let metadata = metadata.expect("comprehensive HTML should have metadata");
421
+
422
+ assert_eq!(
423
+ metadata.title,
424
+ Some("Complete Metadata Example".to_string()),
425
+ "Title should be extracted"
426
+ );
427
+ assert_eq!(
428
+ metadata.description,
429
+ Some("Comprehensive metadata extraction test page".to_string()),
430
+ "Description should be extracted"
431
+ );
432
+ assert_eq!(
433
+ metadata.author,
434
+ Some("Test Author".to_string()),
435
+ "Author should be extracted"
436
+ );
437
+ assert!(!metadata.keywords.is_empty(), "Keywords should be extracted");
438
+ assert_eq!(
439
+ metadata.language,
440
+ Some("en".to_string()),
441
+ "Language should be extracted"
442
+ );
443
+ assert_eq!(
444
+ metadata.text_direction,
445
+ Some(TextDirection::LeftToRight),
446
+ "Text direction should be extracted"
447
+ );
448
+ assert_eq!(
449
+ metadata.canonical_url,
450
+ Some("https://example.com/article/complete".to_string()),
451
+ "Canonical URL should be extracted"
452
+ );
453
+ assert_eq!(
454
+ metadata.base_href,
455
+ Some("https://example.com/".to_string()),
456
+ "Base href should be extracted"
457
+ );
458
+
459
+ assert!(!metadata.open_graph.is_empty(), "Open Graph tags should be extracted");
460
+
461
+ assert!(
462
+ !metadata.twitter_card.is_empty(),
463
+ "Twitter Card tags should be extracted"
464
+ );
465
+
466
+ assert!(!metadata.headers.is_empty(), "Headers should be extracted");
467
+ let h1_count = metadata.headers.iter().filter(|h| h.level == 1).count();
468
+ assert_eq!(h1_count, 1, "Should have exactly one H1");
469
+ assert!(metadata.headers.iter().any(|h| h.level == 2), "Should have H2 headers");
470
+ assert!(metadata.headers.iter().any(|h| h.level == 3), "Should have H3 headers");
471
+
472
+ assert!(!metadata.links.is_empty(), "Links should be extracted");
473
+ assert!(
474
+ metadata.links.iter().any(|l| l.link_type == LinkType::Anchor),
475
+ "Anchor links should be present"
476
+ );
477
+ assert!(
478
+ metadata.links.iter().any(|l| l.link_type == LinkType::Email),
479
+ "Email links should be present"
480
+ );
481
+ assert!(
482
+ metadata.links.iter().any(|l| l.link_type == LinkType::Phone),
483
+ "Phone links should be present"
484
+ );
485
+
486
+ assert!(!metadata.images.is_empty(), "Images should be extracted");
487
+ assert!(
488
+ metadata.images.iter().any(|img| img.image_type == ImageType::External),
489
+ "External images should be present"
490
+ );
491
+ assert!(
492
+ metadata.images.iter().any(|img| img.image_type == ImageType::DataUri),
493
+ "Data URI images should be present"
494
+ );
495
+ assert!(
496
+ metadata.images.iter().any(|img| img.image_type == ImageType::Relative),
497
+ "Relative images should be present"
498
+ );
499
+
500
+ let img_with_dims = metadata.images.iter().find(|img| img.dimensions.is_some());
501
+ assert!(img_with_dims.is_some(), "At least one image should have dimensions");
502
+ if let Some(img) = img_with_dims {
503
+ assert_eq!(
504
+ img.dimensions,
505
+ Some((400, 300)),
506
+ "Image dimensions should be correctly extracted"
507
+ );
508
+ }
509
+
510
+ assert!(
511
+ !metadata.structured_data.is_empty(),
512
+ "Structured data should be extracted"
513
+ );
514
+
515
+ assert!(!markdown.is_empty(), "Markdown should be generated");
516
+ assert!(
517
+ markdown.contains("Complete Metadata Example"),
518
+ "Markdown should contain heading text"
519
+ );
520
+ }
521
+
522
+ /// Real-world-like webpage structure with realistic metadata patterns.
523
+ /// Tests extraction from a realistic blog post scenario.
524
+ #[test]
525
+ fn test_metadata_real_world_webpage() {
526
+ let html = "<!DOCTYPE html>\
527
+ <html lang=\"en\"><head>\
528
+ <meta charset=\"UTF-8\">\
529
+ <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\
530
+ <title>How to Build Rust Web Applications | TechBlog</title>\
531
+ <meta name=\"description\" content=\"Learn how to build scalable web applications using Rust\">\
532
+ <meta name=\"keywords\" content=\"rust, web development, actix, async, tutorial\">\
533
+ <meta name=\"author\" content=\"Sarah Chen\">\
534
+ <link rel=\"canonical\" href=\"https://techblog.example.com/rust-web-apps\">\
535
+ <base href=\"https://techblog.example.com/\">\
536
+ <meta property=\"og:title\" content=\"How to Build Rust Web Applications\">\
537
+ <meta property=\"og:description\" content=\"A comprehensive guide to building web apps with Rust\">\
538
+ <meta property=\"og:image\" content=\"https://techblog.example.com/images/rust-web.jpg\">\
539
+ <meta property=\"og:type\" content=\"article\">\
540
+ <meta name=\"twitter:card\" content=\"summary_large_image\">\
541
+ <meta name=\"twitter:title\" content=\"How to Build Rust Web Applications\">\
542
+ <meta name=\"twitter:image\" content=\"https://techblog.example.com/images/rust-web-twitter.jpg\">\
543
+ <meta name=\"twitter:creator\" content=\"@sarahcodes\">\
544
+ <script type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"BlogPosting\",\"headline\":\"How to Build Rust Web Applications\"}</script>\
545
+ </head><body>\
546
+ <header><nav>\
547
+ <a href=\"/\">Home</a><a href=\"/blog\">Blog</a><a href=\"/resources\">Resources</a><a href=\"/about\">About</a>\
548
+ </nav></header>\
549
+ <article>\
550
+ <h1>How to Build Rust Web Applications</h1>\
551
+ <img src=\"https://techblog.example.com/images/rust-web-hero.jpg\" alt=\"Rust web development\" title=\"Hero image\">\
552
+ <p>Guide content here</p>\
553
+ <h2>Getting Started</h2>\
554
+ <p>Before diving in, install Rust.</p>\
555
+ <h3>Installation</h3>\
556
+ <p>Visit <a href=\"https://www.rust-lang.org/tools/install\">installation page</a>.</p>\
557
+ <h3>Your First Project</h3>\
558
+ <p>Create project with cargo</p>\
559
+ <h2>Building</h2>\
560
+ <h3>Dependencies</h3>\
561
+ <p>Setup Cargo.toml</p>\
562
+ <h3>Routes</h3>\
563
+ <p>Learn <a href=\"/blog/rust-routing\">routing</a>.</p>\
564
+ <h2>Advanced</h2>\
565
+ <h3>Async</h3>\
566
+ <p>See <a href=\"https://tokio.rs\" title=\"Tokio async runtime\">Tokio</a>.</p>\
567
+ <h3>Database</h3>\
568
+ <p>Contact <a href=\"mailto:hello@techblog.example.com\">hello@techblog.example.com</a></p>\
569
+ <h2>Gallery</h2>\
570
+ <img src=\"/images/diagram1.png\" alt=\"Architecture diagram\" width=\"600\" height=\"400\">\
571
+ <img src=\"/images/diagram2.png\" alt=\"Flow chart\" width=\"600\" height=\"400\">\
572
+ <h2>Conclusion</h2>\
573
+ <p>Excellent choice. <a href=\"/blog/rust-deployment\">Deployment</a>.</p>\
574
+ <footer><p>Questions? <a href=\"tel:+1-555-0100\">Call</a> or <a href=\"#contact\">contact</a>.</p></footer>\
575
+ </article>\
576
+ </body></html>";
577
+
578
+ let (markdown, metadata) =
579
+ super::super::converter::convert_html_to_markdown_with_metadata(html, None, None).unwrap();
580
+ let metadata = metadata.expect("real-world HTML should have metadata");
581
+
582
+ assert_eq!(
583
+ metadata.title,
584
+ Some("How to Build Rust Web Applications | TechBlog".to_string()),
585
+ "Real-world title with site name should be extracted"
586
+ );
587
+ assert!(metadata.description.is_some(), "Description should be present");
588
+ assert_eq!(
589
+ metadata.author,
590
+ Some("Sarah Chen".to_string()),
591
+ "Author should be extracted"
592
+ );
593
+ assert!(!metadata.keywords.is_empty(), "Keywords should be extracted");
594
+
595
+ assert!(!metadata.open_graph.is_empty(), "Article should have Open Graph tags");
596
+
597
+ assert!(
598
+ !metadata.twitter_card.is_empty(),
599
+ "Article should have Twitter Card tags"
600
+ );
601
+
602
+ assert!(metadata.headers.len() >= 5, "Should extract multiple heading levels");
603
+ assert!(
604
+ metadata.headers.iter().any(|h| h.level == 1),
605
+ "Should have H1 (main title)"
606
+ );
607
+ assert!(
608
+ metadata.headers.iter().any(|h| h.level == 2),
609
+ "Should have H2 (sections)"
610
+ );
611
+ assert!(
612
+ metadata.headers.iter().any(|h| h.level == 3),
613
+ "Should have H3 (subsections)"
614
+ );
615
+
616
+ assert!(metadata.links.len() >= 3, "Should extract multiple links");
617
+ assert!(
618
+ metadata.links.iter().any(|l| l.link_type == LinkType::Internal),
619
+ "Should have internal links"
620
+ );
621
+ assert!(
622
+ metadata.links.iter().any(|l| l.link_type == LinkType::External),
623
+ "Should have external links"
624
+ );
625
+ assert!(
626
+ metadata.links.iter().any(|l| l.link_type == LinkType::Email)
627
+ || metadata.links.iter().any(|l| l.link_type == LinkType::Phone),
628
+ "Should have either email or phone links"
629
+ );
630
+
631
+ assert!(!metadata.images.is_empty(), "Should extract images");
632
+ let hero_image = metadata.images.iter().find(|img| {
633
+ img.alt
634
+ .as_ref()
635
+ .is_some_and(|a| a.contains("Hero") || a.contains("development") || a.contains("hero"))
636
+ });
637
+ if hero_image.is_none() {
638
+ assert!(!metadata.images.is_empty(), "Should have extracted at least one image");
639
+ }
640
+
641
+ assert!(
642
+ !metadata.structured_data.is_empty(),
643
+ "Should extract structured data (JSON-LD)"
644
+ );
645
+ let json_ld = metadata
646
+ .structured_data
647
+ .iter()
648
+ .find(|sd| sd.data_type == StructuredDataType::JsonLd);
649
+ assert!(json_ld.is_some(), "Should have JSON-LD structured data");
650
+ assert_eq!(
651
+ json_ld.unwrap().schema_type,
652
+ Some("BlogPosting".to_string()),
653
+ "JSON-LD should identify as BlogPosting schema"
654
+ );
655
+
656
+ assert!(!markdown.is_empty(), "Should generate Markdown from HTML");
657
+ assert!(markdown.contains("Rust"), "Markdown should contain article content");
658
+ }
659
+ }