Skip to content

Commit

Permalink
Merge pull request #85 from wangx036/MIf
Browse files Browse the repository at this point in the history
Modify:Remove all elements between @if~@endif, not paragraph
  • Loading branch information
shps951023 authored Sep 15, 2024
2 parents 4ef9cee + 1ae2d9e commit ad19bdd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/MiniWord/MiniWord.Implment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ private static void ReplaceText(OpenXmlElement xmlElement, WordprocessingDocumen

private static void ReplaceStatements(OpenXmlElement xmlElement, Dictionary<string, object> tags)
{
var descendants = xmlElement.Descendants().ToList();
var paragraphs = xmlElement.Descendants<Paragraph>().ToList();

while (paragraphs.Any(s => s.InnerText.Contains("@if")))
Expand All @@ -525,10 +526,14 @@ private static void ReplaceStatements(OpenXmlElement xmlElement, Dictionary<stri

if (!checkStatement)
{
for (int i = ifIndex + 1; i <= endIfFinalIndex - 1; i++)
var paragraphIfIndex = descendants.FindIndex(a => a == paragraphs[ifIndex]);
var paragraphEndIfIndex = descendants.FindIndex(a => a == paragraphs[endIfFinalIndex]);

for (int i = paragraphIfIndex + 1; i <= paragraphEndIfIndex - 1; i++)
{
paragraphs[i].Remove();
descendants[i].Remove();
}

}

paragraphs[ifIndex].Remove();
Expand Down

0 comments on commit ad19bdd

Please sign in to comment.