fix import

This commit is contained in:
2025-04-24 17:06:45 +02:00
parent 0034602fff
commit e0daa147f1
2 changed files with 14 additions and 6 deletions

View File

@ -13,15 +13,16 @@ import urllib.request
import base64
# --- Bundled library imports ---
# These should now find the libraries in ./lib via the modified sys.path
import bs4
from .lib.markdown2 import Markdown
# Explicitly import from the 'lib' directory, now that the package root is in sys.path
from lib import bs4
from lib.markdown2 import Markdown
# --- End bundled library imports ---
from functools import partial
__all__ = ("markdown2html",)
# Use the imported module name
markdowner = Markdown(extras=["fenced-code-blocks", "cuddled-lists"])
# FIXME: how do I choose how many workers I want? Does thread pool reuse threads or
@ -36,6 +37,7 @@ def markdown2html(markdown, basepath, re_render, resources, viewport_width, font
"""
html = markdowner.convert(markdown)
# Use the imported module name
soup = bs4.BeautifulSoup(html, "html.parser")
for img_element in soup.find_all("img"):
src = img_element["src"]
@ -55,14 +57,15 @@ def markdown2html(markdown, basepath, re_render, resources, viewport_width, font
# realpath: simplify that paths so that we don't have duplicated caches
path = os.path.realpath(os.path.expanduser(os.path.join(basepath, src)))
base64, (width, height) = get_base64_image(path, re_render, resources)
base64_img, (width, height) = get_base64_image(path, re_render, resources) # Renamed local var to avoid conflict
img_element["src"] = base64
img_element["src"] = base64_img
if width > viewport_width:
img_element["width"] = viewport_width
img_element["height"] = viewport_width * (height / width)
# remove comments, because they pollute the console with error messages
# Use the imported module name
for comment_element in soup.find_all(
text=lambda text: isinstance(text, bs4.Comment)
):
@ -81,7 +84,7 @@ def markdown2html(markdown, basepath, re_render, resources, viewport_width, font
.replace(" ", '<i class="space">.</i>')
.replace("\n", "<br />")
)
# Use the imported module name
code_element.replace_with(bs4.BeautifulSoup(fixed_pre, "html.parser"))
# FIXME: highlight the code using Sublime's syntax