Skip to content

Commit dba9069

Browse files
committed
Fixed text align behavior
1 parent 7a96a55 commit dba9069

File tree

5 files changed

+100
-8
lines changed

5 files changed

+100
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Released on tbd.
1010
- Fixed integer serialization of keyframe stops (#128)
1111
- Fixed ordering of rows and columns in `grid` and `grid-gap` (#137)
1212
- Fixed inclusion of CSS from stylesheets (#116, #140)
13+
- Fixed style empty if `text-align` is `start` (#151)
1314
- Added further compactification of CSS tuples (#89, #93)
1415
- Added support for 8-digit hex color codes (#132)
1516
- Added more CSSOM possibilities and helpers (#6)

src/AngleSharp.Css.Tests/Declarations/CssTextProperty.cs

+35-2
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,39 @@ public void CssOverflowWrapAlternateNameNoneIllegal()
690690
Assert.IsFalse(property.IsInherited);
691691
Assert.IsFalse(property.IsImportant);
692692
Assert.IsFalse(property.HasValue);
693-
}
694-
}
693+
}
694+
695+
[Test]
696+
public void CssTextAlignLegalStart_Issue151()
697+
{
698+
var snippet = "text-align:start";
699+
var property = ParseDeclaration(snippet);
700+
Assert.AreEqual("text-align", property.Name);
701+
Assert.IsTrue(property.HasValue);
702+
Assert.IsFalse(property.IsImportant);
703+
Assert.IsFalse(property.IsInherited);
704+
Assert.AreEqual("start", property.Value);
705+
}
706+
707+
[Test]
708+
public void CssTextAlignLegalJustifyAll_Issue151()
709+
{
710+
var snippet = "text-align:justify-all";
711+
var property = ParseDeclaration(snippet);
712+
Assert.AreEqual("text-align", property.Name);
713+
Assert.IsTrue(property.HasValue);
714+
Assert.IsFalse(property.IsImportant);
715+
Assert.IsFalse(property.IsInherited);
716+
Assert.AreEqual("justify-all", property.Value);
717+
}
718+
719+
[Test]
720+
public void CssTextAlignIllegalJustifyNone_Issue151()
721+
{
722+
var snippet = "text-align:justify-none";
723+
var property = ParseDeclaration(snippet);
724+
Assert.AreEqual("text-align", property.Name);
725+
Assert.IsFalse(property.HasValue);
726+
}
727+
}
695728
}

src/AngleSharp.Css/Constants/CssKeywords.cs

+10
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,11 @@ public static class CssKeywords
702702
/// </summary>
703703
public static readonly String Justify = "justify";
704704

705+
/// <summary>
706+
/// The justify-all keyword.
707+
/// </summary>
708+
public static readonly String JustifyAll = "justify-all";
709+
705710
/// <summary>
706711
/// The underline keyword.
707712
/// </summary>
@@ -1422,6 +1427,11 @@ public static class CssKeywords
14221427
/// </summary>
14231428
public static readonly String Separate = "separate";
14241429

1430+
/// <summary>
1431+
/// The match-parent keyword.
1432+
/// </summary>
1433+
public static readonly String MatchParent = "match-parent";
1434+
14251435
/// <summary>
14261436
/// The start keyword.
14271437
/// </summary>

src/AngleSharp.Css/Constants/Map.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,16 @@ static class Map
9393
/// <summary>
9494
/// Contains the string-HorizontalAlignment mapping.
9595
/// </summary>
96-
public static readonly Dictionary<String, HorizontalAlignment> HorizontalAlignments = new(StringComparer.OrdinalIgnoreCase)
97-
{
98-
{ CssKeywords.Left, HorizontalAlignment.Left },
99-
{ CssKeywords.Right, HorizontalAlignment.Right },
100-
{ CssKeywords.Center, HorizontalAlignment.Center },
101-
{ CssKeywords.Justify, HorizontalAlignment.Justify },
96+
public static readonly Dictionary<String, TextAlign> HorizontalAlignments = new(StringComparer.OrdinalIgnoreCase)
97+
{
98+
{ CssKeywords.Left, TextAlign.Left },
99+
{ CssKeywords.Right, TextAlign.Right },
100+
{ CssKeywords.Center, TextAlign.Center },
101+
{ CssKeywords.Justify, TextAlign.Justify },
102+
{ CssKeywords.Start, TextAlign.Start },
103+
{ CssKeywords.End, TextAlign.End },
104+
{ CssKeywords.JustifyAll, TextAlign.JustifyAll },
105+
{ CssKeywords.MatchParent, TextAlign.MatchParent },
102106
};
103107

104108
/// <summary>

src/AngleSharp.Css/Dom/TextAlign.cs

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
namespace AngleSharp.Css.Dom
2+
{
3+
/// <summary>
4+
/// An enumeration with all possible text alignments.
5+
/// </summary>
6+
public enum TextAlign: byte
7+
{
8+
/// <summary>
9+
/// The inline contents are aligned to the left edge of the line box.
10+
/// This is the default value for table data.
11+
/// </summary>
12+
Left,
13+
/// <summary>
14+
/// The inline contents are centered within the line box. This is
15+
/// the default value for table headers.
16+
/// </summary>
17+
Center,
18+
/// <summary>
19+
/// The inline contents are aligned to the right edge of the line box.
20+
/// </summary>
21+
Right,
22+
/// <summary>
23+
/// The text is justified. Text should line up their left and right
24+
/// edges to the left and right content edges of the paragraph.
25+
/// </summary>
26+
Justify,
27+
/// <summary>
28+
/// The same as left if direction is left-to-right and right if direction is right-to-left.
29+
/// </summary>
30+
Start,
31+
/// <summary>
32+
/// The same as right if direction is left-to-right and left if direction is right-to-left.
33+
/// </summary>
34+
End,
35+
/// <summary>
36+
/// Same as justify, but also forces the last line to be justified.
37+
/// </summary>
38+
JustifyAll,
39+
/// <summary>
40+
/// Similar to inherit, but the values start and end are calculated according to the parent's direction and are replaced by the appropriate left or right value.
41+
/// </summary>
42+
MatchParent,
43+
}
44+
}

0 commit comments

Comments
 (0)