gpt4 book ai didi

java - 关于cssparser

转载 作者:太空宇宙 更新时间:2023-11-04 16:02:53 25 4
gpt4 key购买 nike

friend 们,我正在使用 cssparser 来解析我的 CSS。我的代码是这样的:

public static Map<String, CSSStyleRule> parseCSS1() throws IOException {
Map<String, CSSStyleRule> rules = new LinkedHashMap<String, CSSStyleRule>();

InputSource inputSource = new InputSource(new FileReader("C:\\COMPUTERS.css"));
CSSStyleSheet styleSheet = new CSSOMParser().parseStyleSheet(inputSource, null, null);

CSSRuleList ruleList = styleSheet.getCssRules();
for (int i = 0; i < ruleList.getLength(); i++) {
CSSRule rule = ruleList.item(i);
if (rule.getType() == CSSRule.STYLE_RULE) {
CSSStyleRule styleRule = (CSSStyleRule) rule;
rules.put(styleRule.getSelectorText(), styleRule);
}
}

return rules;
}

现在,当我尝试在 CSS (rules.getvalues()) 中打印值时,解析后会给出以下结果:

BODY { font-family: monospace; 
color: black;
font-size: medium;
font-style: normal;
font-weight: normal;
background-color: rgb(255, 182, 193);
background-image: url(images/COMPUTERSbody_computers.gif);
border: no }

在最后一行 border:no 之后没有分号,而在原始 CSS 中它存在。

那么,我应该手动添加分号还是我犯了一个错误?

此外,在原始 CSS 中:

background-color: #FFB6C1  

被替换为:

background-color: rgb(255, 182, 193);

在解析后的输出中。有什么办法可以保持原来的样子吗?

最佳答案

CSS 声明中的最后一个分号不是强制性的,库故意将其省略。

关于java - 关于cssparser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9578827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com