Skip to content

Commit 0c0a8dc

Browse files
committed
add: better support for converter tool on windows
1 parent 68bf97d commit 0c0a8dc

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

htmlgenerator/contrib/convertfromhtml.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import codecs
2+
import os
23

34
import black # type: ignore
45
from bs4 import BeautifulSoup, Comment, Doctype, NavigableString, Tag # type: ignore
@@ -122,10 +123,12 @@ def parsehtml(html, formatting, compact):
122123
html = hg.BaseElement(""",
123124
]
124125

125-
soup = BeautifulSoup(
126-
html,
127-
"lxml",
128-
)
126+
if os.name == "nt":
127+
parser = "html.parser"
128+
else:
129+
parser = "lxml"
130+
131+
soup = BeautifulSoup(html, parser)
129132
for subtag in soup.contents:
130133
tags = convert(subtag, 1, compact)
131134
if tags:
@@ -146,6 +149,7 @@ def main():
146149

147150
formatflag = "--no-formatting"
148151
compactflag = "--compact"
152+
encodingflag = "--encoding"
149153

150154
files = sys.argv[1:]
151155
formatting = formatflag not in files
@@ -154,10 +158,15 @@ def main():
154158
files.remove(formatflag)
155159
if compactflag in files:
156160
files.remove(compactflag)
161+
if encodingflag in files:
162+
encoding = files[files.index(encodingflag) + 1]
163+
files.remove(encodingflag)
164+
files.remove(encoding)
165+
157166
if not files:
158167
print(parsehtml(sys.stdin.read(), formatting, compact), end="")
159168
for _file in files:
160-
with open(_file) as rf:
169+
with open(_file, encoding=encoding) as rf:
161170
with open(_file + ".py", "w") as wf:
162171
wf.write(parsehtml(rf.read(), formatting, compact))
163172

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
packages=find_packages(),
2626
zip_safe=False,
2727
include_package_data=True,
28-
extras_require={"all": ["black", "beautifulsoup4", "lxml"]},
28+
extras_require={
29+
"all": ["black", "beautifulsoup4", "lxml;platform_system!='Windows'"]
30+
},
2931
entry_points={
3032
"console_scripts": [
3133
"convertfromhtml = htmlgenerator.contrib.convertfromhtml:main",

0 commit comments

Comments
 (0)