The margin CSS properties are not correctly parsed when unit-less
vladislav-todorov opened this issue · comments
Description
The margin properties are not correctly parsed when unit-less. As you can see on the playground (https://playcode.io/1750419) the margins of the elements are respected when rendering the page. Unfortunately, the ParseStyleSheet() method does not respect them.
Steps to Reproduce
Run the following example:
using AngleSharp.Css.Dom;
using AngleSharp.Css.Parser;
string style = "p { margin-top: 80; margin-bottom: 40; margin-left: 60; margin-right: 20; }";
CssParser cssParser = new CssParser(new CssParserOptions()
{
IsIncludingUnknownDeclarations = true,
IsIncludingUnknownRules = true,
IsToleratingInvalidSelectors = true,
});
ICssStyleSheet sheet = cssParser.ParseStyleSheet(style);
ICssRule rule = sheet.Rules[0];
Console.WriteLine(rule.CssText);
Console.ReadLine();
Expected Behavior
The output should be:
p { margin-top: 80; margin-bottom: 40; margin-left: 60; margin-right: 20; }
Actual Behavior
The output is:
p { }
Possible Solution / Known Workarounds
Change:
public static IValueConverter Converter = AutoLengthOrPercentConverter;
to this:
public static IValueConverter Converter = Or(
AutoLengthOrPercentConverter,
NumberConverter);
in the respective declaration classes.
(Note that unitless behavior is different in quirks mode, i.e., without a proper HTML5 doctype. AngleSharp, however, only has limited support for quirks mode and AngleSharp.Css does not support quirks mode. You can see that with your demo when you prepend <!DOCTYPE html>
to the document.)