Skip to content

Commit 715f038

Browse files
committed
Fixed issues #80 #82
1 parent 382b4bf commit 715f038

File tree

12 files changed

+144
-15
lines changed

12 files changed

+144
-15
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 0.16.2
2+
3+
Released on Thursday, November 4 2021.
4+
5+
- Fixed issue with unbalanced grid areas and rows (#82)
6+
- Fixed small numbers to be transformed into negative exponentials (#80)
7+
18
# 0.16.1
29

310
Released on Wednesday, August 11 2021.

src/AngleSharp.Css.Tests/Declarations/CssMarginProperty.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ public void CssMarginLeftLengthLegal()
1818
Assert.AreEqual("15px", property.Value);
1919
}
2020

21+
[Test]
22+
public void CssMarginLeftTinyValue_Issue80()
23+
{
24+
var snippet = "margin-left: 0.00001px";
25+
var property = ParseDeclaration(snippet);
26+
Assert.AreEqual("margin-left", property.Name);
27+
Assert.IsFalse(property.IsImportant);
28+
Assert.IsFalse(property.IsInherited);
29+
Assert.IsTrue(property.HasValue);
30+
Assert.AreEqual("0.00001px", property.Value);
31+
}
32+
2133
[Test]
2234
public void CssMarginLeftInitialLegal()
2335
{

src/AngleSharp.Css.Tests/Parsing/StyleSheet.cs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,110 @@ public async Task ParseEmptySheet_Issue42()
1515
var sheet = await parser.ParseStyleSheetAsync(sheetCode);
1616
Assert.IsNotNull(sheet);
1717
}
18+
19+
[Test]
20+
public async Task ParseStyleSheetAndBack_Issue82()
21+
{
22+
var css = @"
23+
.root {
24+
position: absolute;
25+
top: 0;
26+
left: 0;
27+
width: calc(100% - 10px);
28+
height: calc(100% - 10px);
29+
padding: 5px;
30+
}
31+
32+
.container {
33+
width: 100%;
34+
height: 100%;
35+
display: grid;
36+
grid-template-columns: 1fr 1fr;
37+
grid-template-rows: 240px calc(100% - 360px) 100px;
38+
grid-template-areas: 'header info' 'quantity info' 'footerOk footerCancel';
39+
row-gap: 10px;
40+
font-size: 26px;
41+
}
42+
43+
.destination {
44+
grid-area: header;
45+
width: calc(100% - 20px);
46+
height: calc(100% - 20px);
47+
margin: 10px;
48+
display: grid;
49+
grid-template-columns: auto auto auto;
50+
grid-template-rows: 150px 50px;
51+
grid-template-areas:
52+
""sourcerp image destrp""
53+
""sourcele image destle"";
54+
}
55+
56+
.quantitygrid {
57+
width: 100%;
58+
height: 100%;
59+
display: grid;
60+
grid-template-columns: auto auto auto;
61+
grid-template-rows: 150px 100px;
62+
grid-template-areas: 'minus number plus';
63+
}
64+
65+
.headergrid {
66+
width: 100%;
67+
height: 100%;
68+
display: grid;
69+
grid-template-columns: 1fr 1fr 1fr;
70+
grid-template-rows: 1fr 1fr;
71+
grid-template-areas: 'sourceplace space destinationplace' 'sourcelc space destinationlc';
72+
}
73+
74+
#info td + td {
75+
font-size: 24px;
76+
}
77+
78+
input {
79+
animation-duration: 2s;
80+
font-family: inherit;
81+
background-color: white;
82+
}
83+
84+
td {
85+
padding: 5px;
86+
}
87+
88+
paper-button {
89+
padding: 0;
90+
background-color: var(--kx-dark);
91+
box-sizing: border-box;
92+
display: flex;
93+
align-items: center;
94+
justify-content: center;
95+
color: white;
96+
/*font-weight: bolder;*/
97+
}
98+
99+
@keyframes errorAnimation {
100+
0% {
101+
background-color: white;
102+
}
103+
104+
1% {
105+
background-color: red;
106+
}
107+
108+
100% {
109+
background-color: white;
110+
}
111+
}
112+
113+
input:invalid {
114+
color: red;
115+
}
116+
";
117+
var parser = new CssParser();
118+
var formatter = new MinifyStyleFormatter();
119+
var ss = await parser.ParseStyleSheetAsync(css);
120+
var newCss = ss.ToCss(formatter);
121+
Assert.IsNotNull(newCss);
122+
}
18123
}
19124
}

