Skip to content

Commit 321cad1

Browse files
DKWoodsSteve Canny
authored andcommitted
tabs: add TabStop.leader
1 parent 48a7e31 commit 321cad1

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

docx/oxml/text/parfmt.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
from ...enum.text import (
8-
WD_ALIGN_PARAGRAPH, WD_LINE_SPACING, WD_TAB_ALIGNMENT
8+
WD_ALIGN_PARAGRAPH, WD_LINE_SPACING, WD_TAB_ALIGNMENT, WD_TAB_LEADER
99
)
1010
from ...shared import Length
1111
from ..simpletypes import ST_SignedTwipsMeasure, ST_TwipsMeasure
@@ -322,6 +322,9 @@ class CT_TabStop(BaseOxmlElement):
322322
``<w:tab>`` element, representing an individual tab stop.
323323
"""
324324
val = RequiredAttribute('w:val', WD_TAB_ALIGNMENT)
325+
leader = OptionalAttribute(
326+
'w:leader', WD_TAB_LEADER, default=WD_TAB_LEADER.SPACES
327+
)
325328
pos = RequiredAttribute('w:pos', ST_SignedTwipsMeasure)
326329

327330

docx/text/tabstops.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ def alignment(self):
7272
"""
7373
return self._tab.val
7474

75+
@property
76+
def leader(self):
77+
"""
78+
A member of :ref:`WdTabLeader` specifying a repeating character used
79+
as a "leader", filling in the space spanned by this tab. Assigning
80+
|None| produces the same result as assigning `WD_TAB_LEADER.SPACES`.
81+
"""
82+
return self._tab.leader
83+
7584
@property
7685
def position(self):
7786
"""

features/tab-tabstop-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Feature: Tab stop properties
2424
| RIGHT |
2525

2626

27-
@wip
2827
Scenario Outline: Get TabStop.leader
2928
Given a tab stop having <leader> leader
3029
Then tab_stop.leader is <value>

tests/text/test_tabstops.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
absolute_import, division, print_function, unicode_literals
1010
)
1111

12-
from docx.enum.text import WD_TAB_ALIGNMENT
12+
from docx.enum.text import WD_TAB_ALIGNMENT, WD_TAB_LEADER
1313
from docx.shared import Twips
1414
from docx.text.tabstops import TabStop, TabStops
1515

@@ -29,6 +29,10 @@ def it_knows_its_alignment(self, alignment_get_fixture):
2929
tab_stop, expected_value = alignment_get_fixture
3030
assert tab_stop.alignment == expected_value
3131

32+
def it_knows_its_leader(self, leader_get_fixture):
33+
tab_stop, expected_value = leader_get_fixture
34+
assert tab_stop.leader == expected_value
35+
3236
# fixture --------------------------------------------------------
3337

3438
@pytest.fixture(params=[
@@ -41,6 +45,17 @@ def alignment_get_fixture(self, request):
4145
expected_value = getattr(WD_TAB_ALIGNMENT, member)
4246
return tab_stop, expected_value
4347

48+
@pytest.fixture(params=[
49+
('w:tab', 'SPACES'),
50+
('w:tab{w:leader=none}', 'SPACES'),
51+
('w:tab{w:leader=dot}', 'DOTS'),
52+
])
53+
def leader_get_fixture(self, request):
54+
tab_stop_cxml, member = request.param
55+
tab_stop = TabStop(element(tab_stop_cxml))
56+
expected_value = getattr(WD_TAB_LEADER, member)
57+
return tab_stop, expected_value
58+
4459
@pytest.fixture
4560
def position_get_fixture(self, request):
4661
tab_stop = TabStop(element('w:tab{w:pos=720}'))

0 commit comments

Comments
 (0)