The GetInnerText() extension method in v0.12.1 of AngleSharp.Css removes whitespace before a <span> element; that isn't desired behavior.
Steps to Reproduce
using AngleSharp;
using AngleSharp.Dom;
using AngleSharp.Html.Parser;
static class Program
{
static void Main()
{
var ctx = BrowsingContext.New(Configuration.Default.WithCss());
var parser = ctx.GetService<IHtmlParser>();
var nodeList = parser.ParseFragment("<div><div>Div with <span>a span</span> in it.</div></div>", null);
var element = (IElement)nodeList[0];
Console.WriteLine(element.GetInnerText());
Console.ReadKey();
}
}
Expected behavior: Outputs "Div with a span in it.".
In all of Firefox, Chrome, Edge, and IE, pasting var wrapper = document.createElement("div"); wrapper.innerHTML = "<div>Div with <span>a span</span> in it.</div>"; wrapper.innerText into the developer console produces this output.
Actual behavior: Outputs "Div witha span in it."
Environment details: .NET Framework v4.6.2
Possible Solution
The problem appears to lie at the end of ProcessText. I'm not sure I fully understand the intent there, it appears to remove a single space after the last non-whitespace character of a text node with trailing white-space. I think that might not be correct when the subsequent node is an inline element, the text node is at the end of an inline element, or if the style for the text node had white-space pre or pre-wrap.
Bug Report
Description
The GetInnerText() extension method in v0.12.1 of AngleSharp.Css removes whitespace before a
<span>
element; that isn't desired behavior.Steps to Reproduce
Expected behavior: Outputs "Div with a span in it.".
In all of Firefox, Chrome, Edge, and IE, pasting
var wrapper = document.createElement("div"); wrapper.innerHTML = "<div>Div with <span>a span</span> in it.</div>"; wrapper.innerText
into the developer console produces this output.Actual behavior: Outputs "Div witha span in it."
Environment details: .NET Framework v4.6.2
Possible Solution
The problem appears to lie at the end of
ProcessText
. I'm not sure I fully understand the intent there, it appears to remove a single space after the last non-whitespace character of a text node with trailing white-space. I think that might not be correct when the subsequent node is an inline element, the text node is at the end of an inline element, or if the style for the text node had white-space pre or pre-wrap.