Skip to content

Commit

Permalink
Fixed shorthand properties using inherit AngleSharp#100
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jun 1, 2022
1 parent 3a64567 commit 0751cbe
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Released on Tuesday, May 31 2022.
- Dropped .NET Framework 4.6
- Updated to use AngleSharp 0.17
- Fixed casing issue with color, timing, and gradient functions (#109)
- Fixed shorthand properties using `inherit` being omitted (#100)

# 0.16.4

Expand Down
32 changes: 32 additions & 0 deletions src/AngleSharp.Css.Tests/Library/StringRepresentation.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
namespace AngleSharp.Css.Tests.Library
{
using AngleSharp.Css.Dom;
using AngleSharp.Css.Parser;
using AngleSharp.Css.Values;
using NUnit.Framework;
using System.IO;
using static CssConstructionFunctions;

[TestFixture]
public class StringRepresentationTests
Expand Down Expand Up @@ -41,5 +43,35 @@ public void TransparentColorDoesNotWorkWithHexOutput_Issue96()
Color.UseHex = false;
Assert.AreEqual("rgba(65, 12, 48, 0.04)", text);
}

[Test]
public void ShorthandPaddingInheritPropertiesShouldBeIncluded_Issue100()
{
var html = @"<style>#x div { padding: inherit }</style>";
var dom = ParseDocument(html);
var styleSheet = dom.StyleSheets[0] as ICssStyleSheet;
var css = styleSheet.ToCss();
Assert.AreEqual("#x div { padding: inherit }", css);
}

[Test]
public void ShorthandMarginInheritPropertiesShouldBeIncluded_Issue100()
{
var html = @"<style>#x div { margin: inherit }</style>";
var dom = ParseDocument(html);
var styleSheet = dom.StyleSheets[0] as ICssStyleSheet;
var css = styleSheet.ToCss();
Assert.AreEqual("#x div { margin: inherit }", css);
}

[Test]
public void ShorthandBorderInheritPropertiesShouldBeIncluded_Issue100()
{
var html = @"<style>#x div { border: inherit }</style>";
var dom = ParseDocument(html);
var styleSheet = dom.StyleSheets[0] as ICssStyleSheet;
var css = styleSheet.ToCss();
Assert.AreEqual("#x div { border: inherit }", css);
}
}
}
2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Declarations/MarginDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static class MarginDeclaration

sealed class MarginAggregator : IValueAggregator, IValueConverter
{
private static readonly IValueConverter converter = AutoLengthOrPercentConverter.Periodic();
private static readonly IValueConverter converter = Or(AutoLengthOrPercentConverter, AssignInitial(Length.Zero)).Periodic();

public ICssValue Convert(StringSource source) => converter.Convert(source);

Expand Down
2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Declarations/PaddingDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static class PaddingDeclaration

sealed class PaddingAggregator : IValueAggregator, IValueConverter
{
private static readonly IValueConverter converter = LengthOrPercentConverter.Periodic();
private static readonly IValueConverter converter = Or(LengthOrPercentConverter, AssignInitial(Length.Zero)).Periodic();

public ICssValue Convert(StringSource source) => converter.Convert(source);

Expand Down
3 changes: 2 additions & 1 deletion src/AngleSharp.Css/Extensions/ValueConverterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace AngleSharp.Css.Converters
using AngleSharp.Text;
using System;
using System.Collections.Generic;
using static ValueConverters;

/// <summary>
/// Essential extensions for using the value converters.
Expand Down Expand Up @@ -61,7 +62,7 @@ public static IValueConverter Exclusive(this IValueConverter converter)
}

public static IValueConverter Option(this IValueConverter converter, ICssValue defaultValue) =>
new OptionValueConverter(converter, defaultValue);
Or(new OptionValueConverter(converter, defaultValue), AssignInitial(defaultValue));

public static String Join<T>(this IEnumerable<T> values, String separator)
where T : ICssValue
Expand Down

0 comments on commit 0751cbe

Please sign in to comment.