Module

rendering.api_doc_enhancer

API Documentation Enhancer - Post-processes API docs to inject badges and visual indicators.

This module operates on parsed HTML after Markdown rendering but before template application. It's designed to work around Mistune's HTML escaping while maintaining clean, maintainable code.

Architecture:

  • Operates at the rendering pipeline stage (after Markdown → HTML)
  • Uses marker syntax in templates (@async, @property, etc.)
  • Injects HTML badges via regex replacement
  • Opt-in via page type (python-module, api-reference)

Usage:

from bengal.rendering.api_doc_enhancer import APIDocEnhancer

enhancer = APIDocEnhancer()
enhanced_html = enhancer.enhance(html, page_type='python-module')

Classes

APIDocEnhancer
Post-processes API documentation HTML to inject badges and visual enhancements. This enhancer tran…
4

Post-processes API documentation HTML to inject badges and visual enhancements.

This enhancer transforms marker syntax (e.g., @async, @property) into styled HTML badges. It operates on already-parsed HTML, avoiding Mistune's escaping issues.

Markers are placed in templates after method names and get replaced with proper HTML during post-processing.

Methods 3

should_enhance
Check if a page should be enhanced based on its type.
1 bool
def should_enhance(self, page_type: str | None) -> bool

Check if a page should be enhanced based on its type.

Parameters 1
page_type str | None

The page type from frontmatter

Returns

bool

True if the page should be enhanced

enhance
Enhance HTML with API documentation badges. This method applies all badge tran…
2 str
def enhance(self, html: str, page_type: str | None = None) -> str

Enhance HTML with API documentation badges.

This method applies all badge transformations to the HTML if the page type indicates it's an API documentation page.

Parameters 2
html str

Parsed HTML from markdown rendering

page_type str | None

Page type from frontmatter (optional)

Returns

str

Enhanced HTML with badges injected (or unchanged HTML if not applicable)

strip_markers
Remove all marker syntax from HTML without adding badges. Useful for pages tha…
1 str
def strip_markers(self, html: str) -> str

Remove all marker syntax from HTML without adding badges.

Useful for pages that want to show API documentation without badges, or for debugging purposes.

Parameters 1
html str

HTML with marker syntax

Returns

str

HTML with markers removed

Internal Methods 1
__init__
Initialize the enhancer.
0 None
def __init__(self) -> None

Initialize the enhancer.

Functions

get_enhancer
Get or create the singleton APIDocEnhancer instance.
0 APIDocEnhancer
def get_enhancer() -> APIDocEnhancer

Get or create the singleton APIDocEnhancer instance.

Returns

APIDocEnhancer

Shared APIDocEnhancer instance