From e2bcc7027cc1f44d7bf7928db8f4c8ec8179958a Mon Sep 17 00:00:00 2001 From: Stephan Steiger Date: Tue, 8 Apr 2025 13:40:10 +0200 Subject: [PATCH] prevent blank lines when html tags have attributes --- .../Model/SharePoint/Pages/Internal/PageText.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/PageText.cs b/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/PageText.cs index 065bede4d9..b244b749c4 100644 --- a/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/PageText.cs +++ b/src/sdk/PnP.Core/Model/SharePoint/Pages/Internal/PageText.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Text.Json; +using System.Text.RegularExpressions; namespace PnP.Core.Model.SharePoint { @@ -135,18 +136,11 @@ public override string ToHtml(float controlIndex) catch { } StringBuilder html = new StringBuilder(); - html.Append($@"
"); + html.Append($@"
"); html.Append($@"
"); if (!string.IsNullOrEmpty(Text)) { - if (Text.Trim().StartsWith("

", StringComparison.InvariantCultureIgnoreCase) || - Text.Trim().StartsWith("

", StringComparison.InvariantCultureIgnoreCase) || - Text.Trim().StartsWith("

", StringComparison.InvariantCultureIgnoreCase) || - Text.Trim().StartsWith("

", StringComparison.InvariantCultureIgnoreCase) || - Text.Trim().StartsWith("

", StringComparison.InvariantCultureIgnoreCase) || - Text.Trim().StartsWith("
    ", StringComparison.InvariantCultureIgnoreCase) || - Text.Trim().StartsWith("
    ", StringComparison.InvariantCultureIgnoreCase) || - Text.Trim().StartsWith("
    ", StringComparison.InvariantCultureIgnoreCase))
    +                if (Regex.IsMatch(Text.Trim(), @"^<(p|h1|h2|h3|h4|ul|blockquote|pre)(\s+[^>]*)?>\s*", RegexOptions.IgnoreCase))
                     {
                         html.Append(Text);
                     }
    @@ -158,7 +152,7 @@ public override string ToHtml(float controlIndex)
                 html.Append("

"); html.Append("
"); return html.ToString(); - } + } #endregion #region Internal and private methods