Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html to wml enhancements #2

Open
wants to merge 2 commits into
base: vNext
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions OpenXmlPowerTools.Tests/HtmlToWmlConverterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ public class HwTests
[InlineData("T1830.html")]
[InlineData("T1840.html")]
[InlineData("T1850.html")]
[InlineData("T1860.html")]
[InlineData("T1870.html")]

public void HW001(string name)
{
Expand Down
4 changes: 2 additions & 2 deletions OpenXmlPowerTools/HtmlToWmlConverterCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2829,9 +2829,9 @@ private static XElement[] GetSpacingProperties(XElement paragraph, HtmlToWmlConv
// todo should check based on display property
bool numItem = paragraph.Name == XhtmlNoNamespace.li;

if (numItem && marginTopProperty.IsAuto)
if (numItem && marginTopProperty != null && marginTopProperty.IsAuto)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use
`if (numItem && marginTopProperty?.IsAuto)'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that numItem is 'bool', but marginTopProperty?.IsAuto is 'bool?' , so '&&' operator cannot be applied to 'bool' and 'bool?'.

Thank you for your review!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (numItem && marginTopProperty?.IsAuto == true)

beforeAutospacing = "1";
if (numItem && marginBottomProperty.IsAuto)
if (numItem && marginTopProperty != null && marginBottomProperty.IsAuto)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be marginBottomProperty != null (copy/paste issue I guess)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (numItem && marginBottomProperty?.IsAuto == true)

afterAutospacing = "1";
if (marginTopProperty != null && marginTopProperty.IsNotAuto)
{
Expand Down
6 changes: 6 additions & 0 deletions OpenXmlPowerTools/HtmlToWmlCssApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,10 @@ private static CssExpression ComputeAbsoluteLength(XElement element, CssExpressi
throw new OpenXmlPowerToolsException("Internal error");
newPtSize = (unit == CssUnit.EM) ? decFontSize * decValue : decFontSize * decValue / 2;
}
else if (unit == CssUnit.REM)
{
newPtSize = settings.DefaultFontSize * decValue;
}
else
{
if (unit == null && decValue == 0d)
Expand Down Expand Up @@ -1515,6 +1519,8 @@ private static CssExpression ComputeAbsoluteFontSize(XElement element, CssExpres
newPtSize = ptSize / 2 * decValue;
if (unit == CssUnit.Percent)
newPtSize = ptSize * decValue / 100d;
if (unit == CssUnit.REM)
newPtSize = settings.DefaultFontSize * decValue;
}
else
{
Expand Down
30 changes: 30 additions & 0 deletions TestFiles/T1860.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<meta charset="UTF-8"/>

<style>
ol {
list-style-type: none;
margin: 0;
padding: 0;
}

ol > li {
display: table;
counter-increment: item;
margin-bottom: 0.6em;
}

</style>

<body>

<section >
<ol>
<li>
<span >Description</span>
</li>
</ol>
</section>
</body>
</html>
16 changes: 16 additions & 0 deletions TestFiles/T1870.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<meta charset="UTF-8"/>
<style>

h2 {
margin-top: 2rem;
}

</style>

<body>
<h1>Test1</h1>
<h2>Test2</h2>
</body>
</html>