diff --git a/otterwiki/renderer.py b/otterwiki/renderer.py index 6560d7e..e3f5b33 100644 --- a/otterwiki/renderer.py +++ b/otterwiki/renderer.py @@ -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): @@ -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 @@ -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() + '{}\n'.format(mistune.escape(code.strip())) ) + return html if cursormagicword in info: info = info.replace(cursormagicword, "") prefix = cursormagicword @@ -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 = [