Markdown : restyle inline code for the dark theme

Markdig.Wpf's default inline-code style applies a light Background +
"fancy" Foreground that becomes a near-illegible mustard-on-charcoal
mess in our dark theme.

Detect inline code by its FontFamily (Consolas / Courier / Typewriter,
applied by Markdig's default style) and rebrand:
  Background = #1A1F2A  (dark, blends with card)
  Foreground = #CDD6E4  (soft off-white, easy contrast)
  FontFamily = Cascadia Code, Consolas, monospace

Affects both the UpdateAvailableDialog and the ReleaseNotesViewerDialog
since they share BuildThemedDocument.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-03 10:25:37 +02:00
parent 89c78c9b37
commit 6d11b43d17

View File

@@ -102,6 +102,24 @@ internal static class MarkdownTheming
foreach (var i in h.Inlines.ToList()) foreach (var i in h.Inlines.ToList())
ApplyToInline(i, accent, fgSecondary, accent); ApplyToInline(i, accent, fgSecondary, accent);
break; break;
case Run r:
// Markdig.Wpf rend `inline code` en tant que <Run> avec un Style
// par défaut qui pose un Background clair + Foreground "fancy" — illisible
// sur notre thème sombre. On détecte le code inline par sa FontFamily
// (monospace appliquée par le style Markdig) et on rebadge avec des couleurs
// qui matchent le reste de la UI : fond noir foncé + texte primaire.
var fontFamilyName = r.FontFamily?.Source ?? string.Empty;
if (fontFamilyName.Contains("Consolas", StringComparison.OrdinalIgnoreCase)
|| fontFamilyName.Contains("Courier", StringComparison.OrdinalIgnoreCase)
|| fontFamilyName.Contains("Typewriter", StringComparison.OrdinalIgnoreCase))
{
r.Background = new SolidColorBrush(Color.FromRgb(0x1A, 0x1F, 0x2A));
r.Foreground = new SolidColorBrush(Color.FromRgb(0xCD, 0xD6, 0xE4));
r.FontFamily = new FontFamily("Cascadia Code, Consolas, monospace");
}
break;
case Span s: case Span s:
foreach (var i in s.Inlines.ToList()) foreach (var i in s.Inlines.ToList())
ApplyToInline(i, fg, fgSecondary, accent); ApplyToInline(i, fg, fgSecondary, accent);