Browse Source

Default pro highlight

jk-bakalarka
Jiří Kalvoda 9 months ago
parent
commit
41f51bf6fe
  1. 4
      src/formatitko/html_generator.py

4
src/formatitko/html_generator.py

@ -110,7 +110,7 @@ class HTMLGenerator(OutputGenerator):
def generate_CodeBlock(self, e: CodeBlock): def generate_CodeBlock(self, e: CodeBlock):
lexer = None lexer = None
if e.classes and len(e.classes) > 0 and (e.attributes["highlight"] == True or e.attributes["highlight"] == 'True'): if e.classes and len(e.classes) > 0 and (e.attributes.get("highlight", False) in [True, 'True']):
# Syntax highlighting using pygments # Syntax highlighting using pygments
for cl in e.classes: for cl in e.classes:
try: try:
@ -122,7 +122,7 @@ class HTMLGenerator(OutputGenerator):
warnings.warn(f"Syntax highligher does not have lexer for element with these classes: {e.classes}", UserWarning) warnings.warn(f"Syntax highligher does not have lexer for element with these classes: {e.classes}", UserWarning)
if lexer: if lexer:
formatter = HtmlFormatter(style=e.attributes["style"], noclasses=True) formatter = HtmlFormatter(style=e.attributes.get("style", self.context.get_metadata("highlight-style")), noclasses=True)
result = highlight(e.text, lexer, formatter) result = highlight(e.text, lexer, formatter)
self.writeraw(result) self.writeraw(result)
else: else:

Loading…
Cancel
Save