Skip to content

Commit

Permalink
Merge pull request stevencohn#1151 from stevencohn/1150-remove-empty-…
Browse files Browse the repository at this point in the history
…with-formula

consider mathML comments as text content
  • Loading branch information
stevencohn committed Nov 1, 2023
2 parents a745796 + c095261 commit f35ccb4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion OneMore/Commands/Clean/RemoveEmptyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace River.OneMoreAddIn.Commands
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;
Expand Down Expand Up @@ -122,7 +123,7 @@ public bool CollapseEmptyLines()
var elements = range
.Select(e => e.Parent)
.Distinct()
.Where(e => e.TextValue().Trim().Length == 0)
.Where(e => e.TextValue().Trim().Length == 0 && !e.IsMathML())
.ToList();

if (elements?.Any() != true)
Expand Down
14 changes: 14 additions & 0 deletions OneMore/Helpers/Extensions/XElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,20 @@ public static XElement FirstAncestor(this XElement element, XName name, XName br
}


/// <summary>
/// Determines if the content of the element consists only of a mathML statement
/// which is identified when its CDATA specifies an XML comment.
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
public static bool IsMathML(this XElement element)
{
var cdata = element.GetCData();
return cdata != null &&
Regex.IsMatch(cdata.Value, @"<!--.+?-->", RegexOptions.Singleline);
}


/// <summary>
/// OneMore Extension >> Extract the sanitized text value of the given element
/// </summary>
Expand Down

0 comments on commit f35ccb4

Please sign in to comment.