Skip to content

Commit

Permalink
Remove consideration for _GoBack bookmark
Browse files Browse the repository at this point in the history
  • Loading branch information
onizet committed Sep 23, 2024
1 parent cfcdbdd commit 4799416
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 33 deletions.
9 changes: 0 additions & 9 deletions src/Html2OpenXml/HtmlConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,6 @@ public async Task ParseBody(string html, CancellationToken cancellationToken = d
p.Remove();
}

// move the paragraph with BookmarkStart `_GoBack` as the last child
// That bookmark is continuously moved after the last edit
p = body.GetFirstChild<Paragraph>();
if (p != null && p.GetFirstChild<BookmarkStart>()?.Name == "_GoBack")
{
p.Remove();
body.Append(p);
}

// Push the sectionProperties as the last element of the Body
// (required by OpenXml schema to avoid the bad formatting of the document)
if (sectionProperties != null)
Expand Down
24 changes: 0 additions & 24 deletions test/HtmlToOpenXml.Tests/BodyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,5 @@ public bool PageOrientation_OverrideExistingLayout_ReturnsLandscapeDimension(str
var bidi = mainPart.Document.Body!.GetFirstChild<SectionProperties>()?.GetFirstChild<BiDi>();
return bidi?.Val?.Value;
}

[Test(Description = "Bookmark _GoBack is reserved and must stand after the last edit change")]
public async Task WithGoBackBookmark_ShouldBeAfterAppendedOutput()
{
using var generatedDocument = new MemoryStream();
using (var buffer = ResourceHelper.GetStream("Resources.DocWithCustomStyle.docx"))
buffer.CopyTo(generatedDocument);

generatedDocument.Position = 0L;
using WordprocessingDocument package = WordprocessingDocument.Open(generatedDocument, true);
MainDocumentPart mainPart = package.MainDocumentPart!;

var goBackBookmark = mainPart.Document.Body!.Elements<Paragraph>()
.FirstOrDefault(p => p.GetFirstChild<BookmarkStart>()?.Name?.Value == "_GoBack");
Assert.That(goBackBookmark, Is.Not.Null);

HtmlConverter converter = new HtmlConverter(mainPart);
await converter.ParseBody("<p>Placeholder</p>");

Assert.That(mainPart.Document.Body!.LastChild, Is.TypeOf<SectionProperties>());
var paragrahs = mainPart.Document.Body!.Elements<Paragraph>();
Assert.That(paragrahs.Count(), Is.EqualTo(2));
Assert.That(paragrahs.Last().GetFirstChild<BookmarkStart>()?.Name?.Value, Is.EqualTo("_GoBack"));
}
}
}

0 comments on commit 4799416

Please sign in to comment.