Improve formatting for Markdown.

We try to keep our Markdown rendered output as close as possible to the
source text formatting, but there's only so much that can be done by
CSS. This change massively improves the rendering by introducing a set
of new Markdown processors that clean up newlines and attributes, giving
us the output our users would expect.

This primarily does the following:

* Keeps the correct number of blank lines between blocks (by default,
  Python Markdown will just trim them away).

* Keeps code blocks (and certain other extension-provided blocks) from
  having an unnecessary extra blank line after the HTML (interfering
  with our <pre> formatting).

* Allows line breaks in lists.

* Wrapped lines of text inside an ordered list item no longer shows the
  wrapped text at the same indentation level as the item's counter
  value. It now properly stays within the confines of the list item.

  To make this happen, we had to use CSS counters and some custom
  styles (using `display: table` and friends).

* Allows ordered lists to start at a particular value. We do this by
  turning off lazy_ol, which gives us a start= attribute on the list.
  Then, to get it to play nice with the custom counters mentioned above,
  we have a Markdown block processor that adds CSS to the <ol> that
  initializes the counter to the right value.

* Adds unit tests to ensure these formatting rules do not break in
  the future.

The result is much nicer formatting for most cases (all cases I've
tested).

Reviewed at https://reviews.reviewboard.org/r/6643/
Improve escaping text for display in Markdown.

Our former approach of escaping text for use in Markdown was to define a
large regex containing patterns, and any pattern that matches was
fully escaped. This was fine for simple patterns, but it wasn't possible
to escape only a single character or set of characters in more complex
patterns.

Each pattern in the regex can now capture zero or more groups, each of
which will be individually escaped. To do this, we loop through the
groups, escaping each match and inserting that into the resulting
string. It means we do loop on each match through each possible capture
group (including those from other patterns), but it also means we no
longer have to go back through the whole string looking for and escaping
characters, just subsets. (We're really talking a ~50 microsecond
difference for a commit message with a handful of Markdown-unsafe
content anyway).

With this change, we were able to make two escaping fixes:

1. Lines starting with things like "1.2.", which are not list items,
   are no longer escaped.

2. '>' characters are no longer escaped unless they're an autolink
   (like <foo@example.com> or <http://example.com>) or a blockquote
   (single level or nested).

Reviewed at https://reviews.reviewboard.org/r/6653/
Fixes tabs appearing in the subject line of emails.

Python 2.7 has a problem that causes tabs to be used to break up long headers
instead of spaces. When Review Board sends an email with a Subject longer than
62 characters, it inserts a tab to seperate the text into mutiple lines.

Now instead of the Subject header being seperatated by tabs it is seperated by
spaces.

Testing Done:
Ran unit tests.

Bugs closed: 3613

Reviewed at https://reviews.reviewboard.org/r/6647/
Merge branch 'release-2.0.x'
Trivial fix for webapi test failures from the ">" Markdown escaping change.

Some of the unit tests in the webapi tested against an escaped ">", but
as of a recent change, this is no longer escaped. This is a simple fix
to remove the escaping.
Fix a renamed file that snuck in.

My previous commit had a file in the index that shouldn't have been
there. Oops. It's been fixed.
Merge branch 'release-2.0.x'
Update email notification logic to honor should_send_own_update flag

If a user was explicitly listed in a review request along with also being a
member of a group assigned to a request, the should_send_own_update setting in
the users profile would not be honored because the check was happening before
we added explicit users to the to_field list. This also fixes the issue where
we were trying to remove email address that might not actually exist (a blank
review request).

Testing Done:
Had a user create a review request that lists me as an explicit reviewer along
with a group that I'm also a member of; commented on the issue and I never
recieved an email notification.

Bugs closed: 3681, 3684

Reviewed at https://reviews.reviewboard.org/r/6663/
Merge branch 'release-2.0.x'
Issue 3444: Autocomplete is too agressive

Matches beginning of:
- in Group: matches beginning of group name or group alias.
- in People: matches beginning of username or first or last name.

- Autocomplete only replaces input with first dropdown item if input is a
  prefix for the item.
- COMMA key no longer triggers autocomplete; TAB and ENTER keys only work.
- Delete key (not backspace) no longer hides autocomplete dropdown.
- matches dropdown hide after a previous match has been made on the input box.
- Reverted delay values.

Issues reported:
https://code.google.com/p/reviewboard/issues/detail?id=3622
https://code.google.com/p/reviewboard/issues/detail?id=3629
https://code.google.com/p/reviewboard/issues/detail?id=3620

Testing Done:
- No unit tests currently exist for ui.autocomplete.js
- Test input that matches beginning of group name or group alias. Making sure
  each group has a unique name and alias so it's only matching one field.
- Test input that matches beginning of username or first name or last name.
  Making sure each user has unique, username, first and last name so it's only
  matching one field.
- Header bar search tested and still works as expected. Matching one of group
  name, group alias, username, first name or last name.

With 2 users and 2 groups (John and Johndone), tested the following cases on
Windows 8.1 with Chrome 38, Firefox 32, and IE11, and on Linux Mint 17 (Ubuntu
14) with Chromium 37 and Firefox 32:
- type 'John' (wait for dropdown), type 'd', hit TAB/ENTER quickly, does not
  autocomplete since the dropdown hasn't updated due to delay.
- type 'Jo' (wait for dropdown), hit TAB/ENTER, autocompletes to John.
- type 'Johnd' (wait for dropdown', hit TAB/ENTER, autocompletes to Johndoe,
  remove 'ndoe', hit TAB/ENTER, autocompletes to John.
- Comma acts like regular input, does not trigger autocomplete. Starting to
  type another name after a comma behaves normally.
- TAB acts as normal when autocomplete dropdown not present (jumping through
  elements)
- ENTER act as normal when autocomplete dropdown not present (hitting OK below
  input field)

Bugs closed: 3444

Reviewed at https://reviews.reviewboard.org/r/6333/
Short-circuit diff patching for moved files with no changes.

The comment for `DiffChunkGenerator.get_chunks()` indicates that moved files
with no changes should be returned as an empty list without actually fetching
source files or applying patches, but this wasn't the case. This change fixes
the conditional to return the empty list.

Testing done:
- Tested a moved file with no changes. Saw that it displayed correctly without
  ever calling out to 'patch'
- Tested a moved+edited file. Saw that it displayed correctly.
- Ran unit tests.

Reviewed at https://reviews.reviewboard.org/r/6655/
Merge branch 'release-2.0.x'
Fix trimming trailing paragraphs in Markdown that contain elements.

The code for trimming empty paragraphs didn't consider that a paragraph
may have children but not text. It now checks for any child nodes before
determining whether to trim.

Reviewed at https://reviews.reviewboard.org/r/6671/
Remove illegal characters from XML strings before parsing.

It's easy for people to unintentionally inject XML-unsafe characters
into a string from a copy/paste when filling out the Description or
Testing Done fields of a review request.

We now sanitize the XML before attempting to parse it, removing any
illegal characters. The result is a string that can be safely parsed
with no noticeably defects.

Reviewed at https://reviews.reviewboard.org/r/6670/
Merge branch 'release-2.0.x'