examples with nested classes, e.g. microformats2 #42

Open
tantek opened this Issue Dec 8, 2016 · 2 comments

Projects

None yet

2 participants

@tantek
Member
tantek commented Dec 8, 2016

Just saw the lightning talk at #MozAloha - very cool!

Is it possible to write Fathom rules to detect nested class names? Perhaps even with additional CSS Selector constraints?

Would it be possible to add a simple example rule set for parsing data from nested elements with particular class names?

For example, I'd like to write rules like the nested class name rules for microformats2 parsing:

http://microformats.org/wiki/microformats2-parsing#parse_an_element_for_class_microformats

Or at least rules like:
.h-entry .p-name -> title = textContent

Happy to help get something simple working and iterate from there.

@tantek
Member
tantek commented Dec 8, 2016

cc: @mixedpuppy who may have some suggestions for how to do this in Firefox in particular

@erikrose
Member
erikrose commented Dec 8, 2016

Absolutely. For simple cases, you could just use CSS selectors, like...

const rules = ruleset(
    rule(dom('.h-entry .p-name'), type('title').note(fnode => fnode.element.textContent))
);

Soon I plan to add contains() and matching() to the left-hand side of rules that will make it easier to express typed containment (a "foo"-typed node within a "title"-typed node) and arbitrary predicates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment