From 24f877565df3e11cabc54fa607ca5c3c7cb46ab2 Mon Sep 17 00:00:00 2001 From: Greenscreener Date: Wed, 2 Aug 2023 18:09:02 +0200 Subject: [PATCH] =?UTF-8?q?Highlighting=20je=20nyn=C3=AD=20v=C5=BEdy=20inl?= =?UTF-8?q?ine,=20a=C5=A5=20tam=20nen=C3=AD=20t=C5=99eba=20d=C4=9Blat=20ta?= =?UTF-8?q?kov=C3=A1=20ob=C5=99=C3=AD=20magie=20s=20zji=C5=A1=C5=A5ov?= =?UTF-8?q?=C3=A1n=C3=ADm,=20jestli=20pou=C5=BE=C3=ADv=C3=A1me=20defaultn?= =?UTF-8?q?=C3=AD=20styl=20nebo=20ne.=20Mo=C5=BEn=C3=A1=20by=20bylo=20fajn?= =?UTF-8?q?=20to=20n=C4=9Bjak=20um=C4=9Bt=20overridovat.=20Men=C5=A1=C3=AD?= =?UTF-8?q?=20fixy.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/formatitko/formatitko.py | 6 +++--- src/formatitko/html_generator.py | 8 ++++---- src/formatitko/output_generator.py | 8 ++++---- src/formatitko/transform_processor.py | 6 +----- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/formatitko/formatitko.py b/src/formatitko/formatitko.py index 503f7ff..a31931a 100755 --- a/src/formatitko/formatitko.py +++ b/src/formatitko/formatitko.py @@ -61,9 +61,9 @@ def main(): # Generate HTML and TeX out of the transformed document #open(args.output_html, "w").write(html(doc, katexClient, imageProcessor)) #open(args.output_tex, "w").write(tex(doc, imageProcessor)) - # HTMLGenerator(sys.stdout, katexClient, imageProcessor).generate(doc) - OutputGenerator(open("/tmp/doc1", "w")).generate(doc1) - OutputGenerator(open("/tmp/doc2", "w")).generate(doc2) + HTMLGenerator(sys.stdout, katexClient, imageProcessor).generate(doc2) + #OutputGenerator(open("/tmp/doc1", "w")).generate(doc1) + #OutputGenerator(open("/tmp/doc2", "w")).generate(doc2) if args.debug: print(show(doc)) diff --git a/src/formatitko/html_generator.py b/src/formatitko/html_generator.py index 7380a1b..f366998 100644 --- a/src/formatitko/html_generator.py +++ b/src/formatitko/html_generator.py @@ -97,8 +97,8 @@ class HTMLGenerator(OutputGenerator): pass def generate_Doc(self, e: Doc): - formatter = HtmlFormatter(style=e.get_metadata("highlight-style") if e.get_metadata("highlight-style") is not None else "default") - self.generate_simple_tag(tag="style", attributes={}, content=formatter.get_style_defs(".highlight")) + # formatter = HtmlFormatter(style=e.get_metadata("highlight-style") if e.get_metadata("highlight-style") is not None else "default") + # self.generate_simple_tag(tag="style", attributes={}, content=formatter.get_style_defs(".highlight")) self.generate_simple_tag(e, tag="main") def generate_CodeBlock(self, e: CodeBlock): @@ -115,7 +115,7 @@ class HTMLGenerator(OutputGenerator): warnings.warn(f"Syntax highligher does not have lexer for element with these classes: {e.classes}", UserWarning) if lexer: - formatter = HtmlFormatter(style=e.attributes["style"]) + formatter = HtmlFormatter(style=e.attributes["style"], noclasses=True) result = highlight(e.text, lexer, formatter) self.writeraw(result) else: @@ -127,7 +127,7 @@ class HTMLGenerator(OutputGenerator): additional_args = self.get_image_processor_args(e.attributes) # The directory of the current file, will also look for images there. - source_dir = e.attributes["source_dir"] + source_dir = self.context.dir _, ext = os.path.splitext(url) ext = ext[1:] diff --git a/src/formatitko/output_generator.py b/src/formatitko/output_generator.py index fb64101..b898365 100644 --- a/src/formatitko/output_generator.py +++ b/src/formatitko/output_generator.py @@ -20,7 +20,7 @@ class OutputGenerator: self.indent_str = indent_str self.indent_level = initial_indent_level self._at_start_of_line = True - self.current_context = None + self.context = None self.TYPE_DICT_MISC = { TableRow: self.generate_TableRow, @@ -89,8 +89,8 @@ class OutputGenerator: def generate(self, e: Union[Element, ListContainer, list[Union[Element, ListContainer]]]): if isinstance(e, Group): - old_context = self.current_context - self.current_context = e.context + old_context = self.context + self.context = e.context if isinstance(e, list): self.generate_list(e) elif isinstance(e, ListContainer): @@ -105,7 +105,7 @@ class OutputGenerator: except KeyError: raise UnknownElementError(type(e)) if isinstance(e, Group): - self.current_context = old_context + self.context = old_context def escape_special_chars(self, text: str) -> str: return text diff --git a/src/formatitko/transform_processor.py b/src/formatitko/transform_processor.py index c5d4311..b0032cf 100644 --- a/src/formatitko/transform_processor.py +++ b/src/formatitko/transform_processor.py @@ -31,6 +31,7 @@ class TransformProcessor: def __init__(self, root_file_path: str): self.context: Context = None self.root_file_path = root_file_path + self.root_highlight_style = "default" self.TYPE_DICT = { TableRow: self.transform_TableRow, @@ -325,7 +326,6 @@ class TransformProcessor: "sk": "cs", None: None } - print(self.context.get_metadata("language")) return FQuoted(*e.content, quote_type=e.quote_type, style=quote_styles[self.context.get_metadata("language")]) def transform_Image(self, e: Image) -> Image: @@ -458,10 +458,6 @@ class TransformProcessor: e.attributes["highlight"] = self.context.get_metadata("highlight") if self.context.get_metadata("highlight") is not None else True if not "style" in e.attributes: e.attributes["style"] = self.context.get_metadata("highlight-style") if self.context.get_metadata("highlight-style") is not None else "default" - e.attributes["noclasses"] = False - # I think this is supposed to enable inline styles for highlighting when the style differs from the document, but it clearly doesn't work. a) HTML_generator never accesses it and b) Only the top-level document contains a style so you have to ask the top level context, not the current context. - else: - e.attributes["noclasses"] = True return e def transform_Command(self, e: Command) -> Union[Div, Span]: