Skip to content

Conversation

@r-Larch
Copy link

@r-Larch r-Larch commented Jul 9, 2024

This PR enables use cases like the following.

Feel free to merge or close 👍

kind regards
René

[Fact]
public void CanHandleTextAlignment() {
    AssertSuccessfulConversion(
        ConvertToHtml("text-align.docx", mammoth => mammoth
            .AddStyleMap("p[text-align='center'] => p.center:fresh")
            .AddStyleMap("p[text-align='right'] => p.right:fresh")
            .AddStyleMap("p[text-align='justify'] => p.justify:fresh")
        ),
        "<p class=\"center\"><strong>The Sunset Tree</strong></p>" +
        "<p class=\"justify\">Lorem ipsum justify</p>" +
        "<p class=\"justify\">Foobar justify</p>" +
        "<p class=\"right\">TextAlign Right</p>" +
        "<p class=\"center\">Center 1</p>" +
        "<p class=\"center\">Center 2</p>" +
        "<p>Left 1</p>" +
        "<p>Left 2</p>");
}

[Fact]
public void CanHandleTextAlignmentWithStyle() {
    AssertSuccessfulConversion(
        ConvertToHtml("text-align_mixed.docx", mammoth => mammoth
            .AddStyleMap("p[text-align='center'] => p.center:fresh")
            .AddStyleMap("p[text-align='right'] => p.right:fresh")
            .AddStyleMap("p[text-align='justify'] => p.justify:fresh")
            .AddStyleMap("p[style-name='Heading 1', text-align='center'] => h1.center:fresh")
            .AddStyleMap("p[style-name='Heading 1', text-align='right'] => h1.right:fresh")
        ),
        "<h1 class=\"center\">Header 1 Center</h1>" +
        "<h1>Header 1 Left</h1>" +
        "<h1 class=\"right\">Header 1 Right</h1>" +
        "<p>Normal paragraph, lorem ipsum.</p>" +
        "<p class=\"center\">Normal paragraph, align center, lorem ipsum.</p>");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant