Skip to content

Commit

Permalink
fix: in pygments_render replace [] with numeric codes
Browse files Browse the repository at this point in the history
This fixes #190.
  • Loading branch information
redimp committed Jan 26, 2025
1 parent cc80a5c commit 666cfd0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions otterwiki/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ def pygments_render(code, lang, linenumbers=False):
)
linenos = "table" if linenumbers else None
formatter = CodeHtmlFormatter(classprefix=".highlight ", linenos=linenos)
return highlight(code, lexer, formatter)
html = highlight(code, lexer, formatter)
# make sure wikilinks are not present in the code block
html = (
html.replace("'", "'")
.replace("[", "[")
.replace("]", "]")
)
return html


def hidemagicword(text):
Expand Down Expand Up @@ -161,16 +168,17 @@ def clean_html(html: str) -> str:
break
try:
if any(
x in element.attrs.keys()
for x in REMOVE_ATTRIBUTES # pyright: ignore
x in element.attrs.keys() # pyright: ignore
for x in REMOVE_ATTRIBUTES
):
_escape = True
break
except AttributeError:
break
continue
if _escape:
# take nom prisoners
html = escape(html)

return html


Expand Down Expand Up @@ -212,11 +220,12 @@ def block_code(self, code, info=None):
prefix = ""
linenumbers = False
if not info or not len(info):
return (
html = (
'\n'
+ _pre_copy_to_clipboard_tag()
+ '{}</pre></div>\n'.format(mistune.escape(code.strip()))
)
return html
if cursormagicword in info:
info = info.replace(cursormagicword, "")
prefix = cursormagicword
Expand Down Expand Up @@ -372,7 +381,7 @@ def markdown(self, text, cursor=None, **kwargs):
elif cursor is not None:
html = self.htmlcursor + html

text = chain_hooks("renderer_html_postprocess", text)
html = chain_hooks("renderer_html_postprocess", html)

# clean magicword out of toc
toc = [
Expand Down

0 comments on commit 666cfd0

Please sign in to comment.