Private
Public Access
0
0

feat(markdown): apply active theme syntax palette to code blocks

This commit is contained in:
2026-06-04 23:13:33 -04:00
parent df2e82a82d
commit 1cb68e4e3f
2 changed files with 32 additions and 0 deletions
+7
View File
@@ -73,6 +73,13 @@ class MarkdownRenderer:
# Optional callback for custom local link handling (e.g., opening in IDE)
self.on_local_link: Optional[Callable[[str], None]] = None
# Apply the current theme's syntax palette on construction so new
# editors we create pick up the right colors. The renderer is re-created
# when the theme changes (see theme_2 module-load behavior).
from src import theme_2
palette_id = theme_2.get_syntax_palette_for_theme(theme_2.get_current_palette())
theme_2.apply_syntax_palette(palette_id)
# Language mapping for ImGuiColorTextEdit
self._lang_map = {
"python": _get_language_id("python"),
+25
View File
@@ -54,3 +54,28 @@ def test_duplicate_table_content_both_get_replaced():
full = "".join(str(c) for c in mock_md.render.call_args_list)
assert "| A | B |" not in full, f"Raw table text leaked on duplicate: {full!r}"
def test_render_applies_current_syntax_palette(monkeypatch):
"""When a theme is active, the render path should call apply_syntax_palette
so new code-block editors pick up the theme's syntax palette."""
from unittest.mock import patch
from src import theme_2 as theme
class _Tracker:
last_palette = None
last_call = False
def fake_apply(palette_id):
_Tracker.last_palette = palette_id
_Tracker.last_call = True
monkeypatch.setattr(theme, "apply_syntax_palette", fake_apply)
monkeypatch.setattr(theme, "_current_palette", "solarized_dark")
monkeypatch.setattr(theme, "get_syntax_palette_for_theme", lambda n: "dark")
from src.markdown_helper import MarkdownRenderer
with patch("src.markdown_helper.imgui_md") as mock_md, patch("src.markdown_helper.imgui") as mock_imgui, patch("src.markdown_table.imgui") as mock_table_imgui:
_mock_table_calls(mock_table_imgui)
MarkdownRenderer().render("hello world", context_id="p")
assert _Tracker.last_call, "expected apply_syntax_palette to be called"