How to use Chromium CSS parser to parse like CSS string?

280 views
Skip to first unread message

Junaid Iqbal

unread,
Mar 4, 2018, 4:40:05 PM3/4/18
to blink-dev
Hello:

I have CSS like syntax string e.g., 

#some-text 
   some-directive: some-value;
}
.some-text
{
some-directive: some-value;
}
 
I am receiving this value through http header in Document.h. I want to parse this string and and retrieve directive name and value depending upon my need. 

I was wondering can I use chromium's CSS parser to parse this string as my string is exactly in CSS like syntax?

Thanks in Advance!


Rune Lillesveen

unread,
Mar 8, 2018, 7:16:15 AM3/8/18
to Junaid Iqbal, blink-dev
CSSParser::ParseSheet, but you need a StyleSheetContents for that one. Take a look at where ParseSheet is called from.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/c3c4203a-5c9a-4b1a-9e1d-a8392ea33784%40chromium.org.
--
Rune Lillesveen

Junaid Iqbal

unread,
Mar 21, 2018, 9:43:44 AM3/21/18
to blink-dev, juna...@hotmail.com
Thanks Rune, that helps a lot. Now I am able to parse CSS string but the issue is that my directive names are my own defined, CSSParser::ParseSheet does not parse them.

The below string parsed properly as it is a proper CSS

body {color: red;}

but I have string like this:

body { my-own-directive: value; }

this is not parsed properly, when I call

rule->Properties().AsText();

I get an empty string.

Any help would be appreciated, thanks.

Rune Lillesveen

unread,
Mar 21, 2018, 9:53:33 AM3/21/18
to Junaid Iqbal, blink-dev
The CSS parser drops unkown CSS property names. You could use custom properties, but I don't know what you'd use this for. What project is this?
--
Rune Lillesveen

Junaid Iqbal

unread,
Mar 21, 2018, 10:02:25 AM3/21/18
to blink-dev, juna...@hotmail.com
Any starting point of how do I define custom properties?

Actually, I am sending a CSS like string through my webpage, I am using directives in the string that can be used to allow/block the content modification in my webpage.

Rune Lillesveen

unread,
Mar 21, 2018, 1:27:29 PM3/21/18
to Junaid Iqbal, blink-dev
https://developer.mozilla.org/en-US/docs/Web/CSS/--*

I still wonder why you are doing this. Why would you want to make a patched Blink/Chromium?

--
Rune Lillesveen

Junaid Iqbal

unread,
Mar 22, 2018, 1:16:59 PM3/22/18
to blink-dev, juna...@hotmail.com
I wonder the same lol

Its just a class project. Thanks for sharing about custom properties. Works great for me!

I set the string like this

body { --directive-name: value;}

Now I am able to fetch the value but could not fetch the directive-name. The function CSSUnresolvedProperty::GetPropertyNameAtomicString returns "variable" instead of the my

own directive name. Any suggestion on how do I get the directive name?

Thanks,

Alan Cutter

unread,
Mar 22, 2018, 9:30:36 PM3/22/18
to blink-dev, juna...@hotmail.com
What object are you reading the property declaration out of? Can you share your code in a CL?

Junaid Iqbal

unread,
Mar 23, 2018, 9:55:21 AM3/23/18
to blink-dev, juna...@hotmail.com
Thanks Alan for asking. I actually figured it out.

I was using CSSPropertyValueSet::PropertyReference object, I tried ToCSSCustomPropertyDeclaration(property.Value()).GetName() and it works.

Cheers!
Reply all
Reply to author
Forward
0 new messages