Newer versions of JSDOM implement getElementsByTagName correctly.
This means it returns a live node list. When calling
`Element.replaceChild` for links inside the loop over that
collection, elements disappear from the list, meaning we miss
every other item. Without this fix, the `clean-links` testcase
breaks.
When switching to a newer version of JSDOM, it is more literal
about listing whitespace as part of textContent, including
newlines and not normalizing multiple spaces.
It seems prudent to just always normalize whitespace for titles,
which are guaranteed to be pretty short anyway.
* Improve metadata extraction
* Recognize meta[property] as a space-separated list
* Recognize Dulin Core (dc|dcterm): metadata.
* Prefer Dublin Core, Open Graph, Twitter, and HTML in that order.
* _getArticleTitle() is now only used as fallback if document
doesn't provide good metadata.
This provides a descriptive error message if no document is passed, and
ignores the first argument if the second argument looks like
a reasonable DOM document instance.
Previously, `nextElem` was not actually proceeding to the next element, and therefore aborting the paragraph at the first `<br>` (rather than the first `<br><br>` as the comment indicates).
* Remove presentational HTML attributes
Fixes#383
This patch loops through a list of known-presentational attributes in HTML, attempting to remove each from each cleaned element. (Checking for the attribute's existence first seems to just add needless overhead.)
The extra check for the HTML namespace is to avoid removing attributes that inline SVG needs.
* Only remove `width`/`height` for certain elements
Embedded media elements are allowed to have them, but not others.
* Address PR feedback
* Fix loop index formatting
* Only remove `width`/`height` from certain elements
* Combine logic into a single check/remove
* Attempt fixing my recursion
* One weird trick to get your loops to run
* Add inline SVG bailout
Try not to touch any styles for `<svg>`, because it's inherently presentational.
* Update tests to match newly-removed attributes
* Oh those wacky SVGs
The `position:absolute` is a trick to import clipping paths into the document without putting a big 300×150 empty space in it. (`display:none` and such disable the clipPath in some browsers.)
* Whoops, missed some `width`s
* Normalize SVG tagName
JSDOMParser differs from the official DOM here
This adds a number of comments and a wordCount helper function to try to make the code
a bit more readable (which seemed appropriate considering the number of regular expressions).