List

Tags for lists.

class disseminate.tags.list.List(name, content, attributes, context, **kwargs)

Bases: disseminate.tags.tag.Tag

A tag for lists

html_fmt(content=None, attributes=None, format_func='html_fmt', method='html', level=1, **kwargs)

Convert the tag to an html string or html element.

Parameters
contentOptional[Union[str, List[Union[str, list, Tag]]]

Specify an alternative content from the tag’s content. It can either be a string, a tag or a list of strings, tags and lists.

attributesOptional[Union[str, Attributes]]

Specify an alternative attributes dict from the tag’s attributes. It can either be a string or an attributes dict.

format_funcOptional[str]

The format function to use with by formatted_content when formatting sub-tags.

methodOptional[str]

The rendering method for the string. ex: ‘html’ or ‘xml’

levelOptional[int]

The level of the tag.

Returns
htmlstr or html element

A string in HTML format or an HTML element (lxml.builder.E).

tex_fmt(attributes=None, **kwargs)

Format the tag in LaTeX format.

Parameters
contentOptional[Union[str, List[Union[str, list, Tag]]]

Specify an alternative content from the tag’s content. It can either be a string, a tag or a list of strings, tags and lists.

attributesOptional[Union[str, Attributes]]

Specify an alternative attributes dict from the tag’s attributes. It can either be a string or an attributes dict.

mathmodeOptional[bool]

If True, the tag will be rendered in math mode. Otherwise (default) latex text mode is assumed.

levelOptional[int]

The level of the tag.

Returns
tex_stringstr

The formatted tex string.

class disseminate.tags.list.ListItem(*args, **kwargs)

Bases: disseminate.tags.tag.Tag

An item in a list

tex_fmt(**kwargs)

Format the tag in LaTeX format.

Parameters
contentOptional[Union[str, List[Union[str, list, Tag]]]

Specify an alternative content from the tag’s content. It can either be a string, a tag or a list of strings, tags and lists.

attributesOptional[Union[str, Attributes]]

Specify an alternative attributes dict from the tag’s attributes. It can either be a string or an attributes dict.

mathmodeOptional[bool]

If True, the tag will be rendered in math mode. Otherwise (default) latex text mode is assumed.

levelOptional[int]

The level of the tag.

Returns
tex_stringstr

The formatted tex string.

class disseminate.tags.list.OrderedList(name, content, attributes, context, **kwargs)

Bases: disseminate.tags.list.List

A tag for ordered lists

disseminate.tags.list.clean_string_list(parsed_list)

Clean the string list created by parse_string_list.

Cleaning include removeing extra spaces and newlines in parse string line elements.

Parameters
parsed_listList[Tuple[int, str]]

The parsed list from parse_string_list.

Returns
cleaned_listList[Tuple[int, str]]

The cleaned list.

>>> l = parse_string_list("- This is my first item.\n"
    ..
… ” - This is my first subitemn”)
>>> clean_string_list(l)
    ..
[(0, ‘This is my first item.’), (2, ‘This is my first subitem’)]
disseminate.tags.list.normalize_levels(parsed_list, list_level_spaces=2)

Normalize the levels from a parse_list so that the first level is 0, and subsequent levels are properly incremented.

Parameters
parsed_listList[Tuple[int, str]]

The parsed list from parse_string_list.

list_level_spacesint

The number of spaces used to identify sub-levels in a list.

Returns
normalized_listList[Tuple[int, str]]

The normalized list with levels fixed.

>>> l = parse_string_list("- This is my first item.\n"
    ..
… ” - This is my first subitemn”)
>>> normalize_levels(l)
    ..
[(0, ‘This is my first item.’), (1, ‘This is my first subitem’)]
disseminate.tags.list.parse_list(content, context)

Parse lists (and sublists) from a string or list of content.

Parameters
contentUnion[str, List[Union[str, list, Tag], Tag]

The contents of the tag. It can either be a string, a tag or a list of strings, tags and lists.

contextdocument.DocumentContext

The document’s context dict.

Returns
returned_listlist

The list of parse list items, to be used for the content of a list.

disseminate.tags.list.parse_string_list(s)

Parse a string with lists.

Parameters
sstr

The string to parse

Returns
parsed_listList[Tuple[int, str]]

Examples

>>> parse_string_list("- This is my first item.\n"
...                   "  - This is my first subitem\n")
[(0, 'This is my first item.'), (2, 'This is my first subitem')]