mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[SVGPreview]Handle comments properly (#28863)
* [SVGPreview] Handle comments properly * f: spelling * f: add tolerance to the bitmap eq test * f: remove bitmap eq testing, since it doesn't work on CI for some reason * f: parsing issue
This commit is contained in:
@@ -119,7 +119,7 @@ namespace Common.Utilities
|
||||
|
||||
while ((index = s.IndexOf('<', index)) != -1)
|
||||
{
|
||||
if (index < s.Length - 1 && s[index + 1] != '?')
|
||||
if (index < s.Length - 1 && s[index + 1] != '?' && s[index + 1] != '!')
|
||||
{
|
||||
return index;
|
||||
}
|
||||
@@ -130,11 +130,11 @@ namespace Common.Utilities
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int FindFirstXmlCloseTagIndex(string s)
|
||||
private static int FindFirstXmlCloseTagIndex(string s, int openTagIndex)
|
||||
{
|
||||
int index = 1;
|
||||
|
||||
while ((index = s.IndexOf('>', index)) != -1)
|
||||
while ((index = s.IndexOf('>', openTagIndex)) != -1)
|
||||
{
|
||||
if (index > 0 && s[index - 1] != '?')
|
||||
{
|
||||
@@ -160,7 +160,7 @@ namespace Common.Utilities
|
||||
return stringSvgData;
|
||||
}
|
||||
|
||||
int firstXmlCloseTagIndex = FindFirstXmlCloseTagIndex(stringSvgData);
|
||||
int firstXmlCloseTagIndex = FindFirstXmlCloseTagIndex(stringSvgData, firstXmlOpenTagIndex);
|
||||
if (firstXmlCloseTagIndex == -1)
|
||||
{
|
||||
return stringSvgData;
|
||||
@@ -192,13 +192,18 @@ namespace Common.Utilities
|
||||
styleIndex -= numRemoved;
|
||||
}
|
||||
|
||||
firstXmlCloseTagIndex -= numRemoved;
|
||||
|
||||
stringSvgData = RemoveAttribute(stringSvgData, heightIndex, HeightAttribute, out numRemoved);
|
||||
if (styleIndex != -1 && styleIndex > heightIndex)
|
||||
{
|
||||
styleIndex -= numRemoved;
|
||||
}
|
||||
|
||||
firstXmlCloseTagIndex -= numRemoved;
|
||||
|
||||
stringSvgData = RemoveAttribute(stringSvgData, styleIndex, StyleAttribute, out numRemoved);
|
||||
firstXmlCloseTagIndex -= numRemoved;
|
||||
|
||||
width = CheckUnit(width);
|
||||
height = CheckUnit(height);
|
||||
@@ -213,7 +218,7 @@ namespace Common.Utilities
|
||||
scaling += $" _height:expression(this.scrollHeight > {heightR} ? " {height}" : "auto"); _width:expression(this.scrollWidth > {widthR} ? "{width}" : "auto");";
|
||||
|
||||
string newStyle = $"style=\"{scaling}{centering}{oldStyle}\"";
|
||||
int insertAt = stringSvgData.IndexOf(">", StringComparison.InvariantCultureIgnoreCase);
|
||||
int insertAt = firstXmlCloseTagIndex;
|
||||
|
||||
stringSvgData = stringSvgData.Insert(insertAt, " " + newStyle);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user