|
|
@ -15,15 +15,15 @@ from pygments.util import ClassNotFound |
|
|
|
|
|
|
|
from .whitespace import NBSP |
|
|
|
from .context import Group |
|
|
|
from .output_generator import Output_generator |
|
|
|
from .output_generator import OutputGenerator |
|
|
|
from .katex import KatexClient |
|
|
|
from .images import ImageProcessor |
|
|
|
from .util import inlinify |
|
|
|
|
|
|
|
class HTML_generator(Output_generator): |
|
|
|
def __init__(self, output_file, katex_client: KatexClient, image_processor:ImageProcessor, *args, **kwargs): |
|
|
|
self.katex_client = katex_client |
|
|
|
self.image_processor = image_processor |
|
|
|
class HTMLGenerator(OutputGenerator): |
|
|
|
def __init__(self, output_file, katexClient: KatexClient, imageProcessor: ImageProcessor, *args, **kwargs): |
|
|
|
self.katexClient = katexClient |
|
|
|
self.imageProcessor = imageProcessor |
|
|
|
super().__init__(output_file, *args, **kwargs) |
|
|
|
|
|
|
|
def generate(self, e: Union[Element, ListContainer]): |
|
|
@ -149,15 +149,15 @@ class HTML_generator(Output_generator): |
|
|
|
# Even supported elements have to be 'converted' because the |
|
|
|
# processing contains finding and moving them to the output |
|
|
|
# directory. |
|
|
|
url = self.image_processor.process_image(url, ext, source_dir, **additional_args) |
|
|
|
url = self.imageProcessor.process_image(url, ext, source_dir, **additional_args) |
|
|
|
elif ext in ["pdf", "epdf"]: |
|
|
|
if not "dpi" in additional_args: |
|
|
|
additional_args["dpi"] = 300 |
|
|
|
url = self.image_processor.process_image(url, "png", source_dir, **additional_args) |
|
|
|
url = self.imageProcessor.process_image(url, "png", source_dir, **additional_args) |
|
|
|
elif ext in ["jpg"]: |
|
|
|
url = self.image_processor.process_image(url, "jpeg", source_dir, **additional_args) |
|
|
|
url = self.imageProcessor.process_image(url, "jpeg", source_dir, **additional_args) |
|
|
|
else: |
|
|
|
url = self.image_processor.process_image(url, "png", source_dir, **additional_args) |
|
|
|
url = self.imageProcessor.process_image(url, "png", source_dir, **additional_args) |
|
|
|
|
|
|
|
# Srcset generation - multiple alternative sizes of images browsers can |
|
|
|
# choose from. |
|
|
@ -168,16 +168,16 @@ class HTML_generator(Output_generator): |
|
|
|
# This is inspired by @vojta001's blogPhoto shortcode he made for |
|
|
|
# patek.cz: |
|
|
|
# https://gitlab.com/patek-devs/patek.cz/-/blob/master/themes/patek/layouts/shortcodes/blogPhoto.html |
|
|
|
width, height = self.image_processor.get_image_size(url, [self.image_processor.public_dir]) |
|
|
|
width, height = self.imageProcessor.get_image_size(url, [self.imageProcessor.public_dir]) |
|
|
|
sizes = [(640, 360, 85), (1280, 720, 85), (1920, 1080, 90)] # (widht, height, quality) |
|
|
|
for size in sizes: |
|
|
|
if width <= size[0] and height <= size[1]: |
|
|
|
srcset.append((f'{self.image_processor.web_path}/{url}', f'{width}w')) |
|
|
|
srcset.append((f'{self.imageProcessor.web_path}/{url}', f'{width}w')) |
|
|
|
break |
|
|
|
quality = size[2] if ext == "jpeg" else None |
|
|
|
srcset.append((f'{self.image_processor.web_path}/{self.image_processor.process_image(url, ext, self.image_processor.public_dir, width=size[0], height=size[1], quality=quality)}', f'{size[0]}w')) |
|
|
|
srcset.append((f'{self.imageProcessor.web_path}/{self.imageProcessor.process_image(url, ext, self.imageProcessor.public_dir, width=size[0], height=size[1], quality=quality)}', f'{size[0]}w')) |
|
|
|
|
|
|
|
url = self.image_processor.web_path + "/" + url |
|
|
|
url = self.imageProcessor.web_path + "/" + url |
|
|
|
|
|
|
|
attributes = self.common_attributes(e) |
|
|
|
if "width" in e.attributes: |
|
|
@ -187,7 +187,7 @@ class HTML_generator(Output_generator): |
|
|
|
attributes["alt"] = e.title |
|
|
|
else: |
|
|
|
fake_out = io.StringIO() |
|
|
|
HTML_generator(fake_out, self.katex_client, self.image_processor).generate(e.content) |
|
|
|
HTMLGenerator(fake_out, self.katexClient, self.imageProcessor).generate(e.content) |
|
|
|
attributes["alt"] = fake_out.getvalue() |
|
|
|
|
|
|
|
if len(srcset) != 0: |
|
|
@ -202,9 +202,9 @@ class HTML_generator(Output_generator): |
|
|
|
self.generate(link) |
|
|
|
|
|
|
|
def generate_Group(self, e: Group): |
|
|
|
self.katex_client.begingroup() |
|
|
|
self.katexClient.begingroup() |
|
|
|
self.generate(e.content) |
|
|
|
self.katex_client.endgroup() |
|
|
|
self.katexClient.endgroup() |
|
|
|
|
|
|
|
def generate_Plain(self, e: Plain): |
|
|
|
self.generate(e.content) |
|
|
@ -234,7 +234,7 @@ class HTML_generator(Output_generator): |
|
|
|
"DisplayMath": True, |
|
|
|
"InlineMath": False |
|
|
|
} |
|
|
|
self.writeln(self.katex_client.render(e.text, {"displayMode": formats[e.format]})) |
|
|
|
self.writeln(self.katexClient.render(e.text, {"displayMode": formats[e.format]})) |
|
|
|
|
|
|
|
def generate_RawInline(self, e: RawInline): |
|
|
|
if e.format == "html": |
|
|
|