You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Background color of text: highlighting or shading? #79
Currently, the implementation of background color on text is by using shading:
if (!colorValue.IsEmpty)
{
// change the way the background-color renders. It now uses Shading instead of Highlight.
// Changes brought by Wude on http://html2openxml.codeplex.com/discussions/277570
styleAttributes.Add(new Shading { Val = ShadingPatternValues.Clear, Fill = colorValue.ToHexString() });
}
This makes sense if you're talking about table cell backgrounds etc. However, if your goal is to highlight text, users can become confused because in normal Word operations text is highlighted and not shaded.
My proposal is to implement a feature that checks if the color is applied on a span (meaning text; highlight) or on a different item, which would then shade it. I would like to know your opinions. If you agree, I will create a PR.
This is a good compromise between the original implementation and the change brought by Wude.
I'm unsure whether it is a good idea to be too kind with users and try to find the nearest matching color. You will always find people complaining their color do not match.
Also, your limited the behavior to only <span> and this could be a little less restricted (b,i,u,ins,del,) etc.. Maybe try the opposite condition and limit for p,table,pre,div.
I'm unsure whether it is a good idea to be too kind with users and try to find the nearest matching color. You will always find people complaining their color do not match.
What would you suggest? Just casting the color name to the enum? And if it's a hex/rgb/hsl color just use the shading option?
Also, your limited the behavior to only and this could be a little less restricted (b,i,u,ins,del,) etc.. Maybe try the opposite condition and limit for p,table,pre,div.
Good idea. I should've time in the upcoming days to change this.
I like your idea to capitalize on the parsing of HtmlColor.
You could create an extension method on HtmlColor to convert to HighlightColorValues.
Implement IEquatable<T> on HtmlColor to allow finding them in the Dictionary<HtmlColor, HighlightColorValues> mapping. (Just add the Interface because the method Equals already exists)
You could also rely on HtmlColorTranslator.FromHtml(string namedColor) for easy setup.
If this is correctly described in the Wiki, I see no problem. I will handle that part myself.
I will just requires you to create a test case to validate your feature. This help me greatly to move forward to v3 and validate my refactoring.
Thank you for your support
Hi DynaSpan, did you find some times to implement this ? I'm very interested in your proposal...
If you don't know how to write the test case, I will handle it myself
I did some work a time ago, but since then I bought a house and it's been incredibly busy at work. I hope to find some time the upcoming weeks to look at the PR.
Hello, no update so far. I didn't proceed furthermore because I wasn't sure: highlight will seriously reduce the number of possible colours, while shading is more flexible.
Visually, I can't see anything difference between Shading and Highlighting.
The code has deeply changed since your PR. The code is cleaner and simpler now but you will to revisit your code.
What I would suggest is:
In PhrasingElementExpression, if the background-color matches a known colour (by name, hsl or rgb values), use Highlighting, otherwise fallback on Shading.
What do you think?
It's true that visually there's no difference, however I notice it when we highlight text in our WYSIWYG editor that it becomes a shading in Word. This confuses some of our the people that work with it and is not intuitive.
Maybe we can add a feature flag to enable highlighting? In that case, we could make the feature flag an enum between not activated, only matches and all.
When not activated, it will always use shading. When only matches, it will only highlight if the color is a string and matches the enum, and all would then convert any RGB/HSL values to the nearest available color.
Activity
DynaSpan commentedon Sep 22, 2020
I've created an implementation of this idea in my fork: feature/text-highlighting@ebce9dd
onizet commentedon Sep 23, 2020
This is a good compromise between the original implementation and the change brought by Wude.
I'm unsure whether it is a good idea to be too kind with users and try to find the nearest matching color. You will always find people complaining their color do not match.
Also, your limited the behavior to only
<span>and this could be a little less restricted (b,i,u,ins,del,) etc.. Maybe try the opposite condition and limit forp,table,pre,div.DynaSpan commentedon Sep 24, 2020
What would you suggest? Just casting the color name to the enum? And if it's a hex/rgb/hsl color just use the shading option?
Good idea. I should've time in the upcoming days to change this.
onizet commentedon Sep 24, 2020
I like your idea to capitalize on the parsing of HtmlColor.
You could create an extension method on HtmlColor to convert to
HighlightColorValues.Implement
IEquatable<T>on HtmlColor to allow finding them in theDictionary<HtmlColor, HighlightColorValues>mapping. (Just add the Interface because the methodEqualsalready exists)You could also rely on
HtmlColorTranslator.FromHtml(string namedColor)for easy setup.If this is correctly described in the Wiki, I see no problem. I will handle that part myself.
I will just requires you to create a test case to validate your feature. This help me greatly to move forward to v3 and validate my refactoring.
Thank you for your support
onizet commentedon Jan 21, 2021
Hi DynaSpan, did you find some times to implement this ? I'm very interested in your proposal...
If you don't know how to write the test case, I will handle it myself
DynaSpan commentedon Jan 21, 2021
Hi Onizet,
I did some work a time ago, but since then I bought a house and it's been incredibly busy at work. I hope to find some time the upcoming weeks to look at the PR.
onizet commentedon Jan 22, 2021
Thank you for your swift reply. Your situation sounds very familiar to me :)
jeevasusej commentedon May 19, 2023
It's been one year. Do we have any update on this?
DynaSpan commentedon Nov 11, 2025
Hi @onizet
Has this been fixed? Otherwise I can prepare a PR :)
onizet commentedon Nov 12, 2025
Hello, no update so far. I didn't proceed furthermore because I wasn't sure: highlight will seriously reduce the number of possible colours, while shading is more flexible.
Visually, I can't see anything difference between Shading and Highlighting.
The code has deeply changed since your PR. The code is cleaner and simpler now but you will to revisit your code.
What I would suggest is:
In PhrasingElementExpression, if the background-color matches a known colour (by name, hsl or rgb values), use Highlighting, otherwise fallback on Shading.
What do you think?
DynaSpan commentedon Nov 12, 2025
Hi,
It's true that visually there's no difference, however I notice it when we highlight text in our WYSIWYG editor that it becomes a shading in Word. This confuses some of our the people that work with it and is not intuitive.
Maybe we can add a feature flag to enable highlighting? In that case, we could make the feature flag an enum between not activated, only matches and all.
When
not activated, it will always use shading. Whenonly matches, it will only highlight if the color is a string and matches the enum, andallwould then convert any RGB/HSL values to the nearest available color.onizet commentedon Nov 12, 2025
This enum looks like a good compromise between colour fidelity and OpenXml possibilities. Go for it 👍