Skip to content

Commit 0751cbe

Browse files
committed
Fixed shorthand properties using inherit #100
1 parent 3a64567 commit 0751cbe

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Released on Tuesday, May 31 2022.
55
- Dropped .NET Framework 4.6
66
- Updated to use AngleSharp 0.17
77
- Fixed casing issue with color, timing, and gradient functions (#109)
8+
- Fixed shorthand properties using `inherit` being omitted (#100)
89

910
# 0.16.4
1011

src/AngleSharp.Css.Tests/Library/StringRepresentation.cs

+32
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
namespace AngleSharp.Css.Tests.Library
22
{
3+
using AngleSharp.Css.Dom;
34
using AngleSharp.Css.Parser;
45
using AngleSharp.Css.Values;
56
using NUnit.Framework;
67
using System.IO;
8+
using static CssConstructionFunctions;
79

810
[TestFixture]
911
public class StringRepresentationTests
@@ -41,5 +43,35 @@ public void TransparentColorDoesNotWorkWithHexOutput_Issue96()
4143
Color.UseHex = false;
4244
Assert.AreEqual("rgba(65, 12, 48, 0.04)", text);
4345
}
46+
47+
[Test]
48+
public void ShorthandPaddingInheritPropertiesShouldBeIncluded_Issue100()
49+
{
50+
var html = @"<style>#x div { padding: inherit }</style>";
51+
var dom = ParseDocument(html);
52+
var styleSheet = dom.StyleSheets[0] as ICssStyleSheet;
53+
var css = styleSheet.ToCss();
54+
Assert.AreEqual("#x div { padding: inherit }", css);
55+
}
56+
57+
[Test]
58+
public void ShorthandMarginInheritPropertiesShouldBeIncluded_Issue100()
59+
{
60+
var html = @"<style>#x div { margin: inherit }</style>";
61+
var dom = ParseDocument(html);
62+
var styleSheet = dom.StyleSheets[0] as ICssStyleSheet;
63+
var css = styleSheet.ToCss();
64+
Assert.AreEqual("#x div { margin: inherit }", css);
65+
}
66+
67+
[Test]
68+
public void ShorthandBorderInheritPropertiesShouldBeIncluded_Issue100()
69+
{
70+
var html = @"<style>#x div { border: inherit }</style>";
71+
var dom = ParseDocument(html);
72+
var styleSheet = dom.StyleSheets[0] as ICssStyleSheet;
73+
var css = styleSheet.ToCss();
74+
Assert.AreEqual("#x div { border: inherit }", css);
75+
}
4476
}
4577
}

src/AngleSharp.Css/Declarations/MarginDeclaration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static class MarginDeclaration
2727

2828
sealed class MarginAggregator : IValueAggregator, IValueConverter
2929
{
30-
private static readonly IValueConverter converter = AutoLengthOrPercentConverter.Periodic();
30+
private static readonly IValueConverter converter = Or(AutoLengthOrPercentConverter, AssignInitial(Length.Zero)).Periodic();
3131

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

src/AngleSharp.Css/Declarations/PaddingDeclaration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static class PaddingDeclaration
2727

2828
sealed class PaddingAggregator : IValueAggregator, IValueConverter
2929
{
30-
private static readonly IValueConverter converter = LengthOrPercentConverter.Periodic();
30+
private static readonly IValueConverter converter = Or(LengthOrPercentConverter, AssignInitial(Length.Zero)).Periodic();
3131

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

src/AngleSharp.Css/Extensions/ValueConverterExtensions.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace AngleSharp.Css.Converters
55
using AngleSharp.Text;
66
using System;
77
using System.Collections.Generic;
8+
using static ValueConverters;
89

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

6364
public static IValueConverter Option(this IValueConverter converter, ICssValue defaultValue) =>
64-
new OptionValueConverter(converter, defaultValue);
65+
Or(new OptionValueConverter(converter, defaultValue), AssignInitial(defaultValue));
6566

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

0 commit comments

Comments
 (0)