diff options
| author | Fuwn <[email protected]> | 2023-10-31 11:17:51 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-10-31 11:17:51 -0700 |
| commit | c2fa97e1993ce50a3aa22edf1339b2be3219066f (patch) | |
| tree | d0cf976aad17ed0bdc0897723786eb84f185fad7 | |
| parent | feat(hayai): raise max content length (diff) | |
| download | hayai-c2fa97e1993ce50a3aa22edf1339b2be3219066f.tar.xz hayai-c2fa97e1993ce50a3aa22edf1339b2be3219066f.zip | |
fix(brec): fix images and use regex
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | hayai/brec.py | 14 |
2 files changed, 13 insertions, 4 deletions
@@ -6,3 +6,6 @@ venv # Artifacts uploads + +# Visual Studio Code +.vscode diff --git a/hayai/brec.py b/hayai/brec.py index e9e4bf5..6e10d96 100644 --- a/hayai/brec.py +++ b/hayai/brec.py @@ -50,11 +50,11 @@ class MyHTMLParser(HTMLParser): def bolding(text): - parts = text.split() + parts = re.findall(r"[^\s]+", text) new_text = "" for part in parts: if part in string.punctuation or part in string.digits: - new_text += part + new_text += " " + part else: if len(part) <= 3: new_part = "" @@ -103,6 +103,8 @@ for r, d, f in os.walk(unzip_path): for hfile in f: if hfile[-4:] == "html": htmls.append(os.path.join(r, hfile)) + if hfile[-3:] == "htm": + htmls.append(os.path.join(r, hfile)) for html in htmls: @@ -126,14 +128,14 @@ for html in htmls: full_attr = [] for attr in html_part[1][1]: full_attr.append(attr[0] + f'="{attr[1]}"') - full_attr = ", ".join(full_attr) + full_attr = " ".join(full_attr) if not full_attr: tag += full_attr + ">" else: tag += " " + full_attr + ">" full_html += tag if html_part[0] == "End tag:": - tag = f"</{html_part[1]}>" + tag = f"</{html_part[1]}>\n" full_html += tag full_html = first_tags + full_html @@ -145,4 +147,8 @@ for html in htmls: os.chdir(unzip_path) shutil.make_archive(epub_path, "zip", "./") +try: + os.remove((epub_path + ".zip")[:-4]) +except: + pass os.rename((epub_path + ".zip"), (epub_path + ".zip")[:-4]) |