diff --git a/CHANGELOG.md b/CHANGELOG.md index ddaa5995..76beec50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Released on tbd. - Fixed issue with appended EOF character in `CssText` (#123) - Fixed missing semicolon in `@page` rule (#135) - Fixed integer serialization of keyframe stops (#128) +- Fixed ordering of rows and columns in `grid` and `grid-gap` (#137) # 0.17.0 diff --git a/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs b/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs index 7d366d01..8e956b6b 100644 --- a/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs +++ b/src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs @@ -909,5 +909,21 @@ public void CssGridTemplateLonghands_Issue68() var style = ParseDeclarations(snippet); Assert.AreEqual("grid-template: none", style.CssText); } + + [Test] + public void CssGridPreservesParts_Issue137() + { + var snippet = "grid: 10px / 80px"; + var style = ParseDeclarations(snippet); + Assert.AreEqual("grid: 10px / 80px", style.CssText); + } + + [Test] + public void CssGridGapPreservesParts_Issue137() + { + var snippet = "grid-gap: 10px 80px"; + var style = ParseDeclarations(snippet); + Assert.AreEqual("grid-gap: 10px 80px", style.CssText); + } } } diff --git a/src/AngleSharp.Css/Declarations/GapDeclaration.cs b/src/AngleSharp.Css/Declarations/GapDeclaration.cs index 1512f71c..3fcd63b3 100644 --- a/src/AngleSharp.Css/Declarations/GapDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/GapDeclaration.cs @@ -30,8 +30,8 @@ sealed class GapAggregagtor : IValueAggregator, IValueConverter public ICssValue Merge(ICssValue[] values) { - var col = values[0]; - var row = values[1]; + var row = values[0]; + var col = values[1]; if (row != null || col != null) { diff --git a/src/AngleSharp.Css/Declarations/GridDeclaration.cs b/src/AngleSharp.Css/Declarations/GridDeclaration.cs index d5053f4f..42bfba6e 100644 --- a/src/AngleSharp.Css/Declarations/GridDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/GridDeclaration.cs @@ -6,6 +6,7 @@ namespace AngleSharp.Css.Declarations using AngleSharp.Text; using System; using System.Collections.Generic; + using System.Linq; static class GridDeclaration { @@ -37,11 +38,11 @@ public ICssValue Convert(StringSource source) { var template = source.ParseGridTemplate(); - if (template == null) + if (template is null) { var rows = source.ParseTrackList() ?? source.ParseAutoTrackList(); - if (rows != null) + if (rows is not null) { if (source.SkipSpacesAndComments() == Symbols.Solidus) { @@ -153,30 +154,30 @@ public ICssValue[] Split(ICssValue value) gt.TemplateRows, gt.TemplateColumns, gt.TemplateAreas, - null, - null, - null, - null, - null, - null, - null, + null, //new Identifier(CssKeywords.Auto), + null, //new Identifier(CssKeywords.Auto), + null, //new Identifier(CssKeywords.Row), + null, //Length.Zero, + null, //Length.Zero, + null, //new Identifier(CssKeywords.Normal), + null, //new Identifier(CssKeywords.Normal), }; } else if (value is CssGridValue grid) { - var dense = grid.Rows != null ? CssKeywords.Row : CssKeywords.Column; + var dense = grid.Rows is not null ? CssKeywords.Row : CssKeywords.Column; return new[] { grid.Rows, grid.Columns, - null, - grid.Columns != null ? new CssTupleValue(grid.Sizes) : null, - grid.Rows != null ? new CssTupleValue(grid.Sizes) : null, - grid.IsDense ? new Identifier(dense) as ICssValue : null, - null, - null, - null, - null, + null, //new Identifier(CssKeywords.None), + grid.Columns is not null ? new CssTupleValue(grid.Sizes) : null, //new Identifier(CssKeywords.Auto), + grid.Rows is not null ? new CssTupleValue(grid.Sizes) : null, //new Identifier(CssKeywords.Auto), + grid.IsDense ? new Identifier(dense) : null, + null, //Length.Zero, + null, //Length.Zero, + null, //new Identifier(CssKeywords.Normal), + null, //new Identifier(CssKeywords.Normal), }; } else if (value is Identifier) @@ -186,13 +187,13 @@ public ICssValue[] Split(ICssValue value) value, value, value, - null, - null, - null, - null, - null, - null, - null, + null, //new Identifier(CssKeywords.Auto), + null, //new Identifier(CssKeywords.Auto), + null, //new Identifier(CssKeywords.Row), + null, //Length.Zero, + null, //Length.Zero, + null, //new Identifier(CssKeywords.Normal), + null, //new Identifier(CssKeywords.Normal), }; } diff --git a/src/AngleSharp.Css/Declarations/GridGapDeclaration.cs b/src/AngleSharp.Css/Declarations/GridGapDeclaration.cs index fc0a9b41..f7178963 100644 --- a/src/AngleSharp.Css/Declarations/GridGapDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/GridGapDeclaration.cs @@ -30,8 +30,8 @@ sealed class GridGapAggregagtor : IValueAggregator, IValueConverter public ICssValue Merge(ICssValue[] values) { - var col = values[0]; - var row = values[1]; + var row = values[0]; + var col = values[1]; if (row != null || col != null) { diff --git a/src/AngleSharp.Css/Declarations/GridTemplateAreasDeclaration.cs b/src/AngleSharp.Css/Declarations/GridTemplateAreasDeclaration.cs index 151372a1..9772062f 100644 --- a/src/AngleSharp.Css/Declarations/GridTemplateAreasDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/GridTemplateAreasDeclaration.cs @@ -11,6 +11,7 @@ static class GridTemplateAreasDeclaration public static readonly String[] Shorthands = new[] { + PropertyNames.Grid, PropertyNames.GridTemplate, }; diff --git a/src/AngleSharp.Css/Declarations/GridTemplateColumnsDeclaration.cs b/src/AngleSharp.Css/Declarations/GridTemplateColumnsDeclaration.cs index 85ac0130..3f49b08e 100644 --- a/src/AngleSharp.Css/Declarations/GridTemplateColumnsDeclaration.cs +++ b/src/AngleSharp.Css/Declarations/GridTemplateColumnsDeclaration.cs @@ -10,6 +10,7 @@ static class GridTemplateColumnsDeclaration public static readonly String[] Shorthands = new[] { + PropertyNames.Grid, PropertyNames.GridTemplate, }; diff --git a/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs b/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs index 01cb51c9..776795d5 100644 --- a/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs +++ b/src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs @@ -175,7 +175,7 @@ public String ToCssBlock(IStyleFormatter formatter) var usedProperties = new List(); var shorthand = TryCreateShorthand(shorthandName, serialized, usedProperties, false); - if (shorthand != null) + if (shorthand is not null) { list.Add(shorthand); @@ -278,17 +278,17 @@ public void SetProperty(String propertyName, String propertyValue, String priori if (!String.IsNullOrEmpty(propertyValue)) { - if (priority == null || priority.Isi(CssKeywords.Important)) + if (priority is null || priority.Isi(CssKeywords.Important)) { var property = CreateProperty(propertyName); - if (property != null) + if (property is not null) { property.Value = propertyValue; - if (property.RawValue != null) + if (property.RawValue is not null) { - property.IsImportant = priority != null; + property.IsImportant = priority is not null; SetProperty(property); RaiseChanged(); } @@ -421,7 +421,7 @@ private void SetShorthand(ICssProperty shorthand) { var properties = _context.CreateLonghands(shorthand); - if (properties != null) + if (properties is not null) { foreach (var property in properties) {