selfdoc v0.15.1 /selfdoc.js.loader
On this page

JavaScript file loader module that reads and assembles JS source files from the selfdoc.js package using importlib.resources for theme and search scripts.

#selfdoc.js.loader

#selfdoc.js.loader

Loader for selfdoc JS files using importlib.resources.

#load_js

python
def load_js(name: str) -> str

Load a .js file from the selfdoc.js package.

Args:

  • name: Filename without extension (e.g. "theme-toggle").

Returns:

  • The JavaScript source as a string.

#load_search_js

python
def load_search_js(engine: str='builtin') -> str

Compose search JS from engine implementation + dialog UI.

The engine must be one of "builtin", "fuse", or "minisearch". Falls back to "builtin" if the engine name is unrecognized.

Returns:

  • Combined JS string (engine + dialog).

#assemble_body_js

python
def assemble_body_js(body_html: str, toc_html: str, footer_html: str, search_engine: str | None=None) -> str

Assemble the body JS blocks based on page content.

Always includes: theme-toggle, sidebar, nav-groups, scroll-affordance, reading-progress. Conditionally includes blocks based on what HTML content is present on the page. Smooth-scroll restore is always appended last.

Args:

  • body_html: The article body HTML.
  • toc_html: The table-of-contents HTML (empty string if none).
  • footer_html: The page footer HTML.
  • search_engine: Search engine name (unused here, kept for API).

Returns:

  • Concatenated JS string (not yet minified).