#NEWLINE# def paragraph( paratext , style = 'BodyText' , breakbefore = False , jc = 'left' ) : #NEWLINE# #INDENT# "\n    Return a new paragraph element containing *paratext*. The paragraph's\n    default style is 'Body Text', but a new style may be set using the\n    *style* parameter.\n\n    @param string jc: Paragraph alignment, possible values:\n                      left, center, right, both (justified), ...\n                      see http://www.schemacentral.com/sc/ooxml/t-w_ST_Jc.html\n                      for a full list\n\n    If *paratext* is a list, add a run for each (text, char_format_str)\n    2-tuple in the list. char_format_str is a string containing one or more\n    of the characters 'b', 'i', or 'u', meaning bold, italic, and underline\n    respectively. For example:\n\n        paratext = [\n            ('some bold text', 'b'),\n            ('some normal text', ''),\n            ('some italic underlined text', 'iu')\n        ]\n    " #NEWLINE# paragraph = makeelement ( 'p' ) #NEWLINE# if ( not isinstance ( paratext , list ) ) : #NEWLINE# #INDENT# paratext = [ ( paratext , '' ) ] #NEWLINE# #UNINDENT# text_tuples = [ ] #NEWLINE# for pt in paratext : #NEWLINE# #INDENT# ( text , char_styles_str ) = ( pt if isinstance ( pt , ( list , tuple ) ) else ( pt , '' ) ) #NEWLINE# text_elm = makeelement ( 't' , tagtext = text ) #NEWLINE# if ( len ( text . strip ( ) ) < len ( text ) ) : #NEWLINE# #INDENT# text_elm . set ( '{http://www.w3.org/XML/1998/namespace}space' , 'preserve' ) #NEWLINE# #UNINDENT# text_tuples . append ( [ text_elm , char_styles_str ] ) #NEWLINE# #UNINDENT# pPr = makeelement ( 'pPr' ) #NEWLINE# pStyle = makeelement ( 'pStyle' , attributes = { #NEWLINE# #INDENT# 'val' : style , #NEWLINE# #UNINDENT# } ) #NEWLINE# pJc = makeelement ( 'jc' , attributes = { #NEWLINE# #INDENT# 'val' : jc , #NEWLINE# #UNINDENT# } ) #NEWLINE# pPr . append ( pStyle ) #NEWLINE# pPr . append ( pJc ) #NEWLINE# paragraph . append ( pPr ) #NEWLINE# for ( text_elm , char_styles_str ) in text_tuples : #NEWLINE# #INDENT# run = makeelement ( 'r' ) #NEWLINE# rPr = makeelement ( 'rPr' ) #NEWLINE# if ( 'b' in char_styles_str ) : #NEWLINE# #INDENT# b = makeelement ( 'b' ) #NEWLINE# rPr . append ( b ) #NEWLINE# #UNINDENT# if ( 'i' in char_styles_str ) : #NEWLINE# #INDENT# i = makeelement ( 'i' ) #NEWLINE# rPr . append ( i ) #NEWLINE# #UNINDENT# if ( 'u' in char_styles_str ) : #NEWLINE# #INDENT# u = makeelement ( 'u' , attributes = { #NEWLINE# #INDENT# 'val' : 'single' , #NEWLINE# #UNINDENT# } ) #NEWLINE# rPr . append ( u ) #NEWLINE# #UNINDENT# run . append ( rPr ) #NEWLINE# if breakbefore : #NEWLINE# #INDENT# lastRenderedPageBreak = makeelement ( 'lastRenderedPageBreak' ) #NEWLINE# run . append ( lastRenderedPageBreak ) #NEWLINE# #UNINDENT# run . append ( text_elm ) #NEWLINE# paragraph . append ( run ) #NEWLINE# #UNINDENT# return paragraph