From 42d04b77dec9c220e1892aad463c667918be917c Mon Sep 17 00:00:00 2001 From: Greenscreener Date: Tue, 27 Feb 2024 16:24:27 +0100 Subject: [PATCH 1/3] Added title attribute for images, fixed formatting of raw blocks. --- src/formatitko/html_generator.py | 2 ++ src/formatitko/output_generator.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/formatitko/html_generator.py b/src/formatitko/html_generator.py index 2aabe85..e2bc787 100644 --- a/src/formatitko/html_generator.py +++ b/src/formatitko/html_generator.py @@ -194,6 +194,8 @@ class HTMLGenerator(OutputGenerator): attributes["width"] = e.attributes["width"] if "height" in e.attributes: attributes["height"] = e.attributes["height"] + if "title" in e.attributes: + attributes["title"] = e.attributes["title"] if e.title: attributes["alt"] = e.title diff --git a/src/formatitko/output_generator.py b/src/formatitko/output_generator.py index 8e854a3..716e52a 100644 --- a/src/formatitko/output_generator.py +++ b/src/formatitko/output_generator.py @@ -272,9 +272,9 @@ class OutputGenerator: self.write(self.end_tag(tag)) def generate_raw_block_tag(self, tag: str, text: str, attributes: dict[str,str]={}): - self.writeln(self.start_tag(tag, attributes)) + self.writeraw(self.start_tag(tag, attributes)) self.writeraw(text) - self.writeln(self.end_tag(tag)) + self.writeraw(self.end_tag(tag)) def generate_empty_block_tag(self, tag: str, attributes: dict[str,str]={}): self.writeln(self.single_tag(tag, attributes)) From 0e5735cba2f7539a05fbee78ab03b026d94bf969 Mon Sep 17 00:00:00 2001 From: Greenscreener Date: Thu, 7 Mar 2024 17:58:18 +0100 Subject: [PATCH 2/3] Added FileLink element for publishing and linking local files. --- src/formatitko/elements.py | 5 ++++- src/formatitko/html_generator.py | 18 ++++++++++++++++++ src/formatitko/images.py | 3 +++ src/formatitko/nop_processor.py | 7 ++++++- src/formatitko/output_generator.py | 7 +++++-- 5 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/formatitko/elements.py b/src/formatitko/elements.py index 17840f4..0ff016e 100644 --- a/src/formatitko/elements.py +++ b/src/formatitko/elements.py @@ -1,4 +1,4 @@ -from panflute import Quoted +from panflute import Quoted, Link from .command import Command, InlineCommand, BlockCommand, CodeCommand @@ -14,3 +14,6 @@ class FQuoted(Quoted): del kwargs["style"] super().__init__(*args, **kwargs) + +class FileLink(Link): + pass diff --git a/src/formatitko/html_generator.py b/src/formatitko/html_generator.py index e2bc787..e2332c2 100644 --- a/src/formatitko/html_generator.py +++ b/src/formatitko/html_generator.py @@ -19,6 +19,7 @@ from .output_generator import OutputGenerator from .katex import KatexClient from .images import ImageProcessor, ImageProcessorNamespaceSearcher from .util import inlinify +from .elements import FileLink class HTMLGenerator(OutputGenerator): @@ -219,6 +220,23 @@ class HTMLGenerator(OutputGenerator): self.generate(link) + def generate_FileLink(self, e: FileLink): + url = e.url + + # The directory of the current file relative to the current working directory + source_dir = self.context.dir + # The directory of the current file relative to the md file we were called on + rel_dir = self.context.rel_dir + + searcher = self.imageProcessor.get_searcher_by_path(url, rel_dir, source_dir) + url = self.imageProcessor.get_path_without_namespace(url) + + url = self.imageProcessor.process_image(url, "", searcher, self.context) + searcher.publish_image(url) + url = searcher.get_web_path() + "/" + url + + self.generate_Link(Link(*e.content, url=url)) + def generate_InlineGroup(self, e: InlineGroup): self.generate_Group(e) diff --git a/src/formatitko/images.py b/src/formatitko/images.py index c447c30..553ab18 100644 --- a/src/formatitko/images.py +++ b/src/formatitko/images.py @@ -173,6 +173,9 @@ class ImageProcessor: if format == "jpg": format = "jpeg" + if format == "": + format = ext + # Locate all dependencies deps_full = [full_path] for dep in deps: diff --git a/src/formatitko/nop_processor.py b/src/formatitko/nop_processor.py index 8218b2e..b200f5c 100644 --- a/src/formatitko/nop_processor.py +++ b/src/formatitko/nop_processor.py @@ -6,7 +6,7 @@ from panflute import MetaValue from typing import Union, Callable from .whitespace import NBSP -from .elements import FQuoted +from .elements import FQuoted, FileLink from .context import Group, InlineGroup, BlockGroup, Context from .whitespace import Whitespace from .command import BlockCommand, InlineCommand, CodeCommand, Command @@ -88,6 +88,7 @@ class NOPProcessor: Underline: self.transform_Underline, NBSP: self.transform_NBSP, FQuoted: self.transform_FQuoted, + FileLink: self.transform_FileLink, InlineCommand: self.transform_InlineCommand, BlockCommand: self.transform_BlockCommand, @@ -299,6 +300,10 @@ class NOPProcessor: e.content = self.transform(e.content) return e + def transform_FileLink(self, e: FileLink) -> FileLink: + e.content = self.transform(e.content) + return e + def transform_Figure(self, e: Figure) -> Figure: e.content = self.transform(e.content) e.caption = self.transform(e.caption) diff --git a/src/formatitko/output_generator.py b/src/formatitko/output_generator.py index 716e52a..dd051d3 100644 --- a/src/formatitko/output_generator.py +++ b/src/formatitko/output_generator.py @@ -7,7 +7,7 @@ from panflute import stringify from typing import Union, Callable from .whitespace import NBSP -from .elements import FQuoted +from .elements import FQuoted, FileLink from .context import Group, InlineGroup, BlockGroup, Context @@ -127,6 +127,7 @@ class OutputGenerator: Underline: self.generate_Underline, NBSP: self.generate_NBSP, FQuoted: self.generate_FQuoted, + FileLink: self.generate_FileLink, InlineGroup: self.generate_InlineGroup } @@ -367,7 +368,9 @@ class OutputGenerator: self.write("\"") self.generate(e.content) self.write("\"") - + + def generate_FileLink(self, e: FileLink): + self.generate_simple_tag(e) # Inline Elements def generate_Cite(self, e: Cite): From 2a0e90bb9678baa01baad9b64d3e26a5d0e212da Mon Sep 17 00:00:00 2001 From: Greenscreener Date: Thu, 7 Mar 2024 19:47:31 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Quick=20fix=20srcset=C5=AF,=20hodn=C4=9B=20?= =?UTF-8?q?mal=C3=A9=20obr=C3=A1zky=20nenafoukneme=20v=C3=ADc,=20ne=C5=BE?= =?UTF-8?q?=20je=20pot=C5=99eba.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formatitko/html_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatitko/html_generator.py b/src/formatitko/html_generator.py index e2332c2..5104276 100644 --- a/src/formatitko/html_generator.py +++ b/src/formatitko/html_generator.py @@ -205,7 +205,7 @@ class HTMLGenerator(OutputGenerator): HTMLGenerator(fake_out, self.katexClient, self.imageProcessor).generate(e.content) attributes["alt"] = fake_out.getvalue() - if len(srcset) != 0: + if len(srcset) > 1: attributes["src"] = srcset[-1][0] attributes["srcset"] = ", ".join([" ".join(src) for src in srcset]) else: