1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! Verbatim Block Registry and Handling
//!
//! This module provides a flexible and extensible system for handling `verbatim` blocks in Lex.
//! Verbatim blocks are chunks of content that are not parsed by the core Lex parser but are preserved
//! as-is. They are often used for code blocks, raw data, or content that requires specialized
//! processing (like tables, images, or diagrams).
//!
//! # Design Philosophy
//!
//! The core philosophy is that Lex should be able to represent any content, even if it doesn't natively
//! understand it. However, when converting to other formats (like HTML, Markdown, or an intermediate
//! representation), we often want to "hydrate" these verbatim blocks into richer semantic structures.
//!
//! For example, a `doc.table` verbatim block containing a pipe table string should ideally become a
//! structured `Table` node in the IR, rather than just a blob of text.
//!
//! # Architecture
//!
//! The system revolves around two main components:
//!
//! 1. **`VerbatimHandler` Trait**: Defines how to convert between a raw verbatim block (string content + params)
//! and a semantic `DocNode` (IR node).
//! 2. **`VerbatimRegistry`**: A central registry that maps labels (e.g., "doc.table", "image") to
//! specific handlers.
//!
//! ## The Translation Layer
//!
//! This module acts as a translation layer between the raw Lex AST and the semantic IR.
//!
//! * **Lex -> IR**: When converting *from* Lex, if a verbatim block's label matches a registered handler,
//! the handler's `to_ir` method is called. This allows "doc.table" to become a `DocNode::Table`.
//! * **IR -> Lex**: When converting *to* Lex, if an IR node (like `DocNode::Table`) needs to be serialized,
//! handlers are queried to see if they can represent it. This allows a `DocNode::Table` to be serialized
//! back as a `doc.table` verbatim block.
//!
//! # Namespaces
//!
//! To support extensibility and avoid collisions, the registry supports namespaced handlers.
//!
//! * **Exact Match**: "doc.table" matches exactly.
//! * **Namespace Match**: "acme.*" matches any label starting with "acme.".
//!
//! This allows plugins to register a catch-all handler for their own custom types.
//!
//! # Standard Handlers
//!
//! Lex provides standard handlers for common types within the `doc` namespace:
//!
//! * `doc.table`: Markdown-style pipe tables.
//! * `doc.image`: Image references.
//! * `doc.video`, `doc.audio`: Media references.
//!
//! # Usage
//!
//! ```rust,ignore
//! let mut registry = VerbatimRegistry::new();
//! registry.register("doc.table", Box::new(TableHandler));
//!
//! // Converting to IR
//! if let Some(handler) = registry.get("doc.table") {
//! let node = handler.to_ir(content, ¶ms);
//! }
//! ```
use crateFormatError;
use crateDocNode;
use Verbatim;
use HashMap;
/// A handler for a specific verbatim block type.
/// A registry for verbatim block handlers.