mathml2docx 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mathml2docx-0.1.2/mathml2docx.egg-info → mathml2docx-0.1.3}/PKG-INFO +1 -1
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx/__init__.py +1 -1
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx/h2d.py +13 -1
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx/wrapper.py +23 -2
- {mathml2docx-0.1.2 → mathml2docx-0.1.3/mathml2docx.egg-info}/PKG-INFO +1 -1
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/pyproject.toml +1 -1
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/test_code.py +2 -2
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/test_tables.py +2 -2
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/.github/workflows/python-app.yml +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/.gitignore +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/LICENSE +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/README.md +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx/MML2OMML.XSL +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx/config.py +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx/utils.py +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx.egg-info/SOURCES.txt +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx.egg-info/dependency_links.txt +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx.egg-info/requires.txt +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/mathml2docx.egg-info/top_level.txt +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/requirements.txt +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/setup.cfg +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/__init__.py +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/context.py +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/dataset/code.html +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/dataset/mathml.html +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/dataset/tables1.html +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/dataset/tables2.html +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/dataset/tables3.html +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/dataset/testimg.png +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/dataset/text1.html +0 -0
- {mathml2docx-0.1.2 → mathml2docx-0.1.3}/tests/test.py +0 -0
|
@@ -39,6 +39,7 @@ class HtmlToDocx(HTMLParser):
|
|
|
39
39
|
'tables': True,
|
|
40
40
|
'mathml': True,
|
|
41
41
|
'styles': True,
|
|
42
|
+
'img_src_base_path':None,
|
|
42
43
|
}
|
|
43
44
|
self.table_row_selectors = [
|
|
44
45
|
'table > tr',
|
|
@@ -64,6 +65,7 @@ class HtmlToDocx(HTMLParser):
|
|
|
64
65
|
self.include_images = self.options['images']
|
|
65
66
|
self.include_mathml = self.options['mathml']
|
|
66
67
|
self.include_styles = self.options['styles']
|
|
68
|
+
self.img_src_base_path = self.options['img_src_base_path']
|
|
67
69
|
self.paragraph = None
|
|
68
70
|
self.run = None
|
|
69
71
|
self.skip = False
|
|
@@ -217,12 +219,22 @@ class HtmlToDocx(HTMLParser):
|
|
|
217
219
|
except urllib.error.URLError:
|
|
218
220
|
image = None
|
|
219
221
|
else:
|
|
222
|
+
|
|
220
223
|
image = src_attr
|
|
224
|
+
print(self.img_src_base_path)
|
|
221
225
|
if image and image.startswith('data:image/'):
|
|
222
226
|
#-- convert to bytes ready to insert to docx
|
|
223
227
|
image = image.split(',')[1]
|
|
224
228
|
image = base64.b64decode(image)
|
|
225
229
|
image = io.BytesIO(image)
|
|
230
|
+
elif image and self.img_src_base_path:
|
|
231
|
+
image = os.path.abspath(os.path.join(self.img_src_base_path, image))
|
|
232
|
+
print(image)
|
|
233
|
+
if os.path.isfile(image):
|
|
234
|
+
with open(image, "rb") as fp:
|
|
235
|
+
image = io.BytesIO(fp.read())
|
|
236
|
+
else:
|
|
237
|
+
image = None
|
|
226
238
|
else:
|
|
227
239
|
image = None
|
|
228
240
|
|
|
@@ -682,4 +694,4 @@ if __name__=='__main__':
|
|
|
682
694
|
args = vars(arg_parser.parse_args())
|
|
683
695
|
file_html = args.pop('filename_html')
|
|
684
696
|
html_parser = HtmlToDocx()
|
|
685
|
-
html_parser.parse_html_file(file_html, **args)
|
|
697
|
+
html_parser.parse_html_file(file_html, **args)
|
|
@@ -13,10 +13,19 @@ class MathmlToDocx:
|
|
|
13
13
|
tables = True,
|
|
14
14
|
mathml = True,
|
|
15
15
|
styles = True,
|
|
16
|
+
img_src_base_path = None,
|
|
16
17
|
table_style = DEFAULT_TABLE_STYLE,
|
|
17
18
|
paragraph_style = DEFAULT_PARAGRAPH_STYLE):
|
|
18
19
|
self.__h2d = HtmlToDocx()
|
|
19
|
-
self.__options = MathmlTODocxOption(
|
|
20
|
+
self.__options = MathmlTODocxOption(
|
|
21
|
+
self.__h2d,
|
|
22
|
+
fix_html,
|
|
23
|
+
images,
|
|
24
|
+
tables,
|
|
25
|
+
mathml,
|
|
26
|
+
styles,
|
|
27
|
+
img_src_base_path
|
|
28
|
+
)
|
|
20
29
|
self.__h2d.table_style = table_style
|
|
21
30
|
self.__h2d.paragraph_style = paragraph_style
|
|
22
31
|
|
|
@@ -97,7 +106,7 @@ class MathmlToDocx:
|
|
|
97
106
|
self.__h2d.add_styles_to_run(style)
|
|
98
107
|
|
|
99
108
|
class MathmlTODocxOption:
|
|
100
|
-
def __init__(self, h2d, fix_html, images, tables, mathml, styles):
|
|
109
|
+
def __init__(self, h2d, fix_html, images, tables, mathml, styles, img_src_base_path):
|
|
101
110
|
# init
|
|
102
111
|
self.__h2d = h2d
|
|
103
112
|
self.__fix_html = fix_html
|
|
@@ -105,6 +114,7 @@ class MathmlTODocxOption:
|
|
|
105
114
|
self.__tables = tables
|
|
106
115
|
self.__mathml = mathml
|
|
107
116
|
self.__styles = styles
|
|
117
|
+
self.__img_src_base_path = img_src_base_path
|
|
108
118
|
|
|
109
119
|
# h2d options init
|
|
110
120
|
self.__h2d.options["fix-html"] = self.__fix_html
|
|
@@ -112,6 +122,7 @@ class MathmlTODocxOption:
|
|
|
112
122
|
self.__h2d.options["tables"] = self.__tables
|
|
113
123
|
self.__h2d.options["mathml"] = self.__mathml
|
|
114
124
|
self.__h2d.options["styles"] = self.__styles
|
|
125
|
+
self.__h2d.options["img_src_base_path"] = self.__img_src_base_path
|
|
115
126
|
|
|
116
127
|
@property
|
|
117
128
|
def fix_html(self) -> bool:
|
|
@@ -163,6 +174,16 @@ class MathmlTODocxOption:
|
|
|
163
174
|
self.__styles = styles
|
|
164
175
|
self.__h2d.options["styles"] = styles
|
|
165
176
|
|
|
177
|
+
@property
|
|
178
|
+
def img_src_base_path(self) -> Union[str, None]:
|
|
179
|
+
self.__img_src_base_path = self.__h2d.options["img_src_base_path"]
|
|
180
|
+
return self.__img_src_base_path
|
|
181
|
+
|
|
182
|
+
@img_src_base_path.setter
|
|
183
|
+
def img_src_base_path(self, img_src_base_path : Union[str, None]):
|
|
184
|
+
self.__img_src_base_path = img_src_base_path
|
|
185
|
+
self.__h2d.options["img_src_base_path"] = img_src_base_path
|
|
186
|
+
|
|
166
187
|
if __name__=='__main__':
|
|
167
188
|
arg_parser = argparse.ArgumentParser(description='Convert .html file into .docx file with formatting')
|
|
168
189
|
arg_parser.add_argument('filename_html', help='The .html file to be parsed')
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from .context import
|
|
2
|
+
from .context import MathmlToDocx, test_dir
|
|
3
3
|
|
|
4
4
|
# Manual test (requires inspection of result) for converting code and pre blocks.
|
|
5
5
|
|
|
6
6
|
filename = os.path.join(test_dir, 'dataset', 'code.html')
|
|
7
|
-
d =
|
|
7
|
+
d = MathmlToDocx()
|
|
8
8
|
|
|
9
9
|
d.parse_html_file(filename)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from .context import
|
|
2
|
+
from .context import MathmlToDocx, test_dir
|
|
3
3
|
|
|
4
4
|
# Manual test (requires inspection of result) for converting html with nested tables
|
|
5
5
|
|
|
6
6
|
filename = os.path.join(test_dir, 'dataset', 'tables2.html')
|
|
7
|
-
d =
|
|
7
|
+
d = MathmlToDocx()
|
|
8
8
|
|
|
9
9
|
d.parse_html_file(filename)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|