C# 有 CSS 解析器吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/512720/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 06:18:33  来源:igfitidea点击:

Is there a CSS parser for C#?

c#cssparsing

提问by Ken

My program need to parse css files into an in-memory object format. Any advice on how this should be done ?

我的程序需要将 css 文件解析为内存中的对象格式。关于如何做到这一点的任何建议?

回答by Jon Tackabury

ExCSS (supports CSS2.1 and CSS3) on GitHub: https://github.com/TylerBrinks/ExCSS.

GitHub 上的 ExCSS(支持 CSS2.1 和 CSS3):https: //github.com/TylerBrinks/ExCSS

Which is a newer version of the code project article: http://www.codeproject.com/KB/recipes/CSSParser.aspx

这是代码项目文章的较新版本:http: //www.codeproject.com/KB/recipes/CSSParser.aspx

回答by mercator

And a slightly slower search turns up the blog post "CSS parser class in .NET" which embeds this gist on GitHub(in case the blog ever dies).

稍微慢一点的搜索会出现博客文章“ .NET 中的 CSS 解析器类”,它将这个要点嵌入到 GitHub 上(以防博客消失)。

回答by dajood

Hereyou can find another one especially for C# with sample source.

在这里您可以找到另一个特别适用于 C# 的示例源代码。

回答by ChrisW

I wrote one, using the grammar specified in the CSS 2.1 spec. I have also released it now: for details, see http://www.modeltext.com/css/

我写了一个,使用 CSS 2.1 规范中指定的语法。我现在也发布了:详情见http://www.modeltext.com/css/

回答by ChrisW

There is a CSS grammar file for GoldParser:

GoldParser 有一个 CSS 语法文件:

http://goldparser.org/grammars/files/css.zip

http://goldparser.org/grammars/files/css.zip

GoldParser is easy to include in a C# project, and generates an real LALR parser - not some regex hack.

GoldParser 很容易包含在 C# 项目中,并生成一个真正的 LALR 解析器 - 而不是一些正则表达式。

回答by m0sa

Have you tried the one featured in JsonFx? It's written in C#, parses CSS3 syntax and is distributed under a MIT style license.

您是否尝试过JsonFx 中的功能?它是用 C# 编写的,解析 CSS3 语法,并在 MIT 风格许可下分发。