Reusing KHTMLs CSS parser for a KDevelop language plugin

Niko Sams niko.sams at
Thu Oct 22 07:33:29 BST 2009

On Wed, Oct 21, 2009 at 23:19, Milian Wolff <mail at> wrote:
> On Wednesday 21 October 2009 22:38:18 Maksim Orlovich wrote:
>> <snip>
>> > Alternatively to the above, are there maybe KHTML APIs I can use that
>> > give me a low-level analysis of a given CSS file? I'd need e.g. a list of
>> > rule definitions, imports, charset statements, together with line numbers
>> > where they occur. That should actually be enough to build a DUChain.
>> That exists already --- DOM level 2 CSS is exported to C++, see the header
>> files dom/css_*.h. It may not be perfect though, since CSS parsing is
>>  freaky, and very much non-uniform --- pretty much every property requires
>>  special parsing code to get right; and so you only get an accurate model
>>  for things KHTML supports; so for example properties with other vendor
>>  prefixes would not get much info. Also a lot of other implementations like
>>  Gecko simply chose to ignore parts of DOM2 CSS, so some methods may not
>>  have had much real-life testing..
>> There is no line number info, though; and I am not sure def/use is the
>>  right abstraction, either --- CSS is pattern matched, after all, in a
>>  fairly complex way.
> The thing is, we don't really need DOM access. I mean, we want to support the
> developer _while writing the css document_. We don't know to which documents
> he applies this style. Hence DOM sounds like nothing for us.
Just had an idea: Usually you write first the html and then style it.
What if you would
open the html in an kdevelop-embedded-browser (or connected in another
way) and get
code completion for the current document! And even other cool stuff
like highlighting
the elements that match the current css rule, live previewing the
changes without reload...
Ok, I will stop now, somebody has to implement all this :D


More information about the kde-core-devel mailing list