647b2b0f37
- Added `AnchorDataProvider`, `AnchorCollectionDataProvider`, `ContentsDataProvider`, `ContentsArrayDataProvider`, `DropDownDataProvider`, `ListContentDataProvider`, and `ParagraphedContentDataProvider` for enhanced data extraction flexibility. - Updated project version to 2.5.0.
40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using HtmlAgilityPack;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Beam.Abstractions;
|
|
|
|
namespace Beam.Dynamic {
|
|
public class ParagraphedContentDataProvider : IComposableDataProvider<string> {
|
|
public IBinding? Content { get; set; }
|
|
|
|
public string Get(HtmlDocument document) {
|
|
if (Content is null)
|
|
return "";
|
|
|
|
var node = Content.Select(document);
|
|
return node is null ? "" : Get(node);
|
|
}
|
|
|
|
public string Get(HtmlNode node) {
|
|
StringBuilder content = new();
|
|
foreach(var childNode in node.ChildNodes) {
|
|
if (childNode.Name != "p")
|
|
continue;
|
|
content.AppendLine(childNode.InnerText);
|
|
}
|
|
|
|
return content.ToString();
|
|
}
|
|
public HtmlNode? Select(HtmlDocument doc) {
|
|
return Content?.Select(doc);
|
|
}
|
|
|
|
public HtmlNode? Select(HtmlNode node) {
|
|
return node;
|
|
}
|
|
}
|
|
}
|