From fa2cf0a5cc5265139d7b086f52673445056538cd Mon Sep 17 00:00:00 2001 From: Greenscreener Date: Wed, 20 Sep 2023 23:58:41 +0200 Subject: [PATCH] Fixed html escape of code blocks. --- src/formatitko/html_generator.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/formatitko/html_generator.py b/src/formatitko/html_generator.py index ea8b56e..25f3305 100644 --- a/src/formatitko/html_generator.py +++ b/src/formatitko/html_generator.py @@ -1,4 +1,4 @@ -from panflute import Cite, Emph, Image, LineBreak, Link, Math, Note, RawInline, SmallCaps, Str, Strikeout, Subscript, Superscript, Underline +from panflute import Cite, Code, Emph, Image, LineBreak, Link, Math, Note, RawInline, SmallCaps, Str, Strikeout, Subscript, Superscript, Underline from panflute import BulletList, Citation, CodeBlock, Definition, DefinitionItem, DefinitionList, Header, HorizontalRule, LineBlock, LineItem, ListItem, Null, OrderedList, Para, Plain, RawBlock, TableBody, TableFoot, TableHead from panflute import TableRow, TableCell, Caption, Doc from panflute import ListContainer, Element @@ -37,7 +37,7 @@ class HTMLGenerator(OutputGenerator): def escape_special_chars(self, text: str) -> str: text = text.replace("&", "&") text = text.replace("<", "<") - text = text.replace(">", "&rt;") + text = text.replace(">", ">") text = text.replace("\"", """) text = text.replace("'", "'") # text = text.replace(" ", " ") # Don't replace no-break spaces with HTML escapes, because we trust unicode? @@ -125,8 +125,13 @@ class HTMLGenerator(OutputGenerator): result = highlight(e.text, lexer, formatter) self.writeraw(result) else: + e.text = self.escape_special_chars(e.text) self.generate_simple_tag(e, tag="pre") + def generate_Code(self, e: Code): + e.text = self.escape_special_chars(e.text) + self.generate_simple_tag(e) + def generate_Image(self, e: Image): url = e.url