From afaad6165269b5cf06e7fe778208cf99b7b5149b Mon Sep 17 00:00:00 2001 From: Daniel Lo Nigro Date: Sun, 31 Mar 2024 21:09:31 -0700 Subject: [PATCH] Small fixes for HtmlClassFormatter: - Background colour wasn't converted to HTML colour format - Sort styles by name, which also has the effect of grouping related styles together by prefix (e.g. html, json, xml) - Background colour was incorrectly added using `color` instead of `background-color` --- ColorCode.HTML/HtmlClassFormatter.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ColorCode.HTML/HtmlClassFormatter.cs b/ColorCode.HTML/HtmlClassFormatter.cs index 15852c3..6cadac4 100644 --- a/ColorCode.HTML/HtmlClassFormatter.cs +++ b/ColorCode.HTML/HtmlClassFormatter.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using ColorCode.Common; using ColorCode.Parsing; using System.Text; @@ -65,9 +66,9 @@ public string GetCSSString() var str = new StringBuilder(); var plainText = Styles[ScopeName.PlainText]; - if (!string.IsNullOrWhiteSpace(plainText?.Background)) str.Append($"body{{background-color:{plainText.Background};}}"); + if (!string.IsNullOrWhiteSpace(plainText?.Background)) str.Append($"body{{background-color:{plainText.Background.ToHtmlColor()};}}"); - foreach (var style in Styles) + foreach (var style in Styles.OrderBy(style => style.ReferenceName)) { str.Append($" .{style.ReferenceName}{{"); @@ -75,7 +76,7 @@ public string GetCSSString() str.Append($"color:{style.Foreground.ToHtmlColor()};"); if (!string.IsNullOrWhiteSpace(style.Background)) - str.Append($"color:{style.Background.ToHtmlColor()};"); + str.Append($"background-color:{style.Background.ToHtmlColor()};"); if (style.Italic) str.Append("font-style: italic;");