Skip to content
This repository was archived by the owner on Jan 12, 2018. It is now read-only.

Indentation options for paragraphs #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def pagebreak(type='page', orient='portrait'):
return pagebreak


def paragraph(paratext, style='BodyText', breakbefore=False, jc='left'):
def paragraph(paratext, style='BodyText', breakbefore=False, jc='left', ind=None):
'''Make a new paragraph element, containing a run, and some text.
Return the paragraph element.

Expand All @@ -150,6 +150,14 @@ def paragraph(paratext, style='BodyText', breakbefore=False, jc='left'):
see http://www.schemacentral.com/sc/ooxml/t-w_ST_Jc.html
for a full list

@param int ind: Paragraph indentation. You can provide an integer, this one
will be used as the left indentation. Or you can provide a
dictionary to customize all the different indentations, see
http://www.schemacentral.com/sc/ooxml/e-w_ind-1.html.
Example:
ind=1200
ind={"left": 1200, "right": 800}

If paratext is a list, spawn multiple run/text elements.
Support text styles (paratext must then be a list of lists in the form
<text> / <style>. Stile is a string containing a combination od 'bui' chars
Expand Down Expand Up @@ -177,6 +185,18 @@ def paragraph(paratext, style='BodyText', breakbefore=False, jc='left'):
pPr = makeelement('pPr')
pStyle = makeelement('pStyle', attributes={'val': style})
pJc = makeelement('jc', attributes={'val': jc})
# Add the indentation element
if ind:
attrs = {'left': ind}
if type(ind) == dict:
attrs = ind
# Convert the integer attributes to unicode
for k, v in attrs.items():
if type(v) == int:
attrs[k] = unicode(v)
# Create the element
pInd = makeelement('ind', attributes=attrs)
pPr.append(pInd)
pPr.append(pStyle)
pPr.append(pJc)

Expand Down