linuxdoc.kfigure module¶
scalable figure and image handling¶
Sphinx extension which implements scalable image handling. User documentation see Scalable figure and image handling
- class linuxdoc.kfigure.KernelFigure(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Bases:
Figure
KernelImage directive
Earns everything from
.. figure::
directive, except remote URI and glob pattern. The KernelFigure wraps a figure node into a kernel_figure node. Seevisit_kernel_figure
.
- class linuxdoc.kfigure.KernelImage(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Bases:
Image
KernelImage directive
Earns everything from
.. image::
directive, except remote URI and glob pattern. The KernelImage wraps a image node into a kernel_image node. Seevisit_kernel_image
.
- class linuxdoc.kfigure.KernelRender(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Bases:
Figure
KernelRender directive
Render content by external tool. Has all the options known from the figure directive, plus option
caption
. Ifcaption
has a value, a figure node with the caption is inserted. If not, a image node is inserted.The KernelRender directive wraps the text of the directive into a literal_block node and wraps it into a kernel_render node. See
visit_kernel_render
.- final_argument_whitespace = False¶
May the final argument contain whitespace?
- has_content = True¶
May the directive have content?
- option_spec = {'align': <function Figure.align>, 'alt': <function unchanged>, 'caption': <function unchanged>, 'class': <function class_option>, 'figclass': <function class_option>, 'figwidth': <function Figure.figwidth_value>, 'height': <function length_or_unitless>, 'loading': <function Image.loading>, 'name': <function unchanged>, 'scale': <function percentage>, 'target': <function unchanged_required>, 'width': <function length_or_percentage_or_unitless>}¶
Mapping of option names to validator functions.
- optional_arguments = 0¶
Number of optional arguments after the required arguments.
- required_arguments = 1¶
Number of required directive arguments.
- linuxdoc.kfigure.add_kernel_figure_to_std_domain(app, doctree)[source]¶
Add kernel-figure anchors to ‘std’ domain.
The
StandardDomain.process_doc(..)
method does not know how to resolve the caption (label) ofkernel-figure
directive (it only knows about standard nodes, e.g. table, figure etc.). Without any additional handling this will result in a ‘undefined label’ for kernel-figures.This handle adds labels of kernel-figure to the ‘std’ domain labels.
- linuxdoc.kfigure.convert_image(img_node, translator, src_fname=None)[source]¶
Convert a image node for the builder.
Different builder prefer different image formats, e.g. latex builder prefer PDF while html builder prefer SVG format for images.
This function handles output image formats in dependence of source the format (of the image) and the translator’s output format.
- linuxdoc.kfigure.dot2format(app, dot_fname, out_fname)[source]¶
Converts DOT file to
out_fname
usingdot(1)
.dot_fname
pathname of the input DOT file, including extension.dot
out_fname
pathname of the output file, including format extension
The format extension depends on the
dot
command (seeman dot
option-Txxx
). Normally you will use one of the following extensions:.ps
for PostScript,.svg
orsvgz
for Structured Vector Graphics,.fig
for XFIG graphics and.png
orgif
for common bitmap graphics.
- linuxdoc.kfigure.isNewer(path1, path2)[source]¶
Returns True if
path1
is newer thanpath2
If
path1
exists and is newer thanpath2
the function returnsTrue
is returned otherwiseFalse
- class linuxdoc.kfigure.kernel_figure(rawsource='', *children, **attributes)[source]¶
Bases:
figure
Node for
kernel-figure
directive.
- class linuxdoc.kfigure.kernel_image(rawsource='', *children, **attributes)[source]¶
Bases:
image
Node for
kernel-image
directive.
- class linuxdoc.kfigure.kernel_render(rawsource='', *children, **attributes)[source]¶
Bases:
General
,Inline
,Element
Node for
kernel-render
directive.
- linuxdoc.kfigure.setupTools(app)[source]¶
Check available build tools and log some verbose messages.
This function is called once, when the builder is initiated.
- linuxdoc.kfigure.svg2pdf(app, svg_fname, pdf_fname)[source]¶
Converts SVG to PDF with
convert(1)
command.Uses
convert(1)
from ImageMagick (https://www.imagemagick.org) for conversion. ReturnsTrue
on success andFalse
if an error occurred.svg_fname
pathname of the input SVG file with extension (.svg
)pdf_name
pathname of the output PDF file with extension (.pdf
)
- linuxdoc.kfigure.visit_kernel_figure(self, node)[source]¶
Visitor of the
kernel_figure
Node.Handles the
image
child-node with theconvert_image(...)
.
- linuxdoc.kfigure.visit_kernel_image(self, node)[source]¶
Visitor of the
kernel_image
Node.Handles the
image
child-node with theconvert_image(...)
.
- linuxdoc.kfigure.visit_kernel_render(self, node)[source]¶
Visitor of the
kernel_render
Node.If rendering tools available, save the markup of the
literal_block
child node into a file and replace theliteral_block
node with a new createdimage
node, pointing to the saved markup file. Afterwards, handle the image child-node with theconvert_image(...)
.