Content extras¶
Stability
Classifications for this surface are recorded in STABILITY.md.
Package maturity (Beta/Alpha) is separate from API level
(beta / experimental / internal / deferred).
Status: Available on 1.0 (introduced in 0.6.0)
Optional content helpers live in hedron.content (lazy imports; missing extras raise
diagnostics with exact install commands).
Markdown¶
| Parameter | Type | Default | Description |
|---|---|---|---|
| body (positional / children) | str |
required | Markdown source |
| (props) | — | — | See component page / Autodoc |
Rendered Markdown is sanitized through TrustedHtml.nh3 before html.raw. Install
hedron[sanitize] (or rely on the markdown extra's dependency chain) so nh3 is available.
highlight_code¶
| Parameter | Type | Default | Description |
|---|---|---|---|
code |
str |
required | Source text |
lexer |
str |
"python" |
Pygments lexer name |
Returns: TrustedHtml (sanitized highlighted markup).
from hedron import highlight_code
from hedron_core.html import html
trusted = highlight_code("print('hi')", lexer="python")
node = html.div(html.raw(trusted), class_="hedron-code")
process_image¶
| Parameter | Type | Default | Description |
|---|---|---|---|
path_or_bytes |
str \| Path \| bytes |
required | Raw image bytes, or a filesystem path |
root |
Path |
required for str/Path |
Jail directory; resolved path must stay under root |
max_width |
int |
1600 |
Downscale when wider |
format |
str |
"PNG" |
Pillow output format (PNG → RGBA, else RGB) |
Returns: bytes — encoded image bytes.
Paths are resolved with Path.resolve().relative_to(root) (same contract as
safe_download_response). Bytes need no root. Missing root for a path is
HED-CONTENT-0006; escape is HED-CONTENT-0007.
from pathlib import Path
from hedron import process_image
uploads = Path("/var/app/uploads")
png_bytes = process_image("photo.jpg", root=uploads, max_width=1200, format="PNG")
png_from_bytes = process_image(raw, max_width=1200, format="PNG")
validate_email_address¶
| Parameter | Type | Default | Description |
|---|---|---|---|
value |
str |
required | Address to validate |
Returns: normalized email str.
Errors¶
| Situation | Code / behavior |
|---|---|
| Markdown / highlight without extra | Diagnostic with install remediation |
process_image without Pillow |
HED-CONTENT-0003 — install hedron[images] |
validate_email_address without email-validator |
HED-CONTENT-0004 — install hedron[email] |
| Invalid email | HED-CONTENT-0005 |
TrustedHtml.nh3 without nh3 |
HED-SEC-0020 — install hedron[sanitize] |
Install remediations¶
| API | Extra |
|---|---|
Markdown |
pip install "hedron[markdown]>=1.0.0" |
highlight_code |
pip install "hedron[code]>=1.0.0" |
process_image |
pip install "hedron[images]>=1.0.0" |
validate_email_address |
pip install "hedron[email]>=1.0.0" |
TrustedHtml.nh3 |
pip install "hedron[sanitize]>=1.0.0" |
See also Security types and Charts and HTMX.