diff --git a/src/syntax_highlighting/__pycache__/__init__.cpython-39.opt-2.pyc b/src/syntax_highlighting/__pycache__/__init__.cpython-39.opt-2.pyc new file mode 100644 index 0000000..be9d7b5 Binary files /dev/null and b/src/syntax_highlighting/__pycache__/__init__.cpython-39.opt-2.pyc differ diff --git a/src/syntax_highlighting/__pycache__/_version.cpython-39.opt-2.pyc b/src/syntax_highlighting/__pycache__/_version.cpython-39.opt-2.pyc new file mode 100644 index 0000000..3b5d19a Binary files /dev/null and b/src/syntax_highlighting/__pycache__/_version.cpython-39.opt-2.pyc differ diff --git a/src/syntax_highlighting/__pycache__/config.cpython-39.opt-2.pyc b/src/syntax_highlighting/__pycache__/config.cpython-39.opt-2.pyc new file mode 100644 index 0000000..a960630 Binary files /dev/null and b/src/syntax_highlighting/__pycache__/config.cpython-39.opt-2.pyc differ diff --git a/src/syntax_highlighting/__pycache__/consts.cpython-39.opt-2.pyc b/src/syntax_highlighting/__pycache__/consts.cpython-39.opt-2.pyc new file mode 100644 index 0000000..613de63 Binary files /dev/null and b/src/syntax_highlighting/__pycache__/consts.cpython-39.opt-2.pyc differ diff --git a/src/syntax_highlighting/__pycache__/main.cpython-39.opt-2.pyc b/src/syntax_highlighting/__pycache__/main.cpython-39.opt-2.pyc new file mode 100644 index 0000000..1821646 Binary files /dev/null and b/src/syntax_highlighting/__pycache__/main.cpython-39.opt-2.pyc differ diff --git a/src/syntax_highlighting/libs/pygments/formatters/html.py b/src/syntax_highlighting/libs/pygments/formatters/html.py index 2969d50..b97c385 100644 --- a/src/syntax_highlighting/libs/pygments/formatters/html.py +++ b/src/syntax_highlighting/libs/pygments/formatters/html.py @@ -55,7 +55,7 @@ def _get_ttype_class(ttype): CSSFILE_TEMPLATE = '''\ -td.linenos { background-color: #f0f0f0; padding-right: 10px; } +td.linenos { background-color: #; padding-right: 10px; } span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; } pre { line-height: 125%%; } %(styledefs)s @@ -609,7 +609,7 @@ def _wrap_tablelinenos(self, inner): if nocls: yield 0, ('' % self.cssclass + '
' + 'style="background-color: #; padding-right: 10px">' '
' +
                       ls + '
') else: diff --git a/src/syntax_highlighting/main.py b/src/syntax_highlighting/main.py index c4369ac..f3b0eee 100644 --- a/src/syntax_highlighting/main.py +++ b/src/syntax_highlighting/main.py @@ -17,12 +17,9 @@ import os import sys import re -import json from .consts import * # import addon_path # always use shipped pygments library -# FIXME: properly vendorize pygments, lest we interfere with -# other add-ons that might be shipping their own pygments sys.path.insert(0, os.path.join(addon_path, "libs")) from pygments import highlight @@ -34,6 +31,7 @@ from aqt import mw from aqt.editor import Editor from aqt.utils import showWarning +from anki.utils import json from anki.hooks import addHook, wrap from .config import local_conf @@ -406,12 +404,13 @@ def highlight_code(ed): # TODO: understand why this is neccessary else: if centerfragments: - pretty_code = "".join(["
", + pretty_code = "".join(["
", highlight(code, my_lexer, my_formatter), - "
"]) + "

"]) else: - pretty_code = "".join([highlight(code, my_lexer, my_formatter), - "
"]) + pretty_code = "".join(["
", + highlight(code, my_lexer, my_formatter), + "

"]) pretty_code = process_html(pretty_code) @@ -419,20 +418,18 @@ def highlight_code(ed): ed.web.eval("document.execCommand('inserthtml', false, %s);" % json.dumps(pretty_code)) - def process_html(html): """Modify highlighter output to address some Anki idiosyncracies""" # 1.) "Escape" curly bracket sequences reserved to Anki's card template - # system by placing an invisible html tag inbetween - for pattern, replacement in ((r"{{", r"{{"), - (r"}}", r"}}"), - (r"::", r"::")): - html = re.sub(pattern, replacement, html) + + # protect the {{c1::}} clone field + html = re.sub(r"\{\{c\d+::", r"\{\{c\d+::", html) + html = re.sub(r"}}", "}}", html) + return html # Hooks and monkey-patches - if anki21: addHook("setupEditorButtons", onSetupButtons21) Editor.onBridgeCmd = wrap(Editor.onBridgeCmd, onBridgeCmd, "around") diff --git a/src/syntax_highlighting/meta.json b/src/syntax_highlighting/meta.json new file mode 100644 index 0000000..57585fb --- /dev/null +++ b/src/syntax_highlighting/meta.json @@ -0,0 +1 @@ +{"name": "Syntax Highlighting for Code", "mod": 1538875907, "min_point_version": 0, "max_point_version": 0, "branch_index": 0, "disabled": false, "config": {"hotkey": "Alt+s", "limitToLangs": [], "style": "monokai"}} \ No newline at end of file