Classes
ParseConfig
11
▼
Immutable parse configuration.
Set once per Markdown instance, read by all parsers in the context.…
ParseConfig
11
▼
Immutable parse configuration.
Set once per Markdown instance, read by all parsers in the context. Frozen dataclass ensures thread-safety (immutable after creation).
Note: source_file is intentionally excluded—it's per-call state, not configuration. It remains on the Parser instance.
Attributes
| Name | Type | Description |
|---|---|---|
tables_enabled |
bool
|
Enable GFM table parsing |
strikethrough_enabled |
bool
|
Enable |
task_lists_enabled |
bool
|
Enable - [ ] task list items |
footnotes_enabled |
bool
|
Enable [^ref] footnote references |
math_enabled |
bool
|
Enable $inline$ and $$block$$ math |
autolinks_enabled |
bool
|
Enable automatic URL linking |
directive_registry |
DirectiveRegistry | None
|
Registry for directive handlers |
strict_contracts |
bool
|
Raise errors on directive contract violations |
text_transformer |
Callable[[str], str] | None
|
Optional callback to transform plain text lines |
max_nesting_depth |
int
|
Maximum nesting depth, bounding BOTH deep block-container nesting (block quotes, lists, directives) AND deep inline emphasis/strong nesting. Adversarially deep input of either kind raises a catchable |
Methods
Create ParseConfig from dictionary.
Useful for framework integration where con…
classmethod
def from_dict(cls, config_dict: dict) -> ParseConfig
Create ParseConfig from dictionary.
Useful for framework integration where config may come from external sources (e.g., Bengal's own ParseConfig, YAML files, etc.).
Only includes keys that are valid ParseConfig fields; unknown keys are silently ignored.
Parameters
| Name | Type | Description |
|---|---|---|
config_dict |
— |
Dictionary with config values. Keys should match ParseConfig attribute names. |
Functions
Get current parse configuration (thread-local).
**Thread Safety:**
ContextVars…
def get_parse_config() -> ParseConfig
Get current parse configuration (thread-local).
Thread Safety: ContextVars are thread-local by design. Safe to call from any thread.
Returns
ParseConfig
set_parse_config
1
None
▼
Set parse configuration for current context.
**Thread Safety:**
Only affects t…
set_parse_config
1
None
▼
def set_parse_config(config: ParseConfig) -> None
Set parse configuration for current context.
Thread Safety: Only affects the current thread's context. Other threads are unaffected.
Parameters
| Name | Type | Description |
|---|---|---|
config |
ParseConfig |
ParseConfig instance to use for this context. |
reset_parse_config
0
None
▼
Reset to default configuration.
Reuses the module-level _DEFAULT_CONFIG single…
reset_parse_config
0
None
▼
def reset_parse_config() -> None
Reset to default configuration.
Reuses the module-level _DEFAULT_CONFIG singleton, avoiding allocation.
Thread Safety:
Only affects the current thread's context. Other threads are unaffected.
parse_config_context
1
Iterator[None]
▼
Context manager for temporary config changes.
Useful for tests and isolated pa…
parse_config_context
1
Iterator[None]
▼
def parse_config_context(config: ParseConfig) -> Iterator[None]
Context manager for temporary config changes.
Useful for tests and isolated parsing operations.
Thread Safety: Only affects the current thread's context. Properly restores previous config even if an exception is raised.
Parameters
| Name | Type | Description |
|---|---|---|
config |
ParseConfig |
ParseConfig to use within the context. |
Returns
Iterator[None]