docvortex 0.2.1__py3-none-any.whl

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 (364) hide show
  1. docvortex/__init__.py +21 -0
  2. docvortex/analyzers/__init__.py +3 -0
  3. docvortex/analyzers/native/__init__.py +37 -0
  4. docvortex/analyzers/native/_shared/__init__.py +3 -0
  5. docvortex/analyzers/native/_shared/hyperlink.py +16 -0
  6. docvortex/analyzers/native/_shared/image.py +8 -0
  7. docvortex/analyzers/native/_shared/markup/__init__.py +47 -0
  8. docvortex/analyzers/native/_shared/markup/anchors.py +30 -0
  9. docvortex/analyzers/native/_shared/markup/formula.py +37 -0
  10. docvortex/analyzers/native/_shared/markup/projector.py +57 -0
  11. docvortex/analyzers/native/_shared/markup/styles.py +19 -0
  12. docvortex/analyzers/native/_shared/mathml.py +17 -0
  13. docvortex/analyzers/native/_shared/names.py +7 -0
  14. docvortex/analyzers/native/_shared/xycut.py +414 -0
  15. docvortex/analyzers/native/contracts.py +44 -0
  16. docvortex/analyzers/native/csv.py +351 -0
  17. docvortex/analyzers/native/epub/__init__.py +18 -0
  18. docvortex/analyzers/native/epub/constants.py +45 -0
  19. docvortex/analyzers/native/epub/converter.py +80 -0
  20. docvortex/analyzers/native/epub/errors.py +20 -0
  21. docvortex/analyzers/native/epub/metadata.py +31 -0
  22. docvortex/analyzers/native/epub/package.py +649 -0
  23. docvortex/analyzers/native/epub/xhtml.py +306 -0
  24. docvortex/analyzers/native/html/__init__.py +6 -0
  25. docvortex/analyzers/native/html/anchors.py +271 -0
  26. docvortex/analyzers/native/html/constants.py +25 -0
  27. docvortex/analyzers/native/html/contracts.py +7 -0
  28. docvortex/analyzers/native/html/converter.py +117 -0
  29. docvortex/analyzers/native/html/document.py +389 -0
  30. docvortex/analyzers/native/html/errors.py +12 -0
  31. docvortex/analyzers/native/html/resources.py +365 -0
  32. docvortex/analyzers/native/html/selector.py +421 -0
  33. docvortex/analyzers/native/models.py +209 -0
  34. docvortex/analyzers/native/ofd/__init__.py +14 -0
  35. docvortex/analyzers/native/ofd/constants.py +59 -0
  36. docvortex/analyzers/native/ofd/converter.py +31 -0
  37. docvortex/analyzers/native/ofd/errors.py +16 -0
  38. docvortex/analyzers/native/ofd/geometry.py +215 -0
  39. docvortex/analyzers/native/ofd/images.py +124 -0
  40. docvortex/analyzers/native/ofd/metadata.py +53 -0
  41. docvortex/analyzers/native/ofd/models.py +170 -0
  42. docvortex/analyzers/native/ofd/package.py +346 -0
  43. docvortex/analyzers/native/ofd/path.py +201 -0
  44. docvortex/analyzers/native/ofd/reading_order.py +293 -0
  45. docvortex/analyzers/native/ofd/resources.py +122 -0
  46. docvortex/analyzers/native/ofd/scene.py +347 -0
  47. docvortex/analyzers/native/ofd/table.py +240 -0
  48. docvortex/analyzers/native/ofd/text.py +521 -0
  49. docvortex/analyzers/native/office/__init__.py +3 -0
  50. docvortex/analyzers/native/office/doc/__init__.py +3 -0
  51. docvortex/analyzers/native/office/doc/bookmarks.py +81 -0
  52. docvortex/analyzers/native/office/doc/doc_converter.py +573 -0
  53. docvortex/analyzers/native/office/doc/fib.py +261 -0
  54. docvortex/analyzers/native/office/doc/fields.py +101 -0
  55. docvortex/analyzers/native/office/doc/formatting.py +171 -0
  56. docvortex/analyzers/native/office/doc/images.py +162 -0
  57. docvortex/analyzers/native/office/doc/lists.py +356 -0
  58. docvortex/analyzers/native/office/doc/models.py +164 -0
  59. docvortex/analyzers/native/office/doc/parser.py +851 -0
  60. docvortex/analyzers/native/office/doc/pieces.py +256 -0
  61. docvortex/analyzers/native/office/doc/records.py +40 -0
  62. docvortex/analyzers/native/office/doc/sprm.py +269 -0
  63. docvortex/analyzers/native/office/doc/styles.py +215 -0
  64. docvortex/analyzers/native/office/docx/__init__.py +3 -0
  65. docvortex/analyzers/native/office/docx/context.py +71 -0
  66. docvortex/analyzers/native/office/docx/docx_converter.py +614 -0
  67. docvortex/analyzers/native/office/docx/equationxml.py +119 -0
  68. docvortex/analyzers/native/office/docx/fields.py +816 -0
  69. docvortex/analyzers/native/office/docx/formatting_types.py +23 -0
  70. docvortex/analyzers/native/office/docx/main.py +50 -0
  71. docvortex/analyzers/native/office/docx/numbering.py +491 -0
  72. docvortex/analyzers/native/office/docx/office_xml.py +57 -0
  73. docvortex/analyzers/native/office/docx/package_normalizer.py +248 -0
  74. docvortex/analyzers/native/office/docx/resources.py +526 -0
  75. docvortex/analyzers/native/office/docx/styles.py +693 -0
  76. docvortex/analyzers/native/office/docx/tables.py +515 -0
  77. docvortex/analyzers/native/office/equation/__init__.py +3 -0
  78. docvortex/analyzers/native/office/equation/image.py +470 -0
  79. docvortex/analyzers/native/office/equation/latex_dict.py +324 -0
  80. docvortex/analyzers/native/office/equation/mtef.py +885 -0
  81. docvortex/analyzers/native/office/equation/mtef_v5.py +941 -0
  82. docvortex/analyzers/native/office/equation/omml.py +561 -0
  83. docvortex/analyzers/native/office/equation/ooxml.py +62 -0
  84. docvortex/analyzers/native/office/errors.py +33 -0
  85. docvortex/analyzers/native/office/image.py +307 -0
  86. docvortex/analyzers/native/office/legacy/__init__.py +3 -0
  87. docvortex/analyzers/native/office/legacy/binary.py +43 -0
  88. docvortex/analyzers/native/office/legacy/officeart.py +362 -0
  89. docvortex/analyzers/native/office/legacy/ole.py +110 -0
  90. docvortex/analyzers/native/office/limits.py +12 -0
  91. docvortex/analyzers/native/office/odf/__init__.py +3 -0
  92. docvortex/analyzers/native/office/odf/chart.py +76 -0
  93. docvortex/analyzers/native/office/odf/constants.py +70 -0
  94. docvortex/analyzers/native/office/odf/converters.py +403 -0
  95. docvortex/analyzers/native/office/odf/errors.py +18 -0
  96. docvortex/analyzers/native/office/odf/metadata.py +91 -0
  97. docvortex/analyzers/native/office/odf/models.py +176 -0
  98. docvortex/analyzers/native/office/odf/package.py +270 -0
  99. docvortex/analyzers/native/office/odf/styles.py +329 -0
  100. docvortex/analyzers/native/office/odf/table.py +469 -0
  101. docvortex/analyzers/native/office/odf/text.py +1002 -0
  102. docvortex/analyzers/native/office/ooxml_chart.py +1016 -0
  103. docvortex/analyzers/native/office/opc.py +38 -0
  104. docvortex/analyzers/native/office/ppt/__init__.py +3 -0
  105. docvortex/analyzers/native/office/ppt/models.py +118 -0
  106. docvortex/analyzers/native/office/ppt/parser.py +1895 -0
  107. docvortex/analyzers/native/office/ppt/ppt_converter.py +292 -0
  108. docvortex/analyzers/native/office/ppt/records.py +131 -0
  109. docvortex/analyzers/native/office/ppt/style_text.py +247 -0
  110. docvortex/analyzers/native/office/pptx/__init__.py +3 -0
  111. docvortex/analyzers/native/office/pptx/context.py +113 -0
  112. docvortex/analyzers/native/office/pptx/lists.py +558 -0
  113. docvortex/analyzers/native/office/pptx/main.py +20 -0
  114. docvortex/analyzers/native/office/pptx/package_normalizer.py +321 -0
  115. docvortex/analyzers/native/office/pptx/pptx_converter.py +323 -0
  116. docvortex/analyzers/native/office/pptx/resources.py +329 -0
  117. docvortex/analyzers/native/office/pptx/shapes.py +393 -0
  118. docvortex/analyzers/native/office/pptx/text_styles.py +625 -0
  119. docvortex/analyzers/native/office/pptx/titles.py +178 -0
  120. docvortex/analyzers/native/office/rich_text.py +420 -0
  121. docvortex/analyzers/native/office/rtf/__init__.py +3 -0
  122. docvortex/analyzers/native/office/rtf/converter.py +708 -0
  123. docvortex/analyzers/native/office/rtf/lexer.py +213 -0
  124. docvortex/analyzers/native/office/rtf/math.py +339 -0
  125. docvortex/analyzers/native/office/rtf/models.py +185 -0
  126. docvortex/analyzers/native/office/rtf/parser.py +1553 -0
  127. docvortex/analyzers/native/office/spreadsheet/__init__.py +3 -0
  128. docvortex/analyzers/native/office/spreadsheet/html.py +81 -0
  129. docvortex/analyzers/native/office/spreadsheet/models.py +79 -0
  130. docvortex/analyzers/native/office/spreadsheet/projector.py +928 -0
  131. docvortex/analyzers/native/office/streams.py +18 -0
  132. docvortex/analyzers/native/office/xls/__init__.py +3 -0
  133. docvortex/analyzers/native/office/xls/chart.py +132 -0
  134. docvortex/analyzers/native/office/xls/embedded_chart.py +299 -0
  135. docvortex/analyzers/native/office/xls/models.py +109 -0
  136. docvortex/analyzers/native/office/xls/number_format.py +521 -0
  137. docvortex/analyzers/native/office/xls/parser.py +1145 -0
  138. docvortex/analyzers/native/office/xls/records.py +201 -0
  139. docvortex/analyzers/native/office/xls/strings.py +205 -0
  140. docvortex/analyzers/native/office/xls/xls_converter.py +354 -0
  141. docvortex/analyzers/native/office/xlsx/__init__.py +3 -0
  142. docvortex/analyzers/native/office/xlsx/main.py +20 -0
  143. docvortex/analyzers/native/office/xlsx/ooxml_ole.py +522 -0
  144. docvortex/analyzers/native/office/xlsx/package_normalizer.py +310 -0
  145. docvortex/analyzers/native/office/xlsx/xlsx_converter.py +716 -0
  146. docvortex/analyzers/native/pdf/__init__.py +3 -0
  147. docvortex/analyzers/native/pdf/auxiliary_text.py +1671 -0
  148. docvortex/analyzers/native/pdf/char_geometry.py +1662 -0
  149. docvortex/analyzers/native/pdf/code_blocks.py +535 -0
  150. docvortex/analyzers/native/pdf/formulas.py +1985 -0
  151. docvortex/analyzers/native/pdf/geometry.py +281 -0
  152. docvortex/analyzers/native/pdf/graphics.py +1501 -0
  153. docvortex/analyzers/native/pdf/index_blocks.py +268 -0
  154. docvortex/analyzers/native/pdf/inline/__init__.py +3 -0
  155. docvortex/analyzers/native/pdf/inline/common.py +112 -0
  156. docvortex/analyzers/native/pdf/inline/detection.py +590 -0
  157. docvortex/analyzers/native/pdf/inline/matching.py +1185 -0
  158. docvortex/analyzers/native/pdf/inline/materialize.py +457 -0
  159. docvortex/analyzers/native/pdf/inline/scripts.py +975 -0
  160. docvortex/analyzers/native/pdf/inline/types.py +385 -0
  161. docvortex/analyzers/native/pdf/line_layout.py +1106 -0
  162. docvortex/analyzers/native/pdf/line_merging.py +1223 -0
  163. docvortex/analyzers/native/pdf/models.py +246 -0
  164. docvortex/analyzers/native/pdf/native_text.py +1004 -0
  165. docvortex/analyzers/native/pdf/pipeline.py +1390 -0
  166. docvortex/analyzers/native/pdf/script_geometry.py +636 -0
  167. docvortex/analyzers/native/pdf/shared.py +30 -0
  168. docvortex/analyzers/native/pdf/spatial_text.py +383 -0
  169. docvortex/analyzers/native/pdf/table_annotations.py +446 -0
  170. docvortex/analyzers/native/pdf/table_constants.py +48 -0
  171. docvortex/analyzers/native/pdf/table_detection.py +227 -0
  172. docvortex/analyzers/native/pdf/table_filled_grid.py +218 -0
  173. docvortex/analyzers/native/pdf/table_geometry.py +40 -0
  174. docvortex/analyzers/native/pdf/table_materialization.py +444 -0
  175. docvortex/analyzers/native/pdf/table_recovery/__init__.py +15 -0
  176. docvortex/analyzers/native/pdf/table_recovery/candidate.py +356 -0
  177. docvortex/analyzers/native/pdf/table_recovery/contracts.py +154 -0
  178. docvortex/analyzers/native/pdf/table_recovery/engine.py +609 -0
  179. docvortex/analyzers/native/pdf/table_recovery/geometry.py +164 -0
  180. docvortex/analyzers/native/pdf/table_recovery/sparse_common.py +85 -0
  181. docvortex/analyzers/native/pdf/table_recovery/sparse_hybrid.py +804 -0
  182. docvortex/analyzers/native/pdf/table_recovery/sparse_multiline.py +1122 -0
  183. docvortex/analyzers/native/pdf/table_recovery/text.py +414 -0
  184. docvortex/analyzers/native/pdf/table_recovery/text_grid.py +618 -0
  185. docvortex/analyzers/native/pdf/table_recovery/vector.py +1931 -0
  186. docvortex/analyzers/native/pdf/table_rows.py +34 -0
  187. docvortex/analyzers/native/pdf/table_rules.py +1129 -0
  188. docvortex/analyzers/native/pdf/table_text_styles.py +283 -0
  189. docvortex/analyzers/native/pdf/tables.py +147 -0
  190. docvortex/analyzers/native/pdf/text_assembly/__init__.py +3 -0
  191. docvortex/analyzers/native/pdf/text_assembly/annotations.py +581 -0
  192. docvortex/analyzers/native/pdf/text_assembly/assembly.py +292 -0
  193. docvortex/analyzers/native/pdf/text_assembly/common.py +477 -0
  194. docvortex/analyzers/native/pdf/text_assembly/footnotes.py +394 -0
  195. docvortex/analyzers/native/pdf/text_assembly/merging.py +1274 -0
  196. docvortex/analyzers/native/pdf/text_assembly/rows.py +692 -0
  197. docvortex/analyzers/native/pdf/text_blocks.py +82 -0
  198. docvortex/analyzers/native/pdf/text_styles.py +55 -0
  199. docvortex/analyzers/native/pdf/title_analysis/__init__.py +3 -0
  200. docvortex/analyzers/native/pdf/title_analysis/body_profile.py +215 -0
  201. docvortex/analyzers/native/pdf/title_analysis/common.py +117 -0
  202. docvortex/analyzers/native/pdf/title_analysis/document_profile.py +164 -0
  203. docvortex/analyzers/native/pdf/title_analysis/lane_titles.py +758 -0
  204. docvortex/analyzers/native/pdf/title_analysis/page_titles.py +1024 -0
  205. docvortex/analyzers/native/pdf/title_analysis/prototype.py +194 -0
  206. docvortex/analyzers/native/pdf/title_analysis/structural.py +1081 -0
  207. docvortex/analyzers/native/pdf/titles.py +75 -0
  208. docvortex/analyzers/native/pdf/typography.py +19 -0
  209. docvortex/analyzers/native/pdf/visual_annotations.py +1262 -0
  210. docvortex/api.py +180 -0
  211. docvortex/assets/__init__.py +5 -0
  212. docvortex/assets/store.py +51 -0
  213. docvortex/cli.py +54 -0
  214. docvortex/codecs/__init__.py +3 -0
  215. docvortex/codecs/html/__init__.py +22 -0
  216. docvortex/codecs/html/contracts.py +236 -0
  217. docvortex/codecs/html/materializer.py +331 -0
  218. docvortex/codecs/html/parser.py +763 -0
  219. docvortex/codecs/html/resources.py +34 -0
  220. docvortex/codecs/json.py +17 -0
  221. docvortex/content/__init__.py +5 -0
  222. docvortex/content/inline.py +248 -0
  223. docvortex/content/markup/__init__.py +44 -0
  224. docvortex/content/markup/anchors.py +188 -0
  225. docvortex/content/markup/formula.py +280 -0
  226. docvortex/content/markup/projector.py +1237 -0
  227. docvortex/content/markup/styles.py +327 -0
  228. docvortex/content/mathml.py +167 -0
  229. docvortex/content/normalization.py +188 -0
  230. docvortex/content/spans.py +183 -0
  231. docvortex/content/table/__init__.py +18 -0
  232. docvortex/content/table/blocks.py +152 -0
  233. docvortex/content/table/content.py +425 -0
  234. docvortex/content/table/document.py +104 -0
  235. docvortex/content/table/html.py +399 -0
  236. docvortex/content/table/models.py +76 -0
  237. docvortex/content/table/rules.py +42 -0
  238. docvortex/content/table/structure.py +221 -0
  239. docvortex/content/tree.py +5 -0
  240. docvortex/document/__init__.py +3 -0
  241. docvortex/document/contracts.py +22 -0
  242. docvortex/document/detection.py +389 -0
  243. docvortex/document/filetypes.py +175 -0
  244. docvortex/document/page_range.py +167 -0
  245. docvortex/document/pdf/__init__.py +19 -0
  246. docvortex/document/pdf/classify.py +1138 -0
  247. docvortex/document/pdf/constants.py +132 -0
  248. docvortex/document/pdf/diagnostics.py +350 -0
  249. docvortex/document/pdf/document.py +582 -0
  250. docvortex/document/pdf/font_runtime.py +335 -0
  251. docvortex/document/pdf/geometry.py +31 -0
  252. docvortex/document/pdf/images.py +654 -0
  253. docvortex/document/pdf/native_annotations.py +367 -0
  254. docvortex/document/pdf/native_contracts.py +169 -0
  255. docvortex/document/pdf/native_coordinates.py +216 -0
  256. docvortex/document/pdf/native_lifecycle.py +16 -0
  257. docvortex/document/pdf/native_objects.py +902 -0
  258. docvortex/document/pdf/native_text_geometry.py +315 -0
  259. docvortex/document/pdf/pdfium.py +325 -0
  260. docvortex/document/pdf/raster.py +46 -0
  261. docvortex/document/pdf/text/__init__.py +62 -0
  262. docvortex/document/pdf/text/contracts.py +211 -0
  263. docvortex/document/pdf/text/extract.py +165 -0
  264. docvortex/document/pdf/text/geometry.py +16 -0
  265. docvortex/document/pdf/text/groups.py +162 -0
  266. docvortex/document/pdf/visual_geometry.py +201 -0
  267. docvortex/document/pdf/visuals.py +343 -0
  268. docvortex/document/source.py +92 -0
  269. docvortex/errors.py +21 -0
  270. docvortex/export/__init__.py +3 -0
  271. docvortex/export/bundle.py +98 -0
  272. docvortex/export/files.py +66 -0
  273. docvortex/export/middle.py +208 -0
  274. docvortex/foundation/__init__.py +3 -0
  275. docvortex/foundation/geometry.py +125 -0
  276. docvortex/foundation/hyperlink.py +65 -0
  277. docvortex/foundation/image.py +48 -0
  278. docvortex/foundation/image_encoding.py +30 -0
  279. docvortex/foundation/image_payload.py +280 -0
  280. docvortex/foundation/language.py +92 -0
  281. docvortex/foundation/platform.py +38 -0
  282. docvortex/foundation/text.py +153 -0
  283. docvortex/foundation/type_identity.py +20 -0
  284. docvortex/foundation/xml_names.py +20 -0
  285. docvortex/options.py +30 -0
  286. docvortex/postprocess/__init__.py +3 -0
  287. docvortex/postprocess/content.py +53 -0
  288. docvortex/postprocess/document.py +19 -0
  289. docvortex/postprocess/lists.py +236 -0
  290. docvortex/postprocess/page_blocks.py +214 -0
  291. docvortex/postprocess/pages.py +95 -0
  292. docvortex/postprocess/paragraphs.py +580 -0
  293. docvortex/postprocess/visual.py +715 -0
  294. docvortex/render/__init__.py +48 -0
  295. docvortex/render/_internal/__init__.py +3 -0
  296. docvortex/render/_internal/common/__init__.py +3 -0
  297. docvortex/render/_internal/common/context.py +43 -0
  298. docvortex/render/_internal/common/html_table.py +178 -0
  299. docvortex/render/_internal/common/index.py +33 -0
  300. docvortex/render/_internal/common/list_items.py +158 -0
  301. docvortex/render/_internal/common/planner.py +140 -0
  302. docvortex/render/_internal/docx/__init__.py +3 -0
  303. docvortex/render/_internal/docx/assets.py +202 -0
  304. docvortex/render/_internal/docx/inline.py +434 -0
  305. docvortex/render/_internal/docx/math.py +220 -0
  306. docvortex/render/_internal/docx/renderer.py +905 -0
  307. docvortex/render/_internal/docx/styles.py +195 -0
  308. docvortex/render/_internal/docx/table.py +442 -0
  309. docvortex/render/_internal/epub/__init__.py +5 -0
  310. docvortex/render/_internal/epub/assets.py +173 -0
  311. docvortex/render/_internal/epub/package.py +249 -0
  312. docvortex/render/_internal/epub/renderer.py +1156 -0
  313. docvortex/render/_internal/html/__init__.py +3 -0
  314. docvortex/render/_internal/html/inline.py +346 -0
  315. docvortex/render/_internal/html/renderer.py +1041 -0
  316. docvortex/render/_internal/html/sanitizer.py +478 -0
  317. docvortex/render/_internal/html/table.py +121 -0
  318. docvortex/render/_internal/latex/__init__.py +1 -0
  319. docvortex/render/_internal/latex/assets.py +85 -0
  320. docvortex/render/_internal/latex/inline.py +145 -0
  321. docvortex/render/_internal/latex/renderer.py +506 -0
  322. docvortex/render/_internal/latex/table.py +347 -0
  323. docvortex/render/_internal/markdown/__init__.py +3 -0
  324. docvortex/render/_internal/markdown/assets.py +78 -0
  325. docvortex/render/_internal/markdown/blocks.py +635 -0
  326. docvortex/render/_internal/markdown/escaping.py +51 -0
  327. docvortex/render/_internal/markdown/inline.py +260 -0
  328. docvortex/render/_internal/markdown/renderer.py +93 -0
  329. docvortex/render/_internal/markdown/table.py +281 -0
  330. docvortex/render/_internal/pdf/__init__.py +3 -0
  331. docvortex/render/_internal/pdf/assets.py +197 -0
  332. docvortex/render/_internal/pdf/formula.py +417 -0
  333. docvortex/render/_internal/pdf/inline.py +343 -0
  334. docvortex/render/_internal/pdf/renderer.py +734 -0
  335. docvortex/render/_internal/pdf/styles.py +206 -0
  336. docvortex/render/_internal/pdf/table.py +272 -0
  337. docvortex/render/_internal/structured_content/__init__.py +3 -0
  338. docvortex/render/_internal/structured_content/renderer.py +193 -0
  339. docvortex/render/api.py +199 -0
  340. docvortex/render/contracts.py +205 -0
  341. docvortex/render/docx.py +38 -0
  342. docvortex/render/epub.py +35 -0
  343. docvortex/render/fragments.py +70 -0
  344. docvortex/render/html.py +29 -0
  345. docvortex/render/latex.py +24 -0
  346. docvortex/render/markdown.py +50 -0
  347. docvortex/render/pdf.py +25 -0
  348. docvortex/render/structured_content.py +23 -0
  349. docvortex/resources/epub/docvortex.css +91 -0
  350. docvortex/resources/fasttext-langdetect/lid.176.ftz +0 -0
  351. docvortex/resources/fonts/DroidSansFallbackFull.ttf +0 -0
  352. docvortex/resources/fonts/NOTICE +190 -0
  353. docvortex/resources/fonts/manifest.json +9 -0
  354. docvortex/resources/html/docvortex.css +601 -0
  355. docvortex/resources/html/docvortex.min.css +1 -0
  356. docvortex/result.py +91 -0
  357. docvortex/schema.py +1141 -0
  358. docvortex/version.py +3 -0
  359. docvortex-0.2.1.dist-info/METADATA +193 -0
  360. docvortex-0.2.1.dist-info/RECORD +364 -0
  361. docvortex-0.2.1.dist-info/WHEEL +5 -0
  362. docvortex-0.2.1.dist-info/entry_points.txt +2 -0
  363. docvortex-0.2.1.dist-info/licenses/LICENSE.md +21 -0
  364. docvortex-0.2.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,331 @@
