Word Document Construction

The vc2_pseudocode_parser.docx_generator module implements a simplified wrapper around docx for generating Word documents containing SMPTE specification style code listings.

Document model

Documents are defined using a hierarchy of the following classes:

class ListingDocument(body=<factory>)

A document containing code listings. The root of the document heirarchy.

body: List[Union[vc2_pseudocode_parser.docx_generator.Paragraph, vc2_pseudocode_parser.docx_generator.ListingTable]]

The contents of this document.

make_docx_document()

Construct a docx.Document object from this document (ready for saving as a file or further manipulation).

class Paragraph(runs=[])

A paragraph of text consisting of a series of concatenated Runs of text.

As a convenience, the constructor accepts either a list of Runs, a single Run or a str.

Paragraph objects support the + operator which will concatenate the runs in a pair of Paragraphs, producing a new Paragraph. You can also add Run and str to Paragraphs with similar effect.

runs: List[vc2_pseudocode_parser.docx_generator.Run]

The runs of text contained in this paragraph.

class Run(text='', style=None)

A run of text within a paragraph, which will be rendered with a particular style (defined in RunStyle).

text: str = ''
style: Optional[vc2_pseudocode_parser.docx_generator.RunStyle] = None
add_to_docx_paragraph(docx_document, docx_paragraph)
class RunStyle(value)

Text styles for runs.

pseudocode = 'Pseudocode'
pseudocode_fdef = 'Pseudocode Function Defnition'
pseudocode_keyword = 'Pseudocode Keyword'
pseudocode_label = 'Pseudocode Label'
class ListingTable(rows)

A code listing table giving the source code for a single function definiton.

If any lines in the listing contain a comment, the resulting table will have two colums with the code on the left and comments on the right. If no lines contain a comment, the table will have a single column.

rows: List[vc2_pseudocode_parser.docx_generator.ListingLine]

The rows in the table.

class ListingLine(code=<factory>, comment=<factory>)

A single row in a ListingTable.

code: vc2_pseudocode_parser.docx_generator.Paragraph
comment: vc2_pseudocode_parser.docx_generator.Paragraph