duck.html.components.table_of_contents¶
Table of Contents HTML Component.
This module defines two components:
TableOfContentsSection- Represents a content section with a heading and body.TableOfContents- Generates a navigable table of contents.
Each TableOfContentsSection is added to the TableOfContents component, which
automatically creates a clickable list of links for navigation.
Module Contents¶
Classes¶
Table of Contents Component. |
|
Represents a section in the Table of Contents. |
API¶
- class duck.html.components.table_of_contents.TableOfContents(element: Optional[str] = None, properties: Optional[Dict[str, str]] = None, props: Optional[Dict[str, str]] = None, style: Optional[Dict[str, str]] = None, inner_html: Optional[Union[str, str, float]] = None, children: Optional[List[duck.html.components.HtmlComponent]] = None, **kwargs)[source]¶
Bases:
duck.html.components.container.FlexContainerTable of Contents Component.
This component generates a navigable list of links to
TableOfContentsSectioninstances.- Parameters:
title – The title displayed at the top of the Table of Contents. Defaults to “Table of Contents”.
Initialization
Initialize an HTML component.
- Parameters:
element – The HTML element tag name (e.g., textarea, input, button). Can be None, but make sure element is returned by get_element method.
accept_inner_html – Whether the HTML component accepts an inner body (e.g., inner-body-here).
inner_html – Inner html to add to the HTML component. Defaults to None.
properties – Dictionary for properties to initialize the component with.
props – Just same as properties argument (added for simplicity).
style – Dictionary for style to initialize the component with.
**kwargs – Extra keyword arguments
- Raises:
HtmlComponentError – If ‘element’ is not a string or ‘inner_html’ is set but ‘accept_inner_html’ is False.
- add_child(child: duck.html.components.table_of_contents.TableOfContentsSection, list_style: str = 'circle')[source]¶
Adds a
TableOfContentsSectionto the Table of Contents.This method also creates a clickable link for the section heading.
Args: section (TableOfContentsSection): The section to add. list_style (str): The CSS list-style type for the navigation items. Defaults to “circle”.
- add_section(section: duck.html.components.table_of_contents.TableOfContentsSection, list_style: str = 'circle')[source]¶
Adds a
TableOfContentsSectionto the Table of Contents.This method also creates a clickable link for the section heading.
- Parameters:
section – The section to add.
list_style – The CSS list-style type for the navigation items. Defaults to “circle”.
- class duck.html.components.table_of_contents.TableOfContentsSection(element: Optional[str] = None, properties: Optional[Dict[str, str]] = None, props: Optional[Dict[str, str]] = None, style: Optional[Dict[str, str]] = None, inner_html: Optional[Union[str, str, float]] = None, children: Optional[List[duck.html.components.HtmlComponent]] = None, **kwargs)[source]¶
Bases:
duck.html.components.container.FlexContainerRepresents a section in the Table of Contents.
Each section consists of a heading (anchor link target) and body content.
Args:
heading(str): The heading of the section, which will be linked in the Table of Contents.body(str): The main content of the section, which can be plain text or HTML.
Initialization
Initialize an HTML component.
- Parameters:
element – The HTML element tag name (e.g., textarea, input, button). Can be None, but make sure element is returned by get_element method.
accept_inner_html – Whether the HTML component accepts an inner body (e.g., inner-body-here).
inner_html – Inner html to add to the HTML component. Defaults to None.
properties – Dictionary for properties to initialize the component with.
props – Just same as properties argument (added for simplicity).
style – Dictionary for style to initialize the component with.
**kwargs – Extra keyword arguments
- Raises:
HtmlComponentError – If ‘element’ is not a string or ‘inner_html’ is set but ‘accept_inner_html’ is False.