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.

class _ElementInterfaceWrapper(tag, attrib=None)[source]

Bases: Element

setparent(parent)[source]
getparent()[source]
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]
fix_ns(tag, attrib, nsdict)[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]
ToString(et)[source]
escape_cdata(text)[source]
class TableStyle(border=None, backgroundcolor=None)[source]

Bases: object

get_border_()[source]
set_border_(border)[source]
property border
get_backgroundcolor_()[source]
set_backgroundcolor_(backgroundcolor)[source]
property backgroundcolor
class ListLevel(level, sibling_level=True, nested_level=True)[source]

Bases: object

set_sibling(sibling_level)[source]
get_sibling()[source]
set_nested(nested_level)[source]
get_nested()[source]
set_level(level)[source]
get_level()[source]
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_option method.

      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_boolean function, 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 NodeVisitor subclass must support all standard elements (listed in docutils.nodes.node_class_names) and possibly non-standard elements used by the current Reader as well.

assemble_my_parts()[source]

Assemble the self.parts dictionary. Extend in subclasses.

update_stylesheet(stylesheet_root, language_code, region_code)[source]

Update xml style sheet element with language and region/country.

write_zip_str(zfile, name, bytes, compress_type=8)[source]
store_embedded_files(zfile)[source]
get_settings()[source]

modeled after get_stylesheet

get_stylesheet()[source]

Get the stylesheet from the visitor. Ask the visitor to setup the page.

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

create_manifest()[source]
create_meta()[source]
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')
get_str_stylesheet()[source]
retrieve_styles(extension)[source]

Retrieve the stylesheet from either a .xml file or from a .odt (zip) file. Return the content as a string.

extract_table_styles(styles_str)[source]
get_property(stylenode)[source]
add_doc_title()[source]
find_first_text_p(el)[source]

Search the generated doc and return the first <text:p> element.

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.

generate_content_element(root)[source]
setup_page()[source]
get_dom_stylesheet()[source]
setup_paper(root_el)[source]
code_none = 0
code_field = 1
code_text = 2
field_pat = re.compile('%(..?)%')
create_custom_headfoot(parent, text, style_name, automatic_styles)[source]
make_field_element(parent, text, style_name, automatic_styles)[source]
split_field_specifiers_iter(text)[source]
astext()[source]
content_astext()[source]
set_title(title)[source]
get_title()[source]
set_embedded_file_list(embedded_file_list)[source]
get_embedded_file_list()[source]
get_meta_dict()[source]
process_footnotes()[source]
append_child(tag, attrib=None, parent=None)[source]
append_p(style, text=None)[source]
append_pending_ids(el)[source]
set_current_element(el)[source]
set_to_parent()[source]
generate_labeled_block(node, label)[source]
generate_labeled_line(node, label)[source]
encode(text)[source]
dispatch_visit(node)[source]

Override to catch basic attributes which many nodes have.

handle_basic_atts(node)[source]
default_visit(node)[source]

Override for generic, uniform traversals.

default_departure(node)[source]

Override for generic, uniform traversals.

visit_Text(node)[source]
depart_Text(node)[source]
visit_address(node)[source]
depart_address(node)[source]
visit_author(node)[source]
depart_author(node)[source]
visit_authors(node)[source]
depart_authors(node)[source]
visit_contact(node)[source]
depart_contact(node)[source]
visit_date(node)[source]
depart_date(node)[source]
visit_organization(node)[source]
depart_organization(node)[source]
visit_status(node)[source]
depart_status(node)[source]
visit_revision(node)[source]
depart_revision(node)[source]
visit_version(node)[source]
depart_version(node)[source]
visit_attribution(node)[source]
depart_attribution(node)[source]
visit_block_quote(node)[source]
depart_block_quote(node)[source]
visit_bullet_list(node)[source]
depart_bullet_list(node)[source]
visit_caption(node)[source]
depart_caption(node)[source]
visit_comment(node)[source]
depart_comment(node)[source]
visit_compound(node)[source]
depart_compound(node)[source]
visit_container(node)[source]
depart_container(node)[source]
visit_decoration(node)[source]
depart_decoration(node)[source]
visit_definition_list(node)[source]
depart_definition_list(node)[source]
visit_definition_list_item(node)[source]
depart_definition_list_item(node)[source]
visit_term(node)[source]
depart_term(node)[source]
visit_definition(node)[source]
depart_definition(node)[source]
visit_classifier(node)[source]
depart_classifier(node)[source]
visit_document(node)[source]
depart_document(node)[source]
visit_docinfo(node)[source]
depart_docinfo(node)[source]
visit_emphasis(node)[source]
depart_emphasis(node)[source]
visit_enumerated_list(node)[source]
depart_enumerated_list(node)[source]
visit_list_item(node)[source]
depart_list_item(node)[source]
visit_header(node)[source]
depart_header(node)[source]
visit_field(node)[source]
depart_field(node)[source]
visit_field_list(node)[source]
depart_field_list(node)[source]
visit_field_name(node)[source]
depart_field_name(node)[source]
visit_field_body(node)[source]
depart_field_body(node)[source]
visit_figure(node)[source]
depart_figure(node)[source]
visit_footnote(node)[source]
depart_footnote(node)[source]
footnote_chars = ['*', '**', '***', '++', '+++', '##', '###', '@@', '@@@']
visit_footnote_reference(node)[source]
depart_footnote_reference(node)[source]
visit_citation(node)[source]
depart_citation(node)[source]
visit_citation_reference(node)[source]
depart_citation_reference(node)[source]
visit_label(node)[source]
depart_label(node)[source]
visit_generated(node)[source]
depart_generated(node)[source]
check_file_exists(path)[source]
visit_image(node)[source]
depart_image(node)[source]
get_image_width_height(node, attr)[source]
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_scale(node)[source]
get_image_scaled_width_height(node, source)[source]

