(Bug 49929) Several bug fixes in wikitext escaping

* Examples in the bug report plus some more are fixed.

* The bugs reported in the bug report were from bad regexps.

* Additional testing also uncovered a more serious class of
  errors from failing to test for presence of "\n" in the string
  being tested.

  The following snippets which weren't being nowiki-escaped
  all properly nowiki-escape now.  Other test snippets can be
  created by adding comments in place of leading/trailing spaces.
  More tests are left as an exercise to the reader.

  Pre-escaping tests:
  -------------------
  Multiple leading spaces     : "  a", " \ta", "\t\ta"
  Spaces after a NL           : "a\n b",  "a\n\tb", "a\n\t\t b"

  Heading-escaping tests:
  -----------------------
  Trailing spaces             : "=a= ", "=a=\t"
  Leading NL break            : "a\n=b="
  Trailing NL break           : "=a=\nb"
  Trailing comments & spaces  : "=a= <\!--cmt--> \nb"

  The following snippet which was being unnecessarily
  nowiki-escaped is no longer nowiki escaped now.

  Elements after heading char : "=a=<div>b</div>"

* The two new failing tests in html2wt mode are legitimate failures
  -- they were being passed incorrectly before this patch.

* The failing html2html ref test is because the wikitext escaping
  code does not know that leading whitespace in refs is harmless
  (pre-handler doesn't run on ref-content).

  TODO: This should be fixed soon since this might be a problem
  for new citations if they start with leading whitespace.

* TODO: Add more parser tests.

Change-Id: I925d8ded2da16e0bd107fde77d58beff2aac3782
Merge "(Bug 49929) Several bug fixes in wikitext escaping"