MarkupConverter
MarkupConverter copied to clipboard
RGB color is not supported
Hello,
This project is very good & very useful to me for my WPF application. Perhaps, if I am using a "
" tag with "style='color: rgb(255,90,40);' then it is not getting color and set black or gray color. I have debugged into it and found the issue in "MarkupConverter/htmlcssparser.cs ". There is a function of ParseWhiteSpace in which color is converting but I can't understand why there is :
else if (styleValue.Substring(nextIndex, 3).ToLower() == "rbg")
{
// Implement real rgb() color parsing
while (nextIndex < styleValue.Length && styleValue[nextIndex] != ')')
{
nextIndex++;
}
if (nextIndex < styleValue.Length)
{
nextIndex++; // to skip ')'
}
color = "gray"; // return bogus color
}
In this "rbg" is by mistake or some other reason (it should be rgb on rbg) - I don't know.
Anyway, I have resolved it by adding following code:
//Added by Sachin for converting rgb color to hex and return
else if (styleValue.Substring(nextIndex, 3).ToLower() == "rgb")
{
// Implement real rgb() color parsing
startIndex = 4;
string temp_color = styleValue.Substring(startIndex, styleValue.Length - 1 - startIndex);
string[] rgb = temp_color.Split(',');
color = "#" + (byte.Parse(rgb[0])).ToString("X2") + (byte.Parse(rgb[1])).ToString("X2") + (byte.Parse(rgb[2])).ToString("X2");
}
Thanks,
Sachin
Please submit a PR and I will gladly accept
If the merge is done, issue was not resolved?