开发者

How to parse css (stylesheet) comments (annotations)?

开发者 https://www.devze.com 2023-01-08 14:09 出处:网络
I have this idea, the user defines set of css rules with some comments (comments are simple annotations):

I have this idea, the user defines set of css rules with some comments (comments are simple annotations):

/* @name Page style */
body {
   font: 16px/1.5 Arial; /* @editable */
   backgorund-color: #fff; /* @editable */
}

/* @name Section header */
h1 {
   font: 20px/1.2 Arial; /* @editable */
   color: #c44 
}

I can apply this stylesheet to my page but I also want to parse this rules with the comments and provide some forms to edit these styles and let the user change the styles on the fly. These comments will indicate which rules/properties are editable.

I was looking for some browser or server solution. The easiest serwer solution would be to parse this css with some java css parser, convert it to ex. json and then make use of this json in the browser: http://www.featureblend.com/css-json.html

The problem is I haven't found any Java css parser w开发者_运维技巧hich will be able to handle comments.

The same is in the browser, no suitable css parser. Any ideas how to do this?


did you have a look at the css sac parser implementation?

http://www.w3.org/Style/CSS/SAC/

-->

http://www.w3.org/Style/CSS/SAC/doc/org/w3c/css/sac/Parser.html

the document-handler has a comment method

http://www.w3.org/Style/CSS/SAC/doc/org/w3c/css/sac/DocumentHandler.html#comment_java.lang.String_


You could write your own or maybe extend an existing one. It seems like you could match the editable values with a regular expression easily. Do you only want the editable values included in the object, or all values regardless?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号