floki icon indicating copy to clipboard operation
floki copied to clipboard

Extend `fl-contains` to mach on children text as well

Open revati opened this issue 2 years ago • 1 comments

Feature goal

Extend fl-contains to mach on children text as well.

"<div>Some</div>"
|> Floki.parse_document!()
|> Floki.find("div:fl-contains('Some')")
|> IO.inspect(label: :first)
# Output: first: [{"div", [], ["Some"]}]

"<div><span>Some</span></div>"
|> Floki.parse_document!()
|> Floki.find("div:fl-contains('Some')")
|> IO.inspect(label: :second)
# Output: second: []
# Desired output: [{"div", [], [{"span", [], ["Some"]}]}]

revati avatar Feb 02 '22 10:02 revati

Hey @revati :wave:

You actually can archive similar results using a descendant combinator with the "all" selector ("*"). Please try:

"<div><span>Some</span></div>"
|> Floki.parse_document!()
|> Floki.find("div *:fl-contains('Some')")
|> IO.inspect(label: :second)
# Output: second: [{"span", [], ["Some"]}]
# Desired output: [{"div", [], [{"span", [], ["Some"]}]}]

philss avatar Feb 02 '22 13:02 philss