utils
Class info¶
🛈 DocStrings¶
Small helpers around conversion: front matter, title extraction, sanitizing.
extract_title
¶
Return the text of the first <h1> in html, or None if there is none.
Markup inside the heading (emphasis, permalink anchors) is dropped and entities are unescaped.
Source code in src/mkconvert/utils.py
sanitize
¶
sanitize(
html: str, *, extra_attributes: Mapping[str, Set[str]] | None = None, **nh3_options: Any
) -> str
Sanitize HTML with nh3 (needs the nh3 extra).
Uses nh3's safe defaults, which drop e.g. id and class attributes (heading ids,
code block languages). Allow them again with extra_attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html
|
str
|
HTML to clean. |
required |
extra_attributes
|
Mapping[str, Set[str]] | None
|
Attributes to allow in addition to the allowed ones, per tag;
the key |
None
|
nh3_options
|
Any
|
Keyword arguments for |
{}
|
Source code in src/mkconvert/utils.py
split_front_matter
¶
Split a leading ----delimited front matter block off text.
The block may end with --- or .... It is returned unparsed (usually YAML).
Returns:
| Type | Description |
|---|---|
tuple[str | None, str]
|
|