Skip to main content

docparser_core/
lib.rs

1//! `docparser-core`:独立文档解析核心(IR / 统一错误 / 能力抽象 / 注册路由 / 策略 / 引擎)。
2//!
3//! 与 Python 参考实现(`python/docparser/`)共享同一 IR 语义与错误码;
4//! 是发布形态(见 design_docs 06_release_shape.md)的 Rust 侧核心库。
5//! 本 crate 零第三方运行依赖(仅 serde 用于 JSON 往返)。
6//!
7//! # 示例
8//!
9//! ```no_run
10//! use docparser_core::{plugins, DocumentEngine, Registry};
11//!
12//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
13//! let mut registry = Registry::new();
14//! plugins::text::register_defaults(&mut registry); // txt / md / csv / html
15//! let engine = DocumentEngine::new(registry);
16//!
17//! let doc = engine.parse("note.md")?;
18//! println!("{} 页 / {} 字符", doc.pages.len(), doc.meta.text_length);
19//! for block in &doc.pages[0].blocks {
20//!     println!("{:?}: {}", block.kind, block.content);
21//! }
22//! # Ok(())
23//! # }
24//! ```
25//!
26//! 接入其它格式只需注册对应后端(`docparser_pdf::register_defaults` /
27//! `docparser_office::register_defaults` …),见 [`Registry`] 与 [`DocumentEngine`]。
28
29pub mod emit;
30pub mod engine;
31pub mod error;
32pub mod model;
33pub mod plugin;
34pub mod plugins;
35pub mod policy;
36pub mod registry;
37pub mod router;
38
39pub use engine::DocumentEngine;
40pub use error::{DocError, ErrorCode, Result};
41pub use model::{Block, BlockKind, DocMeta, Document, Image, Page, Rect, TableData};
42pub use plugin::{
43    BackendKind, FormatPlugin, ParseCapability, ProcessCapability, RawDoc, RawImage, RawPage,
44    RawTextItem,
45};
46pub use registry::{Registry, RegistryError};