Module

rendering.plugins.directives.checklist

Checklist directive for Mistune.

Provides styled checklist containers for bullet lists and task lists with optional titles and custom styling.

Architecture:

Migrated to BengalDirective base class as part of directive system v2.

Syntax (preferred - named closers): :::{checklist} Prerequisites :style: numbered :show-progress:

  • [x] Python 3.14+
  • [x] Bengal installed
  • [ ] Git configured :::{/checklist}

Options:

:style: - Visual style (default, numbered)
:show-progress: - Display completion percentage for task lists
:compact: - Tighter spacing for dense lists

Classes

ChecklistOptions dataclass
Options for checklist directive.
0

Options for checklist directive.

Inherits from DirectiveOptions

Attributes

Name Type Description
style str

Visual style (default, numbered)

show_progress bool

Display completion percentage for task lists

compact bool

Tighter spacing for dense lists

css_class str

Additional CSS classes

_field_aliases ClassVar[dict[str, str]]
_allowed_values ClassVar[dict[str, list[str]]]
ChecklistDirective
Checklist directive using Mistune's fenced syntax. Syntax: :::{checklist} Optional Title :…
5

Checklist directive using Mistune's fenced syntax.

Syntax:

:::{checklist} Optional Title
:style: numbered
:show-progress:
:compact:
  • Item one
  • Item two
  • [x] Completed item
  • [ ] Unchecked item :::{/checklist}

Options:

:style: - Visual style
  • default: Standard bullet list styling
  • numbered: Ordered list with numbers :show-progress: - Show completion bar for task lists :compact: - Tighter spacing between items

Supports both regular bullet lists and task lists (checkboxes). The directive wraps the list in a styled container.

Inherits from BengalDirective

Attributes

Name Type Description
NAMES ClassVar[list[str]]
TOKEN_TYPE ClassVar[str]
OPTIONS_CLASS ClassVar[type[DirectiveOptions]]
DIRECTIVE_NAMES ClassVar[list[str]]

Methods 2

parse_directive
Build checklist token.
5 DirectiveToken
def parse_directive(self, title: str, options: ChecklistOptions, content: str, children: list[Any], state: Any) -> DirectiveToken

Build checklist token.

Parameters 5
title str
options ChecklistOptions
content str
children list[Any]
state Any
Returns

DirectiveToken

render
Render checklist to HTML.
2 str
def render(self, renderer: Any, text: str, **attrs: Any) -> str

Render checklist to HTML.

Parameters 2
renderer Any
text str
Returns

str

Internal Methods 3
_make_checkboxes_interactive
Remove 'disabled' attribute from checkboxes to allow interaction. Mistune's ta…
1 str
def _make_checkboxes_interactive(self, html_content: str) -> str

Remove 'disabled' attribute from checkboxes to allow interaction.

Mistune's task_lists plugin adds 'disabled' by default. We remove it for checklist directives to enable interactive checklists.

Parameters 1
html_content str
Returns

str

_render_progress_script
Render JavaScript for interactive progress bar updates. When a checkbox is tog…
0 str
def _render_progress_script(self) -> str

Render JavaScript for interactive progress bar updates.

When a checkbox is toggled, updates the progress bar and text.

Returns

str

_render_progress_bar
Calculate and render progress bar from checkbox states. Counts checked vs unch…
1 str
def _render_progress_bar(self, html_content: str) -> str

Calculate and render progress bar from checkbox states.

Counts checked vs unchecked checkboxes in the rendered HTML. Returns empty string if no checkboxes found.

Parameters 1
html_content str
Returns

str

Functions

render_checklist
Legacy render function for backward compatibility.
2 str
def render_checklist(renderer: Any, text: str, **attrs: Any) -> str

Legacy render function for backward compatibility.

Parameters 2

Name Type Default Description
renderer Any
text str

Returns

str