jch/html-pipeline — pull request #144 by Razer6 (2014-09-10 07:28:18+00:00)
Title: Do a second xpath search to match elements without parent node

Hey @jch, it turned out to be not that easy.

However I came up with a solution which needs a second `xpath` search. I changed the first also, because we don't need a `css` search. (`search` internally determines if we do a `xpath` or `css` search). To avoid creating a third list (happens for `(doc.xpath('.//text()') + doc.xpath('text()).each`), I process the nodes in two blocks. Therefore I factored out the processing steps in order to don't violate `DRY`.

On other possibility would be to ensure, that there is always a rode. Since this would affect other filters also, I din't bring this solution. Anyway, this fold be the following:

```ruby
def self.parse(document_or_html)
document_or_html ||= ''
if document_or_html.is_a?(String)
DocumentFragment.parse("#{document_or_html}")
else
document_or_html
end
end
```