Skip to content

Spaces removed around formatted text (bold, italic, underlined) #195

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

Open
methalox opened this issue Apr 3, 2025 · 2 comments
Open

Spaces removed around formatted text (bold, italic, underlined) #195

methalox opened this issue Apr 3, 2025 · 2 comments

Comments

@methalox
Copy link

methalox commented Apr 3, 2025

Describe the bug
Spaces adjacent to formatted text elements (such as bold, italic, or underlined text) are being removed in the output document. Not sure if this happens with other types of text formatting as well.
Worked well in 3.2.2 but it doesn't work in 3.2.3 and 3.2.4

Expected behavior
Spaces should not be removed.

Repro

<p>This is normal text with <b>bold text</b> in the middle.</p>
<p>Here is normal text with <i>italic text</i> in the middle.</p>
<p>This sentence has <u>underlined text</u> surrounded by spaces.</p>
<p>Multiple <b>bold</b> <i>italic</i> <u>underlined</u> elements with spaces between them.</p>

How it appears in the browser:

Image

How it appears in the document:

Image

@onizet
Copy link
Owner

onizet commented Apr 4, 2025

I don't think you are using the correct version. I just give it a look and here is the output:

Image

@cyril265
Copy link

cyril265 commented Apr 9, 2025

I can reproduce the issue in 3.2.4. In .InnerText you see spaces between the words but not in the actual docx file.

using (MemoryStream generatedDocument = new MemoryStream())
{
    using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
    {
        MainDocumentPart mainPart = package.MainDocumentPart;
        if (mainPart == null)
        {
            mainPart = package.AddMainDocumentPart();
            new Document(new Body()).Save(mainPart);
        }

        HtmlConverter converter = new HtmlConverter(mainPart);
        await converter.ParseBody("<p>one <strong>two</strong> three</p>");

        mainPart.Document.Save();
    }

    File.WriteAllBytes("./test.docx", generatedDocument.ToArray());
}
Image

test.docx

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

No branches or pull requests

3 participants