1
+ """把已验证的 DocVortex HTML v1 typed plan 物化为 raw model-list。"""
2
+
3
+ from __future__ import annotations
4
+
5
+ from copy import deepcopy
6
+ import html
7
+
8
+ from lxml import etree # type: ignore[reportMissingImports]
9
+
10
+ from ...schema import RAW_ALGORITHM, BlockType
11
+ from docvortex.content.markup import MarkupProjector, MarkupStylesheet, extract_formula
12
+ from docvortex.content.markup.projector import BLOCK_TAGS, local_name
13
+ from ...content.spans import text_spans
14
+ from .resources import WireResourceContext
15
+ from .contracts import (
16
+ AnnotationWireSpec,
17
+ CodeBodyWireSpec,
18
+ EquationWireSpec,
19
+ FlowchartBodyWireSpec,
20
+ IndexBlockWireSpec,
21
+ IndexLeafWireSpec,
22
+ IndexWireSpec,
23
+ ListBlockWireSpec,
24
+ ListWireSpec,
25
+ DocVortexHtmlWirePlan,
26
+ RichVisualBodyWireSpec,
27
+ TableBodyWireSpec,
28
+ TextWireSpec,
29
+ VisualWireSpec,
30
+ )
31
+
32
+
33
+ class ExactAnchorResolver:
34
+ """把 renderer DOM id 恢复为 typed plan 中保存的原始 anchor。"""
35
+
36
+ def __init__(self, plan: DocVortexHtmlWirePlan) -> None:
37
+ """预扫描标题和页面脚注的 id、文本及原始 anchor。"""
38
+ self._targets: dict[str, str] = {}
39
+ self._heading_anchors: dict[etree._Element, str] = {}
40
+ self._heading_labels: dict[str, str] = {}
41
+ self._note_anchors: dict[etree._Element, str] = {}
42
+ for spec in plan.blocks:
43
+ if not isinstance(spec, TextWireSpec):
44
+ continue
45
+ anchor = (spec.wrapper.get("data-anchor") or "").strip()
46
+ if not anchor:
47
+ continue
48
+ self._targets.setdefault(anchor, anchor)
49
+ for candidate in [spec.content_root, *spec.content_root.iterdescendants()]:
50
+ identity = (candidate.get("id") or "").strip()
51
+ if identity:
52
+ self._targets.setdefault(identity, anchor)
53
+ if spec.block_type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:
54
+ self._heading_anchors[spec.content_root] = anchor
55
+ self._heading_labels[anchor] = " ".join(spec.content_root.itertext()).strip()
56
+ elif spec.block_type == BlockType.PAGE_FOOTNOTE:
57
+ self._note_anchors[spec.content_root] = anchor
58
+
59
+ def resolve_fragment(self, fragment: str) -> str | None:
60
+ """把 renderer id 或原始 anchor 统一还原为内部 fragment。"""
61
+ identity = fragment.removeprefix("#").strip()
62
+ return f"#{anchor}" if (anchor := self._targets.get(identity)) else None
63
+
64
+ def heading_anchor(self, heading: etree._Element) -> str | None:
65
+ """返回精确标题节点的原始 anchor。"""
66
+ return self._heading_anchors.get(heading)
67
+
68
+ def heading_label(self, anchor: str) -> str | None:
69
+ """返回原始 anchor 对应的标题文本。"""
70
+ return self._heading_labels.get(anchor)
71
+
72
+ def note_anchor(self, note: etree._Element) -> str | None:
73
+ """返回精确页面脚注节点的原始 anchor。"""
74
+ return self._note_anchors.get(note)
75
+
76
+
77
+ def materialize_docvortex_html_wire(
78
+ plan: DocVortexHtmlWirePlan,
79
+ resources: WireResourceContext,
80
+ ) -> list[dict[str, object]]:
81
+ """在整棵 canonical 树验证成功后一次性解析资源并生成 raw blocks。"""
82
+ resources.bind_anchors(ExactAnchorResolver(plan))
83
+ stylesheet = MarkupStylesheet()
84
+ projector = MarkupProjector(plan.root, resources, stylesheet, single_document_title=True)
85
+ blocks: list[dict[str, object]] = []
86
+ for spec in plan.blocks:
87
+ if isinstance(spec, TextWireSpec):
88
+ blocks.append(_materialize_text(spec, projector))
89
+ elif isinstance(spec, EquationWireSpec):
90
+ blocks.append(_materialize_equation(spec, resources))
91
+ elif isinstance(spec, VisualWireSpec):
92
+ blocks.extend(_materialize_visual(spec, resources, projector))
93
+ elif isinstance(spec, ListBlockWireSpec):
94
+ blocks.append(_materialize_list(spec.root, projector))
95
+ elif isinstance(spec, IndexBlockWireSpec):
96
+ blocks.append(_materialize_index(spec.root, projector))
97
+ else: # pragma: no cover - PageWireSpec 已穷尽。
98
+ raise AssertionError(f"unsupported wire spec: {type(spec).__name__}")
99
+ return blocks
100
+
101
+
102
+ def _materialize_text(spec: TextWireSpec, projector: MarkupProjector) -> dict[str, object]:
103
+ """恢复文本、标题、页面辅助块和页面脚注。"""
104
+ block: dict[str, object] = {
105
+ "type": spec.block_type,
106
+ "content": _project_inline_content(projector, spec.content_root),
107
+ }
108
+ if spec.block_type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:
109
+ block["level"] = int(spec.wrapper.get("data-level") or 1)
110
+ if spec.block_type in {BlockType.TEXT, BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE, BlockType.PAGE_FOOTNOTE}:
111
+ anchor = (spec.wrapper.get("data-anchor") or "").strip()
112
+ if anchor:
113
+ block["anchor"] = anchor
114
+ return block
115
+
116
+
117
+ def _materialize_equation(spec: EquationWireSpec, resources: WireResourceContext) -> dict[str, object]:
118
+ """恢复行间公式裸 LaTeX 或 renderer-owned 公式图片。"""
119
+ formula = extract_formula(spec.content_root)
120
+ block: dict[str, object] = {
121
+ "type": BlockType.EQUATION,
122
+ "content": formula.latex if formula is not None else "",
123
+ }
124
+ if formula is None:
125
+ block.update(_resolve_image_payload(spec.content_root, resources))
126
+ return block
127
+
128
+
129
+ def _materialize_visual(
130
+ spec: VisualWireSpec,
131
+ resources: WireResourceContext,
132
+ projector: MarkupProjector,
133
+ ) -> list[dict[str, object]]:
134
+ """按 renderer DOM 顺序恢复 visual body 与 annotations。"""
135
+ blocks: list[dict[str, object]] = []
136
+ for child in spec.children:
137
+ if isinstance(child, AnnotationWireSpec):
138
+ blocks.append(
139
+ {
140
+ "type": child.block_type,
141
+ "content": _project_inline_content(projector, child.element),
142
+ }
143
+ )
144
+ continue
145
+ block = _materialize_visual_body(child, resources, projector)
146
+ if spec.sub_type:
147
+ block["sub_type"] = spec.sub_type
148
+ if isinstance(child, CodeBodyWireSpec) and child.kind == "code":
149
+ block["guess_lang"] = spec.guess_lang
150
+ blocks.append(block)
151
+ return blocks
152
+
153
+
154
+ def _materialize_visual_body(
155
+ spec: RichVisualBodyWireSpec | FlowchartBodyWireSpec | TableBodyWireSpec | CodeBodyWireSpec,
156
+ resources: WireResourceContext,
157
+ projector: MarkupProjector,
158
+ ) -> dict[str, object]:
159
+ """从 typed body spec 恢复唯一载荷,不重新判断 DOM 形状。"""
160
+ if isinstance(spec, RichVisualBodyWireSpec):
161
+ block: dict[str, object] = {
162
+ "type": spec.parent_type,
163
+ "content": _restore_content(spec.content_fragment, projector),
164
+ }
165
+ if spec.primary_image is not None:
166
+ block.update(_resolve_image_payload(spec.primary_image, resources))
167
+ return block
168
+ if isinstance(spec, FlowchartBodyWireSpec):
169
+ block = {
170
+ "type": BlockType.IMAGE,
171
+ "content": _flowchart_content(spec.source_element),
172
+ }
173
+ if spec.fallback_image is not None:
174
+ block.update(_resolve_image_payload(spec.fallback_image, resources))
175
+ return block
176
+ if isinstance(spec, TableBodyWireSpec):
177
+ return _materialize_table(spec, resources, projector)
178
+ return _materialize_code(spec, projector)
179
+
180
+
181
+ def _materialize_table(
182
+ spec: TableBodyWireSpec,
183
+ resources: WireResourceContext,
184
+ projector: MarkupProjector,
185
+ ) -> dict[str, object]:
186
+ """恢复已判别的结构表格、文本、图片或空载荷。"""
187
+ block: dict[str, object] = {"type": BlockType.TABLE, "content": ""}
188
+ if spec.kind == "html" and spec.payload_element is not None:
189
+ fragment = etree.Element("div")
190
+ fragment.append(deepcopy(spec.payload_element))
191
+ block["content"] = _restore_content(fragment, projector)
192
+ elif spec.kind == "text" and spec.payload_element is not None:
193
+ block["content"] = "".join(spec.payload_element.itertext())
194
+ elif spec.kind == "image" and spec.payload_element is not None:
195
+ block.update(_resolve_image_payload(spec.payload_element, resources))
196
+ return block
197
+
198
+
199
+ def _materialize_code(spec: CodeBodyWireSpec, projector: MarkupProjector) -> dict[str, object]:
200
+ """恢复普通代码文本或 algorithm 行内语义。"""
201
+ if spec.kind == "code":
202
+ return {
203
+ "type": BlockType.CODE,
204
+ "content": "".join(spec.content_element.itertext()),
205
+ }
206
+ return {
207
+ "type": RAW_ALGORITHM,
208
+ "content": _project_inline_content(projector, spec.content_element),
209
+ }
210
+
211
+
212
+ def _materialize_list(spec: ListWireSpec, projector: MarkupProjector) -> dict[str, object]:
213
+ """递归恢复列表叶子、marker 和嵌套 ListBlock。"""
214
+ children: list[dict[str, object]] = []
215
+ for child in spec.children:
216
+ if isinstance(child, ListWireSpec):
217
+ children.append(_materialize_list(child, projector))
218
+ continue
219
+ content = _project_inline_content(projector, child.content_element) if child.content_element is not None else []
220
+ if child.marker and ({"docvortex-list--reference", "docvortex-list--explicit"} & spec.classes):
221
+ content = [*text_spans(f"{child.marker} "), *content]
222
+ block: dict[str, object] = {"type": child.block_type, "content": content}
223
+ if child.block_index is not None:
224
+ block["index"] = child.block_index
225
+ children.append(block)
226
+ block = {
227
+ "type": BlockType.LIST,
228
+ "attribute": "ordered" if spec.ordered else "unordered",
229
+ "content": children,
230
+ }
231
+ if spec.ordered:
232
+ block["start"] = spec.start
233
+ if spec.sub_type:
234
+ block["sub_type"] = spec.sub_type
235
+ return block
236
+
237
+
238
+ def _materialize_index(spec: IndexWireSpec, projector: MarkupProjector) -> dict[str, object]:
239
+ """递归恢复目录叶子和嵌套 IndexBlock。"""
240
+ children: list[dict[str, object]] = []
241
+ for child in spec.children:
242
+ if isinstance(child, IndexWireSpec):
243
+ nested = _materialize_index(child, projector)
244
+ if child.block_index is not None:
245
+ nested["index"] = child.block_index
246
+ children.append(nested)
247
+ continue
248
+ children.append(_materialize_index_leaf(child, projector))
249
+ return {"type": BlockType.INDEX, "content": children}
250
+
251
+
252
+ def _materialize_index_leaf(spec: IndexLeafWireSpec, projector: MarkupProjector) -> dict[str, object]:
253
+ """恢复目录叶子的内容和标题元数据。"""
254
+ content = _project_inline_content(projector, spec.content_element) if spec.content_element is not None else []
255
+ block: dict[str, object] = {"type": spec.block_type, "content": content}
256
+ if spec.anchor:
257
+ block["anchor"] = spec.anchor
258
+ if spec.block_type in {BlockType.DOC_TITLE, BlockType.PARAGRAPH_TITLE}:
259
+ block["level"] = spec.level or 1
260
+ if spec.block_index is not None:
261
+ block["index"] = spec.block_index
262
+ return block
263
+
264
+
265
+ def _restore_content(fragment: etree._Element | None, projector: MarkupProjector) -> str:
266
+ """按 inline 或安全富 HTML 语义恢复 visual body content。"""
267
+ if fragment is None:
268
+ return ""
269
+ if not _contains_rich_markup(fragment):
270
+ return "".join(fragment.itertext()).strip()
271
+ clone = deepcopy(fragment)
272
+ for carrier in list(clone.iterdescendants()):
273
+ if not isinstance(carrier.tag, str):
274
+ continue
275
+ if local_name(carrier) != "math" or (carrier.get("data-block-type") or "").strip() != BlockType.EQUATION:
276
+ continue
277
+ formula = extract_formula(carrier)
278
+ if formula is None or not formula.latex:
279
+ continue
280
+ replacement = etree.Element("eq")
281
+ replacement.text = formula.latex
282
+ replacement.tail = carrier.tail
283
+ parent = carrier.getparent()
284
+ if parent is not None:
285
+ parent.replace(carrier, replacement)
286
+ return _serialize_fragment(clone)
287
+
288
+
289
+ def _contains_rich_markup(fragment: etree._Element) -> bool:
290
+ """判断片段是否需要以结构化 HTML 而非内部 inline 字符串保存。"""
291
+ return any(
292
+ isinstance(element.tag, str) and (local_name(element) in BLOCK_TAGS or local_name(element) in {"image", "img"})
293
+ for element in fragment.iterdescendants()
294
+ )
295
+
296
+
297
+ def _serialize_fragment(fragment: etree._Element) -> str:
298
+ """把 synthetic fragment 的内容序列化为规范化安全 HTML。"""
299
+ parts = [html.escape(fragment.text or "", quote=False)]
300
+ parts.extend(
301
+ etree.tostring(child, encoding="unicode", method="html", with_tail=True)
302
+ for child in fragment
303
+ if isinstance(child.tag, str)
304
+ )
305
+ return "".join(parts).strip()
306
+
307
+
308
+ def _project_inline_content(projector: MarkupProjector, element: etree._Element) -> list[dict[str, object]]:
309
+ """直接恢复 projector 生成的结构化 Span。"""
310
+ return projector.project_inline_content(element)
311
+
312
+
313
+ def _flowchart_content(source_element: etree._Element) -> str:
314
+ """把 canonical Mermaid 源码恢复为标准 fence。"""
315
+ value = "".join(source_element.itertext()).strip("\n")
316
+ return f"```mermaid\n{value}\n```" if value else ""
317
+
318
+
319
+ def _resolve_image_payload(element: etree._Element, resources: WireResourceContext) -> dict[str, object]:
320
+ """解析已由 canonical parser 选定的单个 renderer-owned 图片。"""
321
+ resolved = resources.resolve_image(element.get("src") or "", alt=element.get("alt") or "")
322
+ if resolved is None:
323
+ return {}
324
+ if resolved.image_base64:
325
+ return {"image_base64": resolved.image_base64}
326
+ if resolved.image_url:
327
+ return {"image_url": resolved.image_url}
328
+ return {}
329
+
330
+
331
+ __all__ = ["ExactAnchorResolver", "materialize_docvortex_html_wire"]