Skip to content

Commit b0f81bc

Browse files
committed
hdr: add HeaderPart._default_header_xml()
1 parent 05895d3 commit b0f81bc

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

docx/parts/hdrftr.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from __future__ import absolute_import, division, print_function, unicode_literals
66

7+
import os
8+
79
from docx.opc.constants import CONTENT_TYPE as CT
810
from docx.opc.part import XmlPart
911
from docx.oxml import parse_xml
@@ -23,4 +25,9 @@ def new(cls, package):
2325
@classmethod
2426
def _default_header_xml(cls):
2527
"""Return bytes containing XML for a default header part."""
26-
raise NotImplementedError
28+
path = os.path.join(
29+
os.path.split(__file__)[0], '..', 'templates', 'default-header.xml'
30+
)
31+
with open(path, 'rb') as f:
32+
xml_bytes = f.read()
33+
return xml_bytes

docx/templates/default-header.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<w:hdr
3+
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main"
6+
xmlns:mv="urn:schemas-microsoft-com:mac:vml"
7+
xmlns:o="urn:schemas-microsoft-com:office:office"
8+
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
9+
xmlns:v="urn:schemas-microsoft-com:vml"
10+
xmlns:w10="urn:schemas-microsoft-com:office:word"
11+
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
12+
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
13+
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
14+
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
15+
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
16+
xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
17+
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
18+
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
19+
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
20+
mc:Ignorable="w14 wp14"
21+
>
22+
<w:p>
23+
<w:pPr>
24+
<w:pStyle w:val="Header"/>
25+
</w:pPr>
26+
</w:p>
27+
</w:hdr>

features/hdr-header-footer.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Feature: Header and footer behaviors
1414
| with no | True |
1515

1616

17-
@wip
1817
Scenario Outline: _Header.is_linked_to_previous setter
1918
Given a _Header object <with-or-no> header definition as header
2019
When I assign <value> to header.is_linked_to_previous

tests/parts/test_hdrftr.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ def it_can_create_a_new_header_part(
3333
header_part, "/word/header42.xml", CT.WML_HEADER, hdr, package_
3434
)
3535

36+
def it_loads_default_header_XML_from_a_template_to_help(self):
37+
# ---tests integration with OS---
38+
xml_bytes = HeaderPart._default_header_xml()
39+
40+
assert xml_bytes.startswith(
41+
b"<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n<w:hdr\n"
42+
)
43+
assert len(xml_bytes) == 1395
44+
3645
# fixture components ---------------------------------------------
3746

3847
@pytest.fixture

0 commit comments

Comments
 (0)