src/AngleSharp.Css/FormatValue.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace AngleSharp.Css
2+
{
3+
using System;
4+
using System.Globalization;
5+
6+
static class FormatValue
7+
{
8+
public const String DoubleFixedPoint = "0.###################################################################################################################################################################################################################################################################################################################################################";
9+
10+
public static String CssStringify(this Double value) => value.ToString(DoubleFixedPoint, CultureInfo.InvariantCulture);
11+
}
12+
}

src/AngleSharp.Css/Values/Composites/CssGridTemplateValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public String CssText
7373

7474
for (var i = 0; i < rowItems.Length; i++)
7575
{
76-
var area = areas[i];
76+
var area = areas.Length > i ? areas[i] : null;
7777
var item = rowItems[i] as CssTupleValue;
7878

7979
if (item != null && area != null)

src/AngleSharp.Css/Values/Primitives/Angle.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
namespace AngleSharp.Css.Values
22
{
3-
using AngleSharp.Css.Dom;
43
using System;
5-
using System.Globalization;
64

75
/// <summary>
86
/// Represents an angle object.
@@ -66,7 +64,7 @@ public Angle(Double value, Unit unit)
6664
/// <summary>
6765
/// Gets the CSS text representation.
6866
/// </summary>
69-
public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString);
67+
public String CssText => String.Concat(_value.CssStringify(), UnitString);
7068

7169
/// <summary>
7270
/// Gets the value of the angle.

src/AngleSharp.Css/Values/Primitives/Fraction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public Fraction(Double value, Unit unit)
3535
/// <summary>
3636
/// Gets the CSS text representation.
3737
/// </summary>
38-
public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString);
38+
public String CssText => String.Concat(_value.CssStringify(), UnitString);
3939

4040
/// <summary>
4141
/// Gets the value of fraction.

src/AngleSharp.Css/Values/Primitives/Frequency.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace AngleSharp.Css.Values
22
{
33
using System;
4-
using System.Globalization;
54

65
/// <summary>
76
/// Represents a time value.
@@ -35,7 +34,7 @@ public Frequency(Double value, Unit unit)
3534
/// <summary>
3635
/// Gets the CSS text representation.
3736
/// </summary>
38-
public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString);
37+
public String CssText => String.Concat(_value.CssStringify(), UnitString);
3938

4039
/// <summary>
4140
/// Gets the value of frequency.

src/AngleSharp.Css/Values/Primitives/Length.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace AngleSharp.Css.Values
22
{
33
using System;
4-
using System.Globalization;
54

65
/// <summary>
76
/// Represents an absolute length value.
@@ -99,7 +98,7 @@ public String CssText
9998
else
10099
{
101100
var unit = _value == 0.0 ? String.Empty : UnitString;
102-
var val = _value.ToString(CultureInfo.InvariantCulture);
101+
var val = _value.CssStringify();
103102
return String.Concat(val, unit);
104103
}
105104
}

src/AngleSharp.Css/Values/Primitives/Resolution.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
namespace AngleSharp.Css.Values
22
{
33
using System;
4-
using System.Globalization;
54

65
/// <summary>
76
/// Represents a resolution value.
@@ -35,7 +34,7 @@ public Resolution(Double value, Unit unit)
3534
/// <summary>
3635
/// Gets the CSS text representation.
3736
/// </summary>
38-
public String CssText => String.Concat(_value.ToString(CultureInfo.InvariantCulture), UnitString);
37+
public String CssText => String.Concat(_value.CssStringify(), UnitString);
3938

4039
/// <summary>
4140
/// Gets the value of resolution.

0 commit comments

Comments
 (0)