11# encoding: utf-8
22
3- """
4- |Document| and closely related objects
5- """
3+ """|Document| and closely related objects"""
64
7- from __future__ import (
8- absolute_import , division , print_function , unicode_literals
9- )
5+ from __future__ import absolute_import , division , print_function , unicode_literals
106
11- from .blkcntnr import BlockItemContainer
12- from .enum .section import WD_SECTION
13- from .enum .text import WD_BREAK
14- from .section import Section , Sections
15- from .shared import ElementProxy , Emu
7+ from docx .blkcntnr import BlockItemContainer
8+ from docx .enum .section import WD_SECTION
9+ from docx .enum .text import WD_BREAK
10+ from docx .section import Section , Sections
11+ from docx .shared import ElementProxy , Emu
1612
1713
1814class Document (ElementProxy ):
19- """
20- WordprocessingML (WML) document. Not intended to be constructed directly.
21- Use :func:`docx.Document` to open or create a document.
15+ """WordprocessingML (WML) document.
16+
17+ Not intended to be constructed directly. Use :func:`docx.Document` to open or create
18+ a document.
2219 """
2320
2421 __slots__ = ('_part' , '__body' )
@@ -28,25 +25,21 @@ def __init__(self, element, part):
2825 self ._part = part
2926 self .__body = None
3027
31- def add_heading (self , text = '' , level = 1 ):
32- """
33- Return a heading paragraph newly added to the end of the document,
34- containing *text* and having its paragraph style determined by
35- *level*. If *level* is 0, the style is set to `Title`. If *level* is
36- 1 (or omitted), `Heading 1` is used. Otherwise the style is set to
37- `Heading {level}`. Raises |ValueError| if *level* is outside the
38- range 0-9.
28+ def add_heading (self , text = "" , level = 1 ):
29+ """Return a heading paragraph newly added to the end of the document.
30+
31+ The heading paragraph will contain *text* and have its paragraph style
32+ determined by *level*. If *level* is 0, the style is set to `Title`. If *level*
33+ is 1 (or omitted), `Heading 1` is used. Otherwise the style is set to `Heading
34+ {level}`. Raises |ValueError| if *level* is outside the range 0-9.
3935 """
4036 if not 0 <= level <= 9 :
4137 raise ValueError ("level must be in range 0-9, got %d" % level )
42- style = ' Title' if level == 0 else ' Heading %d' % level
38+ style = " Title" if level == 0 else " Heading %d" % level
4339 return self .add_paragraph (text , style )
4440
4541 def add_page_break (self ):
46- """
47- Return a paragraph newly added to the end of the document and
48- containing only a page break.
49- """
42+ """Return newly |Paragraph| object containing only a page break."""
5043 paragraph = self .add_paragraph ()
5144 paragraph .add_run ().add_break (WD_BREAK .PAGE )
5245 return paragraph
0 commit comments