From 58611f3e7f567b015be30b0c85b9df43dc4f2311 Mon Sep 17 00:00:00 2001 From: Flag <40310066+Unstoppablesss@users.noreply.github.com> Date: Wed, 13 Sep 2023 17:49:05 +1000 Subject: [PATCH 1/3] Update html.py It won't let the column of numbers remain white in the background when in night mode, and be able to change dynamically. It becomes more nice to look at. --- src/syntax_highlighting/libs/pygments/formatters/html.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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, ('
'
+ 'style="background-color: #; padding-right: 10px">'
' ' +
ls + ' | ')
else:
From f3dfd25f9184bb3cee255372f9624de74fbf1244 Mon Sep 17 00:00:00 2001
From: Flag <40310066+Unstoppablesss@users.noreply.github.com>
Date: Mon, 2 Oct 2023 18:02:22 +1100
Subject: [PATCH 2/3] Update main.py
# Preventing conflicts with clone templates
---
src/syntax_highlighting/main.py | 22 ++++++++++------------
1 file changed, 10 insertions(+), 12 deletions(-)
diff --git a/src/syntax_highlighting/main.py b/src/syntax_highlighting/main.py
index c4369ac..9d243ca 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(["
"]) else: - pretty_code = "".join([highlight(code, my_lexer, my_formatter), - " "]) + pretty_code = "".join(["
"]) pretty_code = process_html(pretty_code) @@ -424,15 +423,14 @@ 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) + +# Preventing conflicts with clone templates + html = re.sub(r"(\{\{)(?![c\d+:])", r"{{", html) + html = re.sub(r"(?}", html) return html # Hooks and monkey-patches - if anki21: addHook("setupEditorButtons", onSetupButtons21) Editor.onBridgeCmd = wrap(Editor.onBridgeCmd, onBridgeCmd, "around") From 67c0886b62a868174c69c1b6eaff5a714917d91f Mon Sep 17 00:00:00 2001 From: Flag <40310066+Unstoppablesss@users.noreply.github.com> Date: Tue, 3 Oct 2023 22:25:50 +1100 Subject: [PATCH 3/3] Add files via upload --- .../__pycache__/__init__.cpython-39.opt-2.pyc | Bin 0 -> 244 bytes .../__pycache__/_version.cpython-39.opt-2.pyc | Bin 0 -> 192 bytes .../__pycache__/config.cpython-39.opt-2.pyc | Bin 0 -> 3088 bytes .../__pycache__/consts.cpython-39.opt-2.pyc | Bin 0 -> 406 bytes .../__pycache__/main.cpython-39.opt-2.pyc | Bin 0 -> 9686 bytes src/syntax_highlighting/main.py | 9 ++++----- src/syntax_highlighting/meta.json | 1 + 7 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 src/syntax_highlighting/__pycache__/__init__.cpython-39.opt-2.pyc create mode 100644 src/syntax_highlighting/__pycache__/_version.cpython-39.opt-2.pyc create mode 100644 src/syntax_highlighting/__pycache__/config.cpython-39.opt-2.pyc create mode 100644 src/syntax_highlighting/__pycache__/consts.cpython-39.opt-2.pyc create mode 100644 src/syntax_highlighting/__pycache__/main.cpython-39.opt-2.pyc create mode 100644 src/syntax_highlighting/meta.json 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 0000000000000000000000000000000000000000..be9d7b58829b07179c72327b9100beb004f38a62 GIT binary patch literal 244 zcmYe~<>g`kf|_{7)G|f}hQ}ZdGGGF79Dul321ukZq%h_% fC*|aPx z>tvife!2221P&k7OSV&lXzArVK4}jAew&|i4nV9-=b%%vGR`r~yW-?YyvoM^0bze< ANdN!< literal 0 HcmV?d00001 diff --git a/src/syntax_highlighting/main.py b/src/syntax_highlighting/main.py index 9d243ca..f3b0eee 100644 --- a/src/syntax_highlighting/main.py +++ b/src/syntax_highlighting/main.py @@ -418,15 +418,14 @@ 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 + + # protect the {{c1::}} clone field + html = re.sub(r"\{\{c\d+::", r"\{\{c\d+::", html) + html = re.sub(r"}}", "}}", html) -# Preventing conflicts with clone templates - html = re.sub(r"(\{\{)(?![c\d+:])", r"{{", html) - html = re.sub(r"(?}", html) return html # Hooks and monkey-patches 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 |