### Define Visitor for Custom Nodes in conf.py Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/third_party_extensions.md Example of defining a `setup` function in `conf.py` to handle custom nodes, specifically the `plantuml` node from `sphinxcontrib-plantuml`. This function registers a custom visitor method for the Docxbuilder translator. ```python # Define setup function in conf.py def setup(app): # Define visit method for plantuml node generated by sphinxcontrib.plantuml # https://pypi.org/project/sphinxcontrib-plantuml/ def docx_visit_plantuml(self, node): def get_filepath(self, node): from sphinxcontrib import plantuml _, filepath = plantuml.render_plantuml(self, node, 'png') return filepath alt = node.get('alt', (node['uml'], None)) # Docxbuilder provides useful methods. See Docxbuilder API reference. self.visit_image_node(node, alt, get_filepath) # Add the visit method to Docxbuilder import docxbuilder translator = docxbuilder.DocxBuilder.default_translator_class setattr(translator, 'visit_plantuml', docx_visit_plantuml) ``` -------------------------------- ### Install docxbuilder Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/docxbuilder.md Install the docxbuilder package using pip. For math directive support, install with the 'math' extra. ```shell pip install docxbuilder ``` ```shell pip install docxbuilder[math] ``` -------------------------------- ### Docxbuilder Configuration Example Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/docxbuilder.md Example of how to configure docx_documents, docx_style, and docx_pagebreak_before_section in conf.py. The docx_documents list defines document structure, target names, properties, and toctree_only behavior. docx_style specifies a custom style file, and docx_pagebreak_before_section controls page breaks before sections. ```python docx_documents = [ ('index', 'docxbuilder.docx', { 'title': 'Docxbuilder documentation', 'created': 'author' 'subject': 'Sphinx builder extension', 'keywords': ['sphinx'] }, True), ] docx_style = 'path/to/custom_style.docx' docx_pagebreak_before_section = 1 ``` -------------------------------- ### Table Style Example Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/style.md Illustrates a basic table structure with headers and multiple rows of data. ```markdown | Heading1 | Heading2 | Heading3 | Heading4 | |------------|------------|------------|------------| | Cell1-1 | Cell1-2 | Cell1-3 | Cell1-4 | | Cell2-1 | Cell2-2 | Cell2-3 | Cell2-4 | | Cell3-1 | Cell3-2 | Cell3-3 | Cell3-4 | ``` -------------------------------- ### Apply Specific Section Settings Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/customization.md Use rst-class directives to apply specific section settings (portrait or landscape) from the style file to subsequent sections in the document. The index N starts from 0 for the first section. ```rst .. rst-class:: docx-section-portrait-1 Section B ========= contents .. Use 1st section from the next section .. rst-class:: docx-section-portrait-0 Section C ========= contents ``` -------------------------------- ### Build docx document Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/docxbuilder.md Use the 'make docx' command or 'sphinx-build -b docx' to generate the docx document from your Sphinx source. ```shell make docx # or sphinx-build -b docx path/to/source path/to/output ``` -------------------------------- ### Admonition Warning Style Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/style.md Demonstrates the formatting for a 'WARNING' admonition to highlight critical alerts. ```text Admonition Warning ``` -------------------------------- ### Admonition Note Style Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/style.md Shows how to format a 'NOTE' admonition for important information. ```text Admonition Note ``` -------------------------------- ### Admonition Note Style Source: https://github.com/amedama41/docxbuilder/blob/master/style_file/source/style.md Shows how to format a 'NOTE' admonition, used for important information or tips. ```markdown #### NOTE Admonition Note ``` -------------------------------- ### Admonition Warning Style Source: https://github.com/amedama41/docxbuilder/blob/master/style_file/source/style.md Demonstrates the formatting for a 'WARNING' admonition, used to highlight potential issues or cautions. ```markdown #### WARNING Admonition Warning ``` -------------------------------- ### Field List Style Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/style.md Presents a field list structure for key-value pairs. ```text * **field1:** descirption1 * **field2:** descirption2 ``` -------------------------------- ### Configure docx Document Generation Source: https://github.com/amedama41/docxbuilder/blob/master/README.rst Customize the generated docx document by defining the 'docx_documents' list in conf.py. This includes specifying the source index file, output filename, and metadata like title, creator, and subject. You can also set a custom style file and control page breaks before sections. ```python docx_documents = [ ('index', 'docxbuilder.docx', { 'title': project, 'creator': author, 'subject': 'A manual of docxbuilder', }, True), ] docx_style = 'path/to/custom_style.docx' docx_pagebreak_before_section = 1 ``` -------------------------------- ### Add docxbuilder to Sphinx Extensions Source: https://github.com/amedama41/docxbuilder/blob/master/README.rst To enable the docxbuilder extension, add 'docxbuilder' to the extensions list in your Sphinx project's conf.py file. ```python extensions = ['docxbuilder'] ``` -------------------------------- ### Literal Block Style Source: https://github.com/amedama41/docxbuilder/blob/master/style_file/source/style.md Demonstrates the rendering of a literal block, typically used for code or preformatted text. ```markdown ```guess Literal Block ``` ``` -------------------------------- ### Define Custom Styles in Python Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/customization.md Configure Docxbuilder to use custom styles by specifying a style file and mapping class names to style names. These styles can then be applied to elements in your document. ```python docx_style = 'path/to/custom-style.docx' docx_style_names = { 'strike': 'Strike', 'custom-table': 'Custom Table', } # And define Strike and Custom Table styles in the style file specified docx_style ``` -------------------------------- ### Literal Block Style Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/style.md Demonstrates the usage of a literal block for displaying code or preformatted text within a document. ```text Literal Block ``` -------------------------------- ### Arrange Table in Landscape Page Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/customization.md Apply the 'docx-landscape' class to a CSV table to render it on a landscape page. This is useful for tables with many columns or wide content. ```rst .. csv-table:: :class: docx-landscape A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 ``` -------------------------------- ### Apply Custom Styles in reStructuredText Source: https://github.com/amedama41/docxbuilder/blob/master/docs/source/customization.md Use roles and directives in reStructuredText to apply custom styles like 'strike' for text and 'custom-table' for tables. Ensure the corresponding styles are defined in your Docxbuilder configuration. ```rst .. Use role to specify character class name. .. role:: strike This :strike:`text` is striked. .. list-table:: Custom style table :class: custom-table * - Row1: Col1 - Row1: Col2 * - Row2: Col1 - Row2: Col2 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.