CssQuotesProperty
Information can be found on MDN:
https://developer.mozilla.org/en-US/docs/Web/CSS/quotes
Gets the enumeration with pairs of values for open-quote and
close-quote. The first pair represents the outer level of quotation,
the second pair is for the first nested level, next pair for third
level and so on.
using AngleSharp.Css;
using AngleSharp.Dom.Html;
using AngleSharp.Extensions;
using System;
using System.Linq;
namespace AngleSharp.Dom.Css
{
internal sealed class CssQuotesProperty : CssProperty
{
private static readonly IValueConverter<Tuple<string, string>[]> Converter = Converters.StringConverter.Many(1, 65535).Constraint((string[] m) => m.Length % 2 == 0).To(TransformArray)
.Or(Keywords.None, new Tuple<string, string>[0]);
internal CssQuotesProperty(CssStyleDeclaration rule)
: base(PropertyNames.Quotes, rule, PropertyFlags.Inherited)
{
}
protected override object GetDefault(IElement element)
{
return Tuple.Create("«", "»");
}
protected override object Compute(IElement element)
{
Tuple<string, string>[] array = Converter.Convert(base.Value);
if (element is IHtmlQuoteElement && array.Length != 0) {
int val = element.GetAncestors().OfType<IHtmlQuoteElement>().Count();
int num = Math.Min(array.Length - 1, val);
return array[num];
}
return Tuple.Create("", "");
}
protected override bool IsValid(ICssValue value)
{
return Converter.Validate(value);
}
private static Tuple<string, string>[] TransformArray(string[] arrays)
{
Tuple<string, string>[] array = new Tuple<string, string>[arrays.Length / 2];
int num = 0;
int num2 = 0;
while (num < arrays.Length) {
array[num2] = Tuple.Create(arrays[num], arrays[num + 1]);
num += 2;
num2++;
}
return array;
}
}
}