diff --git a/src/Html2OpenXml/Utilities/Converter.cs b/src/Html2OpenXml/Utilities/Converter.cs
index 4d2290c..96e914f 100755
--- a/src/Html2OpenXml/Utilities/Converter.cs
+++ b/src/Html2OpenXml/Utilities/Converter.cs
@@ -26,9 +26,9 @@ static class Converter
{
Span loweredValue = span.Length <= 128 ? stackalloc char[span.Length] : new char[span.Length];
span.ToLowerInvariant(loweredValue);
- return loweredValue switch
+ return loweredValue.Trim() switch
{
- "left" => JustificationValues.Left,
+ "left" => JustificationValues.Left,
"right" => JustificationValues.Right,
"center" => JustificationValues.Center,
"justify" => JustificationValues.Both,
@@ -43,7 +43,7 @@ static class Converter
{
Span loweredValue = span.Length <= 128 ? stackalloc char[span.Length] : new char[span.Length];
span.ToLowerInvariant(loweredValue);
- return loweredValue switch
+ return loweredValue.Trim() switch
{
"top" => TableVerticalAlignmentValues.Top,
"middle" => TableVerticalAlignmentValues.Center,
@@ -61,7 +61,7 @@ public static Unit ToFontSize(ReadOnlySpan span)
Span loweredValue = span.Length <= 128 ? stackalloc char[span.Length] : new char[span.Length];
span.ToLowerInvariant(loweredValue);
- var unit = loweredValue switch
+ var unit = loweredValue.Trim() switch
{
"1" or "xx-small" => new Unit(UnitMetric.Point, 10),
"2" or "x-small" => new Unit(UnitMetric.Point, 15),
@@ -92,7 +92,7 @@ public static Unit ToFontSize(ReadOnlySpan span)
Span loweredValue = span.Length <= 128 ? stackalloc char[span.Length] : new char[span.Length];
span.ToLowerInvariant(loweredValue);
- return loweredValue switch
+ return loweredValue.Trim() switch
{
"small-caps" => FontVariant.SmallCaps,
"normal" => FontVariant.Normal,
@@ -106,7 +106,7 @@ public static Unit ToFontSize(ReadOnlySpan span)
Span loweredValue = span.Length <= 128 ? stackalloc char[span.Length] : new char[span.Length];
span.ToLowerInvariant(loweredValue);
- return loweredValue switch
+ return loweredValue.Trim() switch
{
"italic" or "oblique" => FontStyle.Italic,
"normal" => FontStyle.Normal,
@@ -120,7 +120,7 @@ public static Unit ToFontSize(ReadOnlySpan span)
Span loweredValue = span.Length <= 128 ? stackalloc char[span.Length] : new char[span.Length];
span.ToLowerInvariant(loweredValue);
- return loweredValue switch
+ return loweredValue.Trim() switch
{
"700" or "bold" => FontWeight.Bold,
"bolder" => FontWeight.Bolder,
@@ -135,8 +135,9 @@ public static Unit ToFontSize(ReadOnlySpan span)
// return the first font name
Span tokens = stackalloc Range[1];
- return span.SplitCompositeAttribute(tokens, ',') switch {
- 1 => span.Slice(tokens[0]).ToString(),
+ return span.SplitCompositeAttribute(tokens, ',') switch
+ {
+ 1 => span.Slice(tokens[0]).Trim().ToString(),
_ => null
};
}
@@ -148,7 +149,7 @@ public static BorderValues ToBorderStyle(ReadOnlySpan span)
Span loweredValue = span.Length <= 128 ? stackalloc char[span.Length] : new char[span.Length];
span.ToLowerInvariant(loweredValue);
- return loweredValue switch
+ return loweredValue.Trim() switch
{
"dotted" => BorderValues.Dotted,
"dashed" => BorderValues.Dashed,
@@ -177,7 +178,7 @@ public static ICollection ToTextDecoration(ReadOnlySpan va
var tokenCount = span.Split(tokens, ' ', StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < tokenCount; i++)
{
- switch (span.Slice(tokens[i]))
+ switch (span.Slice(tokens[i]).Trim())
{
case "underline": decorations.Add(TextDecoration.Underline); break;
case "line-through": decorations.Add(TextDecoration.LineThrough); break;
diff --git a/test/HtmlToOpenXml.Tests/ElementTests.cs b/test/HtmlToOpenXml.Tests/ElementTests.cs
index 681f47d..11b8583 100644
--- a/test/HtmlToOpenXml.Tests/ElementTests.cs
+++ b/test/HtmlToOpenXml.Tests/ElementTests.cs
@@ -37,13 +37,13 @@ public void PhrasingTag_ReturnsRunWithDefaultStyle (string html) where T : Op
public void MultipleStyle_ShouldBeAllApplied ()
{
var elements = converter.Parse(@"bold with italic style");
Assert.That(elements, Has.Count.EqualTo(1));
@@ -67,7 +67,7 @@ public void MultipleStyle_ShouldBeAllApplied ()
}
}
- [TestCase("Italic!")]
+ [TestCase("Italic!")]
[TestCase("Italic!
")]
[TestCase("")]
public void NestedTagWithStyle_ShouldCascadeParentStyle (string html)