Skip to content

Commit a2df1d1

Browse files
committed
docs: add API docs for header/footer
1 parent 569b880 commit a2df1d1

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

docs/api/section.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,20 @@ Provides access to section properties such as margins and page orientation.
2222

2323

2424
.. autoclass:: Section
25-
:members:
25+
:members:
26+
27+
28+
|_Header| and |_Footer| objects
29+
-------------------------------
30+
31+
32+
.. autoclass:: _Header()
33+
:inherited-members:
34+
:members:
35+
:exclude-members: part
36+
37+
38+
.. autoclass:: _Footer()
39+
:inherited-members:
40+
:members:
41+
:exclude-members: part

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@
109109
110110
.. |_Footer| replace:: :class:`._Footer`
111111
112+
.. |FooterPart| replace:: :class:`.FooterPart`
113+
112114
.. |_Header| replace:: :class:`._Header`
113115
116+
.. |HeaderPart| replace:: :class:`.HeaderPart`
117+
114118
.. |ImageParts| replace:: :class:`.ImageParts`
115119
116120
.. |Inches| replace:: :class:`.Inches`

docx/section.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def even_page_footer(self):
7979
"""|_Footer| object defining footer content for even pages.
8080
8181
The content of this footer definition is ignored unless the document setting
82-
:attr:`~Settings.odd_and_even_pages_header_footer` is set True.
82+
:attr:`~.Settings.odd_and_even_pages_header_footer` is set True.
8383
"""
8484
return _Footer(self._sectPr, self._document_part, WD_HEADER_FOOTER.EVEN_PAGE)
8585

@@ -88,7 +88,7 @@ def even_page_header(self):
8888
"""|_Header| object defining header content for even pages.
8989
9090
The content of this header definition is ignored unless the document setting
91-
:attr:`~Settings.odd_and_even_pages_header_footer` is set True.
91+
:attr:`~.Settings.odd_and_even_pages_header_footer` is set True.
9292
"""
9393
return _Header(self._sectPr, self._document_part, WD_HEADER_FOOTER.EVEN_PAGE)
9494

@@ -106,7 +106,7 @@ def first_page_header(self):
106106
"""|_Header| object defining header content for the first page of this section.
107107
108108
The content of this header definition is ignored unless the property
109-
:attr:`.different_first_page_header_header` is set True.
109+
:attr:`.different_first_page_header_footer` is set True.
110110
"""
111111
return _Header(self._sectPr, self._document_part, WD_HEADER_FOOTER.FIRST_PAGE)
112112

@@ -270,9 +270,9 @@ def __init__(self, sectPr, document_part, header_footer_index):
270270

271271
@property
272272
def is_linked_to_previous(self):
273-
"""True if this header/footer uses the definition from the preceding section.
273+
"""``True`` if this header/footer uses the definition from the prior section.
274274
275-
False if this header/footer has an explicit definition.
275+
``False`` if this header/footer has an explicit definition.
276276
277277
Assigning ``True`` to this property removes the header/footer definition for
278278
this section, causing it to "inherit" the corresponding definition of the prior
@@ -357,7 +357,14 @@ def _prior_headerfooter(self):
357357

358358

359359
class _Footer(_BaseHeaderFooter):
360-
"""Page footer."""
360+
"""Page footer, used for all three types (default, even-page, and first-page).
361+
362+
Note that, like a document or table cell, a footer must contain a minimum of one
363+
paragraph and a new or otherwise "empty" footer contains a single empty paragraph.
364+
This first paragraph can be accessed as `footer.paragraphs[0]` for purposes of
365+
adding content to it. Using :meth:`add_paragraph()` by itself to add content will
366+
leave an empty paragraph above the newly added one.
367+
"""
361368

362369
def _add_definition(self):
363370
"""Return newly-added footer part."""
@@ -393,7 +400,14 @@ def _prior_headerfooter(self):
393400

394401

395402
class _Header(_BaseHeaderFooter):
396-
"""Page header."""
403+
"""Page header, used for all three types (default, even-page, and first-page).
404+
405+
Note that, like a document or table cell, a header must contain a minimum of one
406+
paragraph and a new or otherwise "empty" header contains a single empty paragraph.
407+
This first paragraph can be accessed as `header.paragraphs[0]` for purposes of
408+
adding content to it. Using :meth:`add_paragraph()` by itself to add content will
409+
leave an empty paragraph above the newly added one.
410+
"""
397411

398412
def _add_definition(self):
399413
"""Return newly-added header part."""

0 commit comments

Comments
 (0)