├── src └── syntax_highlighting_ng │ ├── _version.py │ ├── config.json │ ├── icons │ └── button.png │ ├── libs │ └── pygments-2.18.0-py3-none-any.whl │ ├── consts.py │ ├── config.md │ ├── __init__.py │ ├── html_render.py │ ├── config.py │ ├── CHANGELOG.md │ ├── main.py │ └── LICENSE.txt ├── Dockerfile ├── tests ├── README.md ├── environment.yaml ├── test_const.py ├── assets │ └── test_html_render │ │ ├── simple.html │ │ └── conftest.html ├── test_anki.py ├── test_html_render.py └── conftest.py ├── requirements.txt ├── CONTRIBUTING.md ├── TODO.md ├── .pre-commit-config.yaml ├── pyproject.toml ├── CHANGELOG.md ├── NOTES.md ├── make.py ├── README.md └── LICENSE /src/syntax_highlighting_ng/_version.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | __version__ = "0.0.2" 3 | -------------------------------------------------------------------------------- /src/syntax_highlighting_ng/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "hotkey": "Alt+s", 3 | "limitToLangs": [], 4 | "style": "default" 5 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:latest 2 | COPY requirements.txt / 3 | RUN python -m venv /venv 4 | RUN /venv/bin/python -m pip install -r /requirements.txt -------------------------------------------------------------------------------- /src/syntax_highlighting_ng/icons/button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cav71/syntax-highlighting-ng/HEAD/src/syntax_highlighting_ng/icons/button.png -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | ### Tests 2 | 3 | How to run these tests (from the root source directory): 4 | 5 | ```bash 6 | STANDALONE_ADDON=1 PYTHONPATH=src pytest -vvs tests 7 | ``` 8 | -------------------------------------------------------------------------------- /src/syntax_highlighting_ng/libs/pygments-2.18.0-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cav71/syntax-highlighting-ng/HEAD/src/syntax_highlighting_ng/libs/pygments-2.18.0-py3-none-any.whl -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # Please note that these are only build dependencies. They are not 2 | # required to run compiled builds of the add-on within Anki 3 | aab 4 | beautifulsoup4 5 | lxml 6 | mypy 7 | pytest 8 | pytest-cov 9 | pytest-html 10 | ruff 11 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to Contribute to this Project 2 | 3 | Please see the [common contribution guidelines](https://github.com/glutanimate/docs/blob/master/anki/add-ons/CONTRIBUTING.md#how-to-contribute-to-my-anki-add-ons) for my Anki add-ons. 4 | 5 | Thanks! -------------------------------------------------------------------------------- /tests/environment.yaml: -------------------------------------------------------------------------------- 1 | python=3.9 2 | pytest 3 | attrs 4 | jsonschema 5 | six 6 | whichcraft 7 | pygments 8 | ruff 9 | black 10 | mypy 11 | pre-commit 12 | bs4 13 | # need to run also: 14 | # conda uninstall --force rpds-py 15 | # pip install rpds-py aab 16 | -------------------------------------------------------------------------------- /tests/test_const.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | def test_import(fake_anki21): 4 | "test the module import" 5 | import syntax_highlighting_ng 6 | from syntax_highlighting_ng import consts 7 | assert consts.sys_encoding 8 | assert consts.addon_path 9 | assert syntax_highlighting_ng.STANDALONE 10 | -------------------------------------------------------------------------------- /tests/assets/test_html_render/simple.html: -------------------------------------------------------------------------------- 1 |
1a simple one-line
3 |
4 | 
| ", 410 | processed, 411 | " |
| ", processed, " |
1from __future__ import annotations
3 | 2import sys
4 | 3import types
5 | 4from pathlib import Path
6 | 5import pytest
7 | 6
8 | 7
9 | 8@pytest.fixture(scope="function")
10 | 9def assets(request):
11 | 10
12 | 11 class Asset:
13 | 12 def __init__(self):
14 | 13 self.basedir = Path(__file__).parent
15 | 14 self.candidates = [
16 | 15 f"assets/{request.node.module.__name__}",
17 | 16 "assets",
18 | 17 ]
19 | 18 def lookup(self, path: Path | str) -> Path|None:
20 | 19 for candidate in self.candidates:
21 | 20 if (target := (self.basedir / candidate / path)).exists():
22 | 21 return target
23 | 22
24 | 23 def read_text(self, path: Path | str, fallback: str|None=None) -> str|None:
25 | 24 dest = self.lookup(path)
26 | 25 if fallback is not None:
27 | 26 dest = dest or (self.basedir / self.candidates[0] / path)
28 | 27 dest.parent.mkdir(exist_ok=True, parents=True)
29 | 28 dest.write_text(fallback)
30 | 29
31 | 30 return dest.read_text()
32 | 31
33 | 32
34 | 33 return Asset()
35 | 34
36 | 35
37 | 36@pytest.fixture(scope="function")
38 | 37def fake_anki21(monkeypatch):
39 | 38 # monkey patch a fake anki21 module
40 | 39
41 | 40 class Anki(types.ModuleType):
42 | 41 version = "23.10.1"
43 | 42
44 | 43 def pointVersion(self):
45 | 44 return self.point_version()
46 | 45 def point_version(self):
47 | 46 return 231001
48 | 47
49 | 48
50 | 49 class AnkiHooks(types.ModuleType):
51 | 50 def addHook(self):
52 | 51 return 999
53 | 52
54 | 53 class Aqt(types.ModuleType):
55 | 54 pass
56 | 55
57 | 56 class AqtMV(types.ModuleType):
58 | 57 def callme(self):
59 | 58 return 123
60 | 59
61 | 60 replacements = [
62 | 61 ("anki", Anki),
63 | 62 ("anki.hooks", AnkiHooks),
64 | 63 ("aqt", Aqt),
65 | 64 ("aqt.mw", AqtMV),
66 | 65 ]
67 | 66 old = {}
68 | 67 for name, cls in replacements:
69 | 68 old[name] = sys.modules.get(name)
70 | 69 sys.modules[name] = cls(name)
71 | 70 yield old
72 | 71 for name, mod in reversed(old.items()):
73 | 72 if mod:
74 | 73 sys.modules[name] = mod
75 | 74 else:
76 | 75 del sys.modules[name]
77 |
78 |