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

A space is inserted between two spans #179

Open
Wladimir-Panfilenko opened this issue Nov 22, 2024 · 0 comments
Open

A space is inserted between two spans #179

Wladimir-Panfilenko opened this issue Nov 22, 2024 · 0 comments

Comments

@Wladimir-Panfilenko
Copy link

Wladimir-Panfilenko commented Nov 22, 2024

Describe the bug
For two consecutive spans there is an additional space inserted between them.

Expected behavior
Just the content of the two spans without the space.

Repro
<span>foo</span><span>bar</span>
In the browser:
image
In the docx:
image

In this example a single paragraph is generated that contains 3 runs. One run for each of the spans and one for the additional space.

Sample test for easier repro:

public class HtmlToOpenXmlTests
{
        [Fact]
        public void TwoSpans()
        {
            using var memoryStream = new MemoryStream();
            using var wordDocument = WordprocessingDocument.Create(memoryStream, DocumentFormat.OpenXml.WordprocessingDocumentType.Document, true);
            var mainPart = wordDocument.AddMainDocumentPart();
            mainPart.Document = new Document();
            mainPart.Document.AppendChild(new Body());

            var htmlConverter = new HtmlConverter(mainPart);
            var html = "<p><span>foo</span><span>bar</span></p>";
            var parsedElements = htmlConverter.Parse(html);

            var text = ((Paragraph)parsedElements[0]).InnerText;

            text.Should().Be("foobar"); // text is "foo bar" instead
        }
}
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

1 participant