Img

Image tags

class disseminate.tags.img.Img(*args, **kwargs)

Bases: disseminate.tags.tag.Tag

The img tag for inserting images.

When rendering to a target document format, this tag may use a converter, the attributes and context of this tag to convert the infile to an outfile in a needed format.

Attributes
activebool

If True, the Tag can be used by the TagFactory.

html_namestr

If specified, use this name when rendering the tag to html. Otherwise, use name.

in_extOptional[str]

Used to correctly identify the builder to add if the contents need to be rendered first.

img_filepathstr

The path for the (source) image.

add_file(target, content=None, attributes=None, context=None)

Convert and add the file dependency for the specified document target.

Parameters
targetstr

The document target format. ex: ‘.html’, ‘.tex’

contentOptional[Union[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.

attributesOptional[Union[str, Attributes]]

The attributes of the tag.

contextOptional[Type[BaseContext]]

The context with values for the document.

Returns
outfilepathpaths.TargetPath

The filepath for the file in the target document directory.

Raises
ImgFileNotFound

Raises an ImgFileNotFound exception if a filepath couldn’t be found in the tag contents.

BuildError

If a builder could not be found for the builder

content_as_filepath(content=None, context=None)

Returns a filepath from the content, if it’s a valid filepath, or returns None if it isn’t.

Parameters
contentOptional[Union[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.

contextOptional[Type[BaseContext]]

The context with values for the document.

Returns
filepathUnion[pathlib.Path. None]

The filepath, if found, or None if a valid filepath was not found.

html_fmt(content=None, attributes=None, context=None, method='html', **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(content=None, attributes=None, context=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.

exception disseminate.tags.img.ImgFileNotFound

Bases: disseminate.tags.exceptions.TagError

The image file was not found.