AngleSharp Css 使用路径查询元素样式

AngleSharp Css Query For Element Style Using Path

仅给定一个 css 样式表,是否可以使用某种路径查询来解析和查询样式表以检索类似于从 IElement.ComputeCurrentStyle() 返回的计算样式?

var css = @"
<style>
   table { font-family:foobar }
   td { font-weight:bold }
</style>
";

var config = Configuration.Default.WithDefaultLoader().WithCss();
var context = BrowsingContext.New(config);
IDocument document = await context.OpenAsync(req => req.Content(css));
ICssStyleSheet sheet = document.GetStyleSheets().OfType<ICssStyleSheet>().First()

是否可以做类似 sheet.GetComputedStyle("body>table>tbody>tr>td") 的事情来检索 ICssStyleDeclaration

在 github 项目问题跟踪器上得到了对此的回应 https://github.com/AngleSharp/AngleSharp.Css/issues/64

Well to get a computed style you need to have a connection to the DOM. After all, things like selectors can only be computed in context of an available DOM structure. I guess what you are after is to "fake" the DOM, i.e., if you see some selector (like body>table>tbody>tr>td) create the minimal DOM to be able to get an element that satisfies the selector. Then use this element to get the computed style, right? Out of the box this is not possible, but I think it should be doable to write this.