Highlighting je nyní vždy inline, ať tam není třeba dělat taková obří magie s zjišťováním, jestli používáme defaultní styl nebo ne. Možná by bylo fajn to nějak umět overridovat. Menší fixy.
This commit is contained in:
parent
1a629b2bf9
commit
24f877565d
4 changed files with 12 additions and 16 deletions
|
@ -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))
|
||||
|
|
|
@ -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:]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]:
|
||||
|
|
Loading…
Reference in a new issue