Skip to content

Fix: Markdown formatter removed insertion points#92

Merged
Amberg merged 2 commits intomainfrom
workitems/FormatInCelles
Jan 19, 2026
Merged

Fix: Markdown formatter removed insertion points#92
Amberg merged 2 commits intomainfrom
workitems/FormatInCelles

Conversation

@Amberg
Copy link
Owner

@Amberg Amberg commented Jan 19, 2026

Fix: Fix for: #89

This pull request includes dependency updates, a bugfix for Markdown formatting, and new test coverage for a previously reported crash scenario. The most notable changes are the updates to package versions for improved compatibility and stability, enhancements to how Markdown content is processed, and the addition of a regression test for a specific Markdown crash case.

Dependency updates:

  • Updated Markdig package in DocxTemplater.Markdown.csproj to version 0.44.0 or higher, improving Markdown parsing capabilities.
  • Updated DocumentFormat.OpenXml package in DocxTemplater.csproj to version 3.4.1 or higher for better document handling and bug fixes.
  • Updated test dependencies in DocxTemplater.Test.csproj, including Microsoft.NET.Test.Sdk and NUnit3TestAdapter, for improved test reliability and compatibility.

Markdown formatting and bugfix:

  • Improved child element handling in MarkdownFormatter.cs to ensure elements with insertion point markers or marked elements are retained during paragraph merging, addressing a Markdown crash scenario.

Test coverage:

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a critical bug in the Markdown formatter where insertion point markers were being removed during paragraph merging, which caused crashes during template processing. The fix enhances the child element filtering logic to preserve insertion point markers and marked elements alongside Table and Run elements.

Changes:

  • Updated dependency versions for DocumentFormat.OpenXml, Markdig, and test framework packages
  • Fixed child element filtering in MarkdownFormatter to preserve insertion points and marked elements during paragraph merging
  • Added regression test for the crash scenario reported in GitHub issue #89

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
DocxTemplater/DocxTemplater.csproj Updated DocumentFormat.OpenXml minimum version from 3.3.0 to 3.4.1
DocxTemplater.Markdown/DocxTemplater.Markdown.csproj Updated Markdig minimum version from 0.43.0 to 0.44.0
DocxTemplater.Test/DocxTemplater.Test.csproj Updated Microsoft.NET.Test.Sdk to 18.0.1 and NUnit3TestAdapter to 6.1.0, added markdown-crash-example.docx resource
DocxTemplater.Markdown/MarkdownFormatter.cs Enhanced child element filtering to preserve insertion point markers and marked elements during paragraph merging
DocxTemplater.Test/GitHubQuestionsExamples.cs Added MarkdownCrash regression test and reformatted existing test assertion

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +37 to +82
[Test]
// Issue: https://github.com/Amberg/DocxTemplater/issues/89
public void MarkdownCrash()
{
using var fileStream = File.OpenRead("Resources/markdown-crash-example.docx");
var docTemplate = new DocxTemplate(fileStream);
var data = new
{
var_hastegenargumenten = true,
var_tegenargumenten = new[]
{
new
{
nrq_name = "Tegenargument",
nrq_argument = "BASIS ARGUMENT",
nrq_response = "SOME RESPONSE",
nrq_hidedecisiononletter = new
{
Label = "Nee",
Value = false
},
nrq_decision = new
{
Label = "Niet geaccepteerd",
Value = 875810001
},
nrq_regarding = new
{
Label = "Dossier",
Value = 875810000
},
nrq_processphase = new
{
Label = "Hoorzitting",
Value = 875810003
}
}
}
};
docTemplate.RegisterFormatter(new MarkdownFormatter());
docTemplate.BindModel("ds", data);
var result = docTemplate.Process();
docTemplate.Validate();
Assert.That(result, Is.Not.Null);
result.SaveAsFileAndOpenInWord();

Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test validates that the process completes without throwing an exception and returns a non-null result, but it doesn't verify the actual correctness of the output document. Consider adding assertions that check the document content or structure to ensure the markdown is processed correctly and insertion points are preserved as intended by the fix.

Copilot uses AI. Check for mistakes.
@Amberg Amberg merged commit 86ae424 into main Jan 19, 2026
10 checks passed
@Amberg Amberg deleted the workitems/FormatInCelles branch January 23, 2026 12:44
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