(Bug 64017) Template encapsulation bug fixes + cleanup.

getDOMRange
-----------
* After a template range was identified, range.start was being moved
  ahead past any meta-tags (since these meta tags would get deleted
  and data-mw would be set on other elements). However, this led to
  subtle bugs (in fostered content scenarios) where the new DOM range
  order didn't reflect the original source wikitext order.

* The real fix (which should have been there all along) is to leave
  the DOM range unaltered, but in the last step of the algorithm,
  move ahead to find the first non-meta node to add data-mw to.

* This patch makes both these fixes. In turn, this required:
  1. useless span-wrapping-eliding code (Ex: {{echo|foo}} scenarios)
     to get extracted into a helper and applied in the last step.
  2. meta-tag dsr info to be transferred to the first element of template
     content in nested-transclusion scenarios (even though this shouldn't
     have mattered). The presence of this info was being exploited
     by the strip-double-tds pass.

* For purposes of code clarity, reversed the polarity of setting
  range.flipped flag (see code comment).

findTopLevelNonOverlappingRanges
--------------------------------
* Generalized range overlapping code once more and got rid of a
  long-standing FIXME which had been ignored till now.

encapsulateTemplates
--------------------
* Handle the rare case where range.end might not be an ELEMENT.
* Some minor code cleanup for code readability reasons.
* Walk past meta-marker nodes to find the data-mw target node.
* Cleaned up the code and reorganized a bunch of variables into
  an encapInfo object to keep related information together.
* Added a FIXME about a possible bug for further investigation.

findWrappableTemplateRanges
---------------------------
* While debugging some selser failures and wt2html changes, noticed
  a FIXME that alerted to a different regexp in that function and
  in DOMUtils. Fixing the DOMUtils test to use the same regexp fixed
  the failures.

Parser tests
------------
* Because of cleanup and changes to how data-parsoid fields are updated,
  parser test output had to be changed for a few tests to reflect the
  new order.
* This also shows up as changes in previously blacklisted wt2hml tests.

Testing results
---------------
* 2 additional wt2html tests now pass.

* The remaining pages from Bug 64017 that used to fail do not
  report any more failed template encapsulations.

* This snippet now gets properly encapsulated.
-----
{|
|-
{{CH-PH-table
|holiday=[[Restoration of the Republic]]
|date=31 December
|GE =*
|number=1
|variableYN=N
}}

|}
-----

* TODO: Add a new parser test (not sure how to create a simple one)

Change-Id: I7d8f87142afedcbbacdb19b8bfa61722bf1f626a
Merge "(Bug 64017) Template encapsulation bug fixes + cleanup."