Label

The Label tag to reference captions and other labels.

class disseminate.tags.label.LabelAnchor(*args, content, **kwargs)

Bases: disseminate.tags.tag.Tag

The label anchor.

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).

class disseminate.tags.label.LabelMixin(*args, **kwargs)

Bases: object

A mixin class for working with LabelTags LabelAnchors.

This mixing works in coordination with the Tag base class. The constructor (__init__) of this class should be run after the Tag base class’s constructor.

create_label()

Create the label in the label_manager for this tag.

generate_label_id()

Generate the label_id to use in creating the label.

Override this function to customize the generation of the label_id.

Returns
label_idstr

The generated label_id.

generate_label_kind()

Generate the kind tuple for the created label.

Override this function to customize the generation of the label kind.

Returns
kindTuple[str]

A tuple of strings for the kind of label. ex: (‘heading’, ‘chapter’)

class disseminate.tags.label.LabelTag(name, attributes, content, context, **kwargs)

Bases: disseminate.tags.tag.Tag

The name portion of a label.

ex: Chap. 1.2 or Fig. 1.

Parameters
contentstr

The label_id of an existing label.

kindTuple[str]

The kind of the label is a tuple that identified the kind of a label from least specific to most specific. ex: (‘figure’,), (‘chapter’,), (‘equation’,), (‘heading’, ‘h1’,) See LabelManager.format_string

prepend_idOptional[str]

If specified, the label id (identifier) will have this string prepended to it.

(see the :class:`Tag <disseminate.tags.tag.Tag>` base class for details

on the other parameters)

default_fmt(content=None, attributes=None)

Convert the tag to a text string.

Strips the tag information and simply return the content of the tag.

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.

Returns
text_stringstr

A text string with the tags stripped.

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).

process_content = False

Do not convert typography characters. Conversion of typography characters might cause issues with matching the label id.

tex_fmt(content=None, attributes=None, mathmode=False, level=1)

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.

xhtml_fmt(format_func='xhtml_fmt', method='xhtml', **kwargs)

Convert the tag to an xhtml string or html element.

Returns
xhtmlstr or xhtml element

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

disseminate.tags.label.create_label(tag, kind, label_id=None)

Create a label in the label_manager for the given tag.

Note

This function does not create a LabelTag. Only a Label object through the document’s :obj:<LabelManager <disseminate.labels.label_manager.LabelManager>`

Parameters
tagTag

The tag creating the label.

kindTuple[str]

The kind of label. ex: (‘heading’, ‘section’)

label_idOptional[str]

The identifier for the label to create. If None is specified, the generate_label_id function will be used.

Returns
label_idUnion[str, None]

The label_id of the created label, if successful. None if a label could not be created.

disseminate.tags.label.generate_label_id(tag)

Generate a label_id string for the given tag.

Parameters
tagTag

The tag creating the label.

Returns
label_idstr

The label id string for the tag.