Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6a51888

Browse files
authored
Merge pull request #220 from CenterForOpenScience/issue_220
`ValueError: invalid literal for int() with base 10:` crash calling `start_margin_position`
2 parents 361dbdc + 0186b21 commit 6a51888

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**0.9.10**
2+
3+
- No longer error when processing margin positions with decimal points.
4+
15
**0.9.9**
26

37
- Rect elements now correctly handle image data

pydocx/openxml/wordprocessing/paragraph_properties.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ def start_margin_position(self):
3535
# ignored.
3636
start_margin = 0
3737
if self.indentation_left:
38-
start_margin += int(self.indentation_left)
38+
start_margin += int(float(self.indentation_left))
3939
if self.indentation_hanging:
40-
start_margin -= int(self.indentation_hanging)
40+
start_margin -= int(float(self.indentation_hanging))
4141
elif self.indentation_first_line:
42-
start_margin += int(self.indentation_first_line)
42+
start_margin += int(float(self.indentation_first_line))
4343
if start_margin:
4444
return start_margin
4545
return 0

tests/openxml/wordprocessing/test_paragraph_properties.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,21 @@ def test_returns_left_minus_hanging_ignoring_first_line(self):
105105
'''
106106
properties = self._load_from_xml(xml)
107107
self.assertEqual(properties.start_margin_position, 100)
108+
109+
def test_allow_decimal_indentation_for_hanging(self):
110+
xml = '''
111+
<pPr>
112+
<ind left="123.1" hanging="23.2" />
113+
</pPr>
114+
'''
115+
properties = self._load_from_xml(xml)
116+
self.assertEqual(properties.start_margin_position, 100)
117+
118+
def test_allow_decimal_indentation_for_first_line(self):
119+
xml = '''
120+
<pPr>
121+
<ind left="123.3" firstLine="50.4" />
122+
</pPr>
123+
'''
124+
properties = self._load_from_xml(xml)
125+
self.assertEqual(properties.start_margin_position, 173)

0 commit comments

Comments
 (0)