docutils.writers.odf_odt package
Open Document Format (ODF) Writer.
This module is provisional: the API is not settled and may change with any minor Docutils version.
- Element(tag, attrib=None, nsmap=None, nsdict={'chart': 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0', 'dc': 'http://purl.org/dc/elements/1.1/', 'dom': 'http://www.w3.org/2001/xml-events', 'dr3d': 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0', 'draw': 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0', 'fo': 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0', 'form': 'urn:oasis:names:tc:opendocument:xmlns:form:1.0', 'math': 'http://www.w3.org/1998/Math/MathML', 'meta': 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0', 'number': 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0', 'office': 'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'ooo': 'http://openoffice.org/2004/office', 'oooc': 'http://openoffice.org/2004/calc', 'ooow': 'http://openoffice.org/2004/writer', 'presentation': 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0', 'script': 'urn:oasis:names:tc:opendocument:xmlns:script:1.0', 'style': 'urn:oasis:names:tc:opendocument:xmlns:style:1.0', 'svg': 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0', 'table': 'urn:oasis:names:tc:opendocument:xmlns:table:1.0', 'text': 'urn:oasis:names:tc:opendocument:xmlns:text:1.0', 'xforms': 'http://www.w3.org/2002/xforms', 'xlink': 'http://www.w3.org/1999/xlink', 'xsd': 'http://www.w3.org/2001/XMLSchema', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'})[source]
- SubElement(parent, tag, attrib=None, nsmap=None, nsdict={'chart': 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0', 'dc': 'http://purl.org/dc/elements/1.1/', 'dom': 'http://www.w3.org/2001/xml-events', 'dr3d': 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0', 'draw': 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0', 'fo': 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0', 'form': 'urn:oasis:names:tc:opendocument:xmlns:form:1.0', 'math': 'http://www.w3.org/1998/Math/MathML', 'meta': 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0', 'number': 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0', 'office': 'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'ooo': 'http://openoffice.org/2004/office', 'oooc': 'http://openoffice.org/2004/calc', 'ooow': 'http://openoffice.org/2004/writer', 'presentation': 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0', 'script': 'urn:oasis:names:tc:opendocument:xmlns:script:1.0', 'style': 'urn:oasis:names:tc:opendocument:xmlns:style:1.0', 'svg': 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0', 'table': 'urn:oasis:names:tc:opendocument:xmlns:table:1.0', 'text': 'urn:oasis:names:tc:opendocument:xmlns:text:1.0', 'xforms': 'http://www.w3.org/2002/xforms', 'xlink': 'http://www.w3.org/1999/xlink', 'xsd': 'http://www.w3.org/2001/XMLSchema', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'})[source]
- add_ns(tag, nsdict={'chart': 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0', 'dc': 'http://purl.org/dc/elements/1.1/', 'dom': 'http://www.w3.org/2001/xml-events', 'dr3d': 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0', 'draw': 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0', 'fo': 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0', 'form': 'urn:oasis:names:tc:opendocument:xmlns:form:1.0', 'math': 'http://www.w3.org/1998/Math/MathML', 'meta': 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0', 'number': 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0', 'office': 'urn:oasis:names:tc:opendocument:xmlns:office:1.0', 'ooo': 'http://openoffice.org/2004/office', 'oooc': 'http://openoffice.org/2004/calc', 'ooow': 'http://openoffice.org/2004/writer', 'presentation': 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0', 'script': 'urn:oasis:names:tc:opendocument:xmlns:script:1.0', 'style': 'urn:oasis:names:tc:opendocument:xmlns:style:1.0', 'svg': 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0', 'table': 'urn:oasis:names:tc:opendocument:xmlns:table:1.0', 'text': 'urn:oasis:names:tc:opendocument:xmlns:text:1.0', 'xforms': 'http://www.w3.org/2002/xforms', 'xlink': 'http://www.w3.org/1999/xlink', 'xsd': 'http://www.w3.org/2001/XMLSchema', 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'})[source]
- class TableStyle(border=None, backgroundcolor=None)[source]
Bases:
object- property border
- property backgroundcolor
- class Writer[source]
Bases:
Writer- MIME_TYPE = 'application/vnd.oasis.opendocument.text'
- EXTENSION = '.odt'
- supported = ('odt',)
Formats this writer supports.
- default_stylesheet = 'styles.odt'
- default_stylesheet_path = '../../../../envs/latest/lib/python3.12/site-packages/docutils/writers/odf_odt/styles.odt'
- default_template = 'template.txt'
- default_template_path = '../../../../envs/latest/lib/python3.12/site-packages/docutils/writers/odf_odt/template.txt'
- settings_spec = ('ODF-Specific Options', None, (('Specify a stylesheet. Default: "../../../../envs/latest/lib/python3.12/site-packages/docutils/writers/odf_odt/styles.odt"', ['--stylesheet'], {'default': '../../../../envs/latest/lib/python3.12/site-packages/docutils/writers/odf_odt/styles.odt', 'dest': 'stylesheet'}), ('Specify a configuration/mapping file relative to the current working directory for additional ODF options. In particular, this file may contain a section named "Formats" that maps default style names to names to be used in the resulting output file allowing for adhering to external standards. For more info and the format of the configuration/mapping file, see the odtwriter doc.', ['--odf-config-file'], {'metavar': '<file>'}), ('Obfuscate email addresses to confuse harvesters while still keeping email links usable with standards-compliant browsers.', ['--cloak-email-addresses'], {'action': 'store_true', 'default': False, 'dest': 'cloak_email_addresses', 'validator': <function validate_boolean>}), ('Do not obfuscate email addresses.', ['--no-cloak-email-addresses'], {'action': 'store_false', 'default': False, 'dest': 'cloak_email_addresses', 'validator': <function validate_boolean>}), ('Specify the thickness of table borders in thousands of a cm. Default is 35.', ['--table-border-thickness'], {'default': None, 'validator': <function validate_nonnegative_int>}), ('Add syntax highlighting in literal code blocks.', ['--add-syntax-highlighting'], {'action': 'store_true', 'default': False, 'dest': 'add_syntax_highlighting', 'validator': <function validate_boolean>}), ('Do not add syntax highlighting in literal code blocks. (default)', ['--no-syntax-highlighting'], {'action': 'store_false', 'default': False, 'dest': 'add_syntax_highlighting', 'validator': <function validate_boolean>}), ('Create sections for headers. (default)', ['--create-sections'], {'action': 'store_true', 'default': True, 'dest': 'create_sections', 'validator': <function validate_boolean>}), ('Do not create sections for headers.', ['--no-sections'], {'action': 'store_false', 'default': True, 'dest': 'create_sections', 'validator': <function validate_boolean>}), ('Create links.', ['--create-links'], {'action': 'store_true', 'default': False, 'dest': 'create_links', 'validator': <function validate_boolean>}), ('Do not create links. (default)', ['--no-links'], {'action': 'store_false', 'default': False, 'dest': 'create_links', 'validator': <function validate_boolean>}), ('Generate endnotes at end of document, not footnotes at bottom of page.', ['--endnotes-end-doc'], {'action': 'store_true', 'default': False, 'dest': 'endnotes_end_doc', 'validator': <function validate_boolean>}), ('Generate footnotes at bottom of page, not endnotes at end of document. (default)', ['--no-endnotes-end-doc'], {'action': 'store_false', 'default': False, 'dest': 'endnotes_end_doc', 'validator': <function validate_boolean>}), ('Generate a bullet list table of contents, not an ODF/oowriter table of contents.', ['--generate-list-toc'], {'action': 'store_false', 'default': True, 'dest': 'generate_oowriter_toc', 'validator': <function validate_boolean>}), ('Generate an ODF/oowriter table of contents, not a bullet list. (default)', ['--generate-oowriter-toc'], {'action': 'store_true', 'default': True, 'dest': 'generate_oowriter_toc', 'validator': <function validate_boolean>}), ('Specify the contents of an custom header line. See odf_odt writer documentation for details about special field character sequences.', ['--custom-odt-header'], {'default': '', 'dest': 'custom_header'}), ('Specify the contents of an custom footer line. See odf_odt writer documentation for details about special field character sequences.', ['--custom-odt-footer'], {'default': '', 'dest': 'custom_footer'})))
Runtime settings specification. Override in subclasses.
Defines runtime settings and associated command-line options, as used by docutils.frontend.OptionParser. This is a tuple of:
Option group title (string or None which implies no group, just a list of single options).
Description (string or None).
A sequence of option tuples. Each consists of:
Help text (string)
List of option strings (e.g.
['-Q', '--quux']).Dictionary of keyword arguments sent to the OptionParser/OptionGroup
add_optionmethod.Runtime setting names are derived implicitly from long option names (’–a-setting’ becomes
settings.a_setting) or explicitly from the ‘dest’ keyword argument.Most settings will also have a ‘validator’ keyword & function. The validator function validates setting values (from configuration files and command-line option arguments) and converts them to appropriate types. For example, the
docutils.frontend.validate_booleanfunction, required by all boolean settings, converts true values (‘1’, ‘on’, ‘yes’, and ‘true’) to 1 and false values (‘0’, ‘off’, ‘no’, ‘false’, and ‘’) to 0. Validators need only be set once per setting. See the docutils.frontend.validate_* functions.See the optparse docs for more details.
More triples of group title, description, options, as many times as needed. Thus, settings_spec tuples can be simply concatenated.
- settings_defaults = {'output_encoding_error_handler': 'xmlcharrefreplace'}
A dictionary of defaults for settings not in settings_spec (internal settings, intended to be inaccessible by command-line and config file). Override in subclasses.
- relative_path_settings = ('stylesheet_path',)
Settings containing filesystem paths. Override in subclasses. Settings listed here are to be interpreted relative to the current working directory.
- config_section = 'odf_odt writer'
The name of the config file section specific to this component (lowercase, no brackets). Override in subclasses.
- config_section_dependencies = ('writers',)
A list of names of config file sections that are to be applied before config_section, in order (from general to specific). In other words, the settings in config_section are to be overlaid on top of the settings from these sections. The “general” section is assumed implicitly. Override in subclasses.
- translate()[source]
Do final translation of self.document into self.output. Called from write. Override in subclasses.
Usually done with a docutils.nodes.NodeVisitor subclass, in combination with a call to docutils.nodes.Node.walk() or docutils.nodes.Node.walkabout(). The
NodeVisitorsubclass must support all standard elements (listed in docutils.nodes.node_class_names) and possibly non-standard elements used by the current Reader as well.
- update_stylesheet(stylesheet_root, language_code, region_code)[source]
Update xml style sheet element with language and region/country.
- copy_from_stylesheet(outzipfile)[source]
Copy images, settings, etc from the stylesheet doc into target doc.
- assemble_parts()[source]
Assemble the self.parts dictionary. Extend in subclasses.
See <https://docutils.sourceforge.io/docs/api/publisher.html>.
- class ODFTranslator(document)[source]
Bases:
GenericNodeVisitor- used_styles = ('attribution', 'blockindent', 'blockquote', 'blockquote-bulletitem', 'blockquote-bulletlist', 'blockquote-enumitem', 'blockquote-enumlist', 'bulletitem', 'bulletlist', 'caption', 'legend', 'centeredtextbody', 'codeblock', 'codeblock-indented', 'codeblock-classname', 'codeblock-comment', 'codeblock-functionname', 'codeblock-keyword', 'codeblock-name', 'codeblock-number', 'codeblock-operator', 'codeblock-string', 'emphasis', 'enumitem', 'enumlist', 'epigraph', 'epigraph-bulletitem', 'epigraph-bulletlist', 'epigraph-enumitem', 'epigraph-enumlist', 'footer', 'footnote', 'citation', 'header', 'highlights', 'highlights-bulletitem', 'highlights-bulletlist', 'highlights-enumitem', 'highlights-enumlist', 'horizontalline', 'inlineliteral', 'quotation', 'rubric', 'strong', 'table-title', 'textbody', 'tocbulletlist', 'tocenumlist', 'title', 'subtitle', 'heading1', 'heading2', 'heading3', 'heading4', 'heading5', 'heading6', 'heading7', 'admon-attention-hdr', 'admon-attention-body', 'admon-caution-hdr', 'admon-caution-body', 'admon-danger-hdr', 'admon-danger-body', 'admon-error-hdr', 'admon-error-body', 'admon-generic-hdr', 'admon-generic-body', 'admon-hint-hdr', 'admon-hint-body', 'admon-important-hdr', 'admon-important-body', 'admon-note-hdr', 'admon-note-body', 'admon-tip-hdr', 'admon-tip-body', 'admon-warning-hdr', 'admon-warning-body', 'tableoption', 'tableoption.%c', 'tableoption.%c%d', 'Table%d', 'Table%d.%c', 'Table%d.%c%d', 'lineblock1', 'lineblock2', 'lineblock3', 'lineblock4', 'lineblock5', 'lineblock6', 'image', 'figureframe')
- retrieve_styles(extension)[source]
Retrieve the stylesheet from either a .xml file or from a .odt (zip) file. Return the content as a string.
- attach_page_style(el)[source]
Attach the default page style.
Create an automatic-style that refers to the current style of this element and that refers to the default page style.
- rststyle(name, parameters=())[source]
Returns the style name to use for the given style.
If parameters is given name must contain a matching number of
%and is used as a format expression with parameters as the value.
- code_none = 0
- code_field = 1
- code_text = 2
- field_pat = re.compile('%(..?)%')
- footnote_chars = ['*', '**', '***', '++', '+++', '##', '###', '@@', '@@@']
- convert_to_cm(size)[source]
Convert various units to centimeters.
- Note that a call to this method should be wrapped in:
try: except ValueError:
- get_image_scaled_width_height(node, source)[source]
Return the image size in centimeters adjusted by image attrs.
- visit_doctest_block(node)
- depart_doctest_block(node)
- depart_attention(node)
- depart_caution(node)
- depart_danger(node)
- depart_error(node)
- depart_hint(node)
- depart_important(node)
- depart_note(node)
- depart_tip(node)
- depart_admonition(node)