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

Add support for text alignment in paragraphs #43

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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