Skip to content

Commit 974fb68

Browse files
committed
Merge pull request #61 from OpenScienceFramework/issue_61
Handle the noBreakHyphen tag
2 parents 71fb6d9 + cc40887 commit 974fb68

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11

22
Changelog
33
=========
4+
* 0.3.11
5+
* The non breaking hyphen tag was not correctly being imported. This issue
6+
has been fixed.
47
* 0.3.10
58
* Found and optimized a fairly large performance issue with tables that had
69
large amounts of content within a single cell, which includes nested

pydocx/DocxParser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ def parse(self, el):
198198
return self.parse_t(el, parsed)
199199
elif el.tag == 'tab':
200200
return self.parse_tab(el, parsed)
201+
elif el.tag == 'noBreakHyphen':
202+
return self.parse_hyphen(el, parsed)
201203
elif el.tag == 'br':
202204
return self.parse_break_tag(el, parsed)
203205
elif el.tag == 'delText':
@@ -612,6 +614,9 @@ def parse_t(self, el, parsed):
612614
def parse_tab(self, el, parsed):
613615
return ' '
614616

617+
def parse_hyphen(self, el, parsed):
618+
return '-'
619+
615620
def parse_break_tag(self, el, parsed):
616621
return self.break_tag()
617622

pydocx/fixtures/no_break_hyphen.docx

3.64 KB
Binary file not shown.

pydocx/tests/test_docx.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,19 @@ def test_styled_bolding():
776776
''')
777777

778778

779+
def test_no_break_hyphen():
780+
file_path = path.join(
781+
path.abspath(path.dirname(__file__)),
782+
'..',
783+
'fixtures',
784+
'no_break_hyphen.docx',
785+
)
786+
actual_html = convert(file_path)
787+
assert_html_equal(actual_html, BASE_HTML % '''
788+
<p>AAA-BBB</p>
789+
''')
790+
791+
779792
@raises(MalformedDocxException)
780793
def test_malformed_docx_exception():
781794
with NamedTemporaryFile(suffix='.docx') as f:

0 commit comments

Comments
 (0)