On this page
HTML rendering module that tokenizes Markdown, dispatches blocks to specialized renderers, applies post-processors, and assembles full page shells.
#selfdoc.html
#selfdoc.html
Convert Markdown files to static HTML with a built-in minimal converter.
No external dependencies -- handles headings, code blocks, inline code, paragraphs, lists, links, bold/italic, tables, blockquotes, and admonitions. Syntax highlighting uses Pygments when available (optional dependency).
#_minify_js
def _minify_js(js_text)Minify JavaScript by removing comments and collapsing whitespace.
Conservative approach: avoids breaking URLs containing // and preserves single spaces between identifiers.
#_generate_search_js
def _generate_search_js(engine='builtin')Return the search JS as a standalone IIFE string.
Composes the search engine implementation (builtin, fuse, or minisearch) with the shared dialog UI code. The engine must implement two functions: initSearchEngine(entries) and searchEntries(query) returning [{title, path, snippet, score, highlights}].
Args:
engine: One of "builtin", "fuse", or "minisearch".
#_slugify
def _slugify(text)Convert heading text to a URL-friendly slug for deep linking.
Strips HTML tags first, then: NFKD-normalize to decompose accented characters, strip combining marks, lowercase, spaces to hyphens, remove non-word characters except hyphens (preserves CJK/Cyrillic).
#get_css
def get_css(theme_name='minimal')Return the CSS content for the named theme.
Args:
theme_name: Name of the theme to load (default "minimal").
Returns:
- The CSS content as a string.
#_flatten_dark_css
def _flatten_dark_css(dark_rules)Convert dark mode CSS rules to flat selectors.
Pygments get_style_defs returns rules like .code-block code .hll { ... }. We need to wrap each rule individually for both @media and [data-theme] contexts instead of nesting them (which is invalid CSS without native nesting).
#generate_pygments_css
def generate_pygments_css(light_style='default', dark_style='monokai')Generate Pygments CSS rules for light and dark mode.
Args:
light_style: Pygments style name for light mode.dark_style: Pygments style name for dark mode.
Scoped to .code-block code to match the HTML structure produced by _render_code_block().
Returns the CSS string, or an empty string if Pygments is not installed.
#_generate_hero_html
def _generate_hero_html(branding, project_name, config_description, nav_items)Generate the hero section HTML for the landing page.
Args:
branding: Branding config dict (must not be None).project_name: Project name for the hero title.config_description: Project-level description from config.nav_items: Navigation items list, used to derive default CTA link.
Returns:
- HTML string for the hero section.
#_generate_features_html
def _generate_features_html(branding, nav_items)Generate the feature grid HTML for the landing page.
When branding.features is set, uses those explicitly. Otherwise auto-generates one feature card per nav group (subdirectory).
Args:
branding: Branding config dict (must not be None).nav_items: Navigation items list from _build_nav.
Returns:
- HTML string for the feature grid, or empty string if no features.
#generate_html
def generate_html(markdown_files, project_name=None, version=None, has_custom_css=False, repo=None, docs_dir_name='docs/', base_url=None, frontmatter=None, lang='en', page_dates=None, author=None, feed_url=None, critical_css=None, twitter_site=None, search=None, feedback=None, branch='main', search_engine=None, branding=None, config_description=None, auto_detect=None, theme_meta=None, deploy_target=None, run_button=False, line_numbers=False, page_nav=True, page_progress=True, code_icons='colorful', glossary=True, url_prefix='', available_versions=None, available_locales=None, current_version='', current_locale='', is_latest=True)Convert Markdown files to static HTML.
Args:
markdown_files: Dict mapping relative paths to MD content.project_name: Project name for titles and sidebar.version: Version string for display (optional).has_custom_css: Whether a custom.css file exists for the project.repo: GitHub repo URL for "Edit this page" links (optional).docs_dir_name: Docs directory name for constructing source paths.base_url: Base URL for canonical links and sitemap (optional).frontmatter: Dict mapping relative paths to metadata dicts (Feature 34).page_dates: Dict mapping relative paths to (published, modified) tuples (optional).author: Author dict from config (optional, keys: name, type, url).feed_url: Relative URL to the Atom feed (optional, e.g. "feed.xml").url_prefix: Path prefix for versioned/localized URLs (e.g. "en/0.7.0").available_versions: List of version dicts for version picker (optional).available_locales: List of locale dicts for locale picker (optional).current_version: Current version being built (e.g. "0.7.0").current_locale: Current locale being built (e.g. "en").is_latest: Whether this is the latest version (default True).
Returns:
- Dict mapping file paths (.html) to HTML content.
#generate_404_page
def generate_404_page(project_name=None, version=None, has_custom_css=False, nav_items=None, repo=None, base_url=None, lang='en', feed_url=None, critical_css=None, theme_meta=None)Generate a custom 404 page using the standard page template (Feature 39).
Returns the full HTML string for 404.html.
#_render_heading
def _render_heading(token, seen_slugs, first_h1_consumed_ref)Render a Heading token to HTML.
Returns the HTML string, or empty string if this is the first H1 (which is consumed as the page title by _wrap_page).
#_render_table
def _render_table(token, tokens, idx)Render a Table token to HTML, wrapped in .table-wrap with caption.
#_render_definition_list
def _render_definition_list(token)Render a DefinitionList token to HTML.
#_render_block
def _render_block(token, tokens, idx, seen_slugs, first_h1_consumed_ref, run_button=False, line_numbers=False, code_icons='colorful')Dispatch a single block token to its HTML renderer.
Returns the HTML string, or None if the token produces no output (e.g. BlankLine, or the first H1).
#md_to_html
def md_to_html(text, metadata=None, config=None)Convert Markdown text to HTML.
Handles: headings, code blocks (with tabs and annotations), inline code, paragraphs, unordered lists, ordered lists, links, bold, italic, tables.
Args:
text: Markdown source text.metadata: Per-page frontmatter dict (optional). Keysauto_steps
and auto_api (bool) override the corresponding global settings from config.
config: Project config dict (optional). Theauto_detectkey
(an object with optional bool keys steps and api_entries) controls whether heuristics run globally. Per-page metadata takes precedence over global config.
#_render_code_block
def _render_code_block(lang, code_lines, annotations=None, run=False, line_numbers=False, line_start=1, code_icons='colorful')Render a single fenced code block to HTML.
Handles diff highlighting (Feature 27), inline code annotations (Feature 32), build-time syntax highlighting via Pygments (Wave 3 Phase 0), optional line numbers, and language icons.
#_group_code_tabs
def _group_code_tabs(html)Group consecutive code blocks into a tabbed interface (Feature 31).
Detects runs of consecutive
#_apply_step_guides
def _apply_step_guides(html)Add class="steps" to
- elements that follow step/guide/tutorial headings (Feature 33).
- Only wraps when the heading text looks like an identifier (snake_case,
- Only wraps when the code block is short (at most 2 newlines / 3 lines),
Uses a two-pass approach: finds each
- without a class, then searches backward (up to 200 characters) for an h2/h3 whose plain text starts with "step", "guide", or "tutorial" (case-insensitive). If found with no intervening h2/h3 between the match and the
- , adds class="steps".
#_wrap_api_entries
def _wrap_api_entries(html)Wrap h3/h4 + code block + description paragraph in API entry cards (Feature 48).
When an h3 or h4 heading is followed by a code-block div (a function/type signature) and a
(description), with optional whitespace/newlines between them, wrap them together in a
Guards:
camelCase, PascalCase, dotted.method), not natural-language headings.
indicating a signature rather than example code.
#_apply_definitions
def _apply_definitions(html)Wrap definitional subjects in tags when they follow headings.
Detects patterns like "X is a ...", "X refers to ...", "X means ...", "X represents ...", or the inverted "A/An X is ..." in the first
after an
or heading, and wraps X in . #_split_table_cells
pythondef _split_table_cells(line)
Split a markdown table line by unescaped pipes, unescaping \| in cells.
#_parse_table
pythondef _parse_table(table_lines)
Parse markdown table lines into an HTML
#_split_table_cells
def _split_table_cells(line)Split a markdown table line by unescaped pipes, unescaping \| in cells.
#_parse_table
def _parse_table(table_lines)Parse markdown table lines into an HTML