Skip to content

Commit

Permalink
consider mathML comments as text content
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Nov 1, 2023
1 parent a745796 commit c095261
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 c095261

Please sign in to comment.