Return the image size in centimeters adjusted by image attrs.

get_page_width()[source]

Return the document’s page width in centimeters.

generate_figure(node, source, destination, current_element)[source]
generate_image(node, source, destination, current_element, frame_attrs=None)[source]
is_in_table(node)[source]
visit_legend(node)[source]
depart_legend(node)[source]
visit_line_block(node)[source]
depart_line_block(node)[source]
visit_line(node)[source]
depart_line(node)[source]
visit_literal(node)[source]
depart_literal(node)[source]
visit_inline(node)[source]
depart_inline(node)[source]
_calculate_code_block_padding(line)[source]
_add_syntax_highlighting(insource, language)[source]
fill_line(line)[source]
fill_func1(matchobj)[source]
fill_func2(matchobj)[source]
visit_literal_block(node)[source]
depart_literal_block(node)[source]
visit_doctest_block(node)
depart_doctest_block(node)
visit_math(node)[source]
depart_math(node)[source]
visit_math_block(node)[source]
depart_math_block(node)[source]
visit_meta(node)[source]
depart_meta(node)[source]
visit_option_list(node)[source]
depart_option_list(node)[source]
visit_option_list_item(node)[source]
depart_option_list_item(node)[source]
visit_option_group(node)[source]
depart_option_group(node)[source]
visit_option(node)[source]
depart_option(node)[source]
visit_option_string(node)[source]
depart_option_string(node)[source]
visit_option_argument(node)[source]
depart_option_argument(node)[source]
visit_description(node)[source]
depart_description(node)[source]
visit_paragraph(node)[source]
depart_paragraph(node)[source]
visit_problematic(node)[source]
depart_problematic(node)[source]
visit_raw(node)[source]
depart_raw(node)[source]
visit_reference(node)[source]
depart_reference(node)[source]
visit_rubric(node)[source]
depart_rubric(node)[source]
visit_section(node, move_ids=1)[source]
depart_section(node)[source]
visit_strong(node)[source]
depart_strong(node)[source]
visit_substitution_definition(node)[source]
depart_substitution_definition(node)[source]
visit_system_message(node)[source]
depart_system_message(node)[source]
get_table_style(node)[source]
visit_table(node)[source]
depart_table(node)[source]
visit_tgroup(node)[source]
depart_tgroup(node)[source]
visit_colspec(node)[source]
depart_colspec(node)[source]
visit_thead(node)[source]
depart_thead(node)[source]
visit_row(node)[source]
depart_row(node)[source]
visit_entry(node)[source]
depart_entry(node)[source]
visit_tbody(node)[source]
depart_tbody(node)[source]
visit_target(node)[source]
depart_target(node)[source]
visit_title(node, move_ids=1, title_type='title')[source]
depart_title(node)[source]
visit_subtitle(node, move_ids=1)[source]
depart_subtitle(node)[source]
visit_title_reference(node)[source]
depart_title_reference(node)[source]
generate_table_of_content_entry_template(el1)[source]
find_title_label(node, class_type, label_key)[source]
visit_topic(node)[source]
depart_topic(node)[source]
update_toc_page_numbers(el)[source]
update_toc_collect(el, level, collection)[source]
update_toc_add_numbers(collection)[source]
visit_transition(node)[source]
depart_transition(node)[source]
visit_warning(node)[source]
depart_warning(node)[source]
visit_attention(node)[source]
depart_attention(node)
visit_caution(node)[source]
depart_caution(node)
visit_danger(node)[source]
depart_danger(node)
visit_error(node)[source]
depart_error(node)
visit_hint(node)[source]
depart_hint(node)
visit_important(node)[source]
depart_important(node)
visit_note(node)[source]
depart_note(node)
visit_tip(node)[source]
depart_tip(node)
visit_admonition(node)[source]
depart_admonition(node)
generate_admonition(node, label, title=None)[source]
visit_subscript(node)[source]
depart_subscript(node)[source]
visit_superscript(node)[source]
depart_superscript(node)[source]
visit_abbreviation(node)[source]
depart_abbreviation(node)[source]
visit_acronym(node)[source]
depart_acronym(node)[source]
visit_sidebar(node)[source]
depart_sidebar(node)[source]
class Reader(parser=None, parser_name=None)[source]

Bases: Reader

get_transforms()[source]

Transforms required by this class. Override in subclasses.

Submodules