File tree 2 files changed +15
-2
lines changed
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change 7
7
8
8
from __future__ import absolute_import
9
9
10
+ import re
11
+ import six
10
12
from lxml import etree
11
13
12
14
from .ns import NamespacePrefixedTag , nsmap
18
20
oxml_parser .set_element_class_lookup (element_class_lookup )
19
21
20
22
23
+ def remove_hyperlink_tags (xml ):
24
+ is_bytestring = isinstance (xml , six .binary_type )
25
+ if is_bytestring :
26
+ xml = xml .decode ('utf-8' )
27
+ xml = xml .replace ('</w:hyperlink>' , '' )
28
+ xml = re .sub ('<w:hyperlink[^>]*>' , '' , xml )
29
+ if is_bytestring :
30
+ xml = xml .encode ('utf-8' )
31
+ return xml
32
+
33
+
21
34
def parse_xml (xml ):
22
35
"""
23
36
Return root lxml element obtained by parsing XML character string in
24
37
*xml*, which can be either a Python 2.x string or unicode. The custom
25
38
parser is used, so custom element classes are produced for elements in
26
39
*xml* that have them.
27
40
"""
28
- root_element = etree .fromstring (xml , oxml_parser )
41
+ root_element = etree .fromstring (remove_hyperlink_tags ( xml ) , oxml_parser )
29
42
return root_element
30
43
31
44
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ def text_of(relpath):
36
36
PACKAGES = find_packages (exclude = ['tests' , 'tests.*' ])
37
37
PACKAGE_DATA = {'docx' : ['templates/*' ]}
38
38
39
- INSTALL_REQUIRES = ['lxml>=2.3.2' ]
39
+ INSTALL_REQUIRES = ['lxml>=2.3.2' , 'six>=1.10.0' ]
40
40
TEST_SUITE = 'tests'
41
41
TESTS_REQUIRE = ['behave' , 'mock' , 'pyparsing' , 'pytest' ]
42
42
You can’t perform that action at this time.
0 commit comments