fully make bs4 and soupsieve standalone in the project

This commit is contained in:
2025-04-24 17:39:41 +02:00
parent ed336866ee
commit aefb27614f
16 changed files with 72 additions and 77 deletions

View File

@ -11,18 +11,14 @@ import os.path
import concurrent.futures
import urllib.request
import base64
# --- Bundled library imports ---
# 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 .lib.bs4 import BeautifulSoup as bs4
from functools import partial
from .lib.markdown2 import Markdown
__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
@ -37,7 +33,6 @@ 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"]
@ -57,15 +52,14 @@ 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_img, (width, height) = get_base64_image(path, re_render, resources) # Renamed local var to avoid conflict
base64, (width, height) = get_base64_image(path, re_render, resources)
img_element["src"] = base64_img
img_element["src"] = base64
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)
):
@ -84,7 +78,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