Add compatibility with Python-Markdown 2.5 and 2.6.

Review Request #8988 — Created June 3, 2017 and submitted — Latest diff uploaded




Our Markdown extensions and rendering logic made use of features or
implemented functions that have been deprecated in Python-Markdown 2.5
and 2.6. There were also behavioral changes since 2.4 that impacted our
WYSIWYG rendering.

The signature for makeExtension has changed, and the safe_mode
argument is scheduled for removal. To handle these changes, our
makeExtension functions now accept variable and keyword arguments,
which will work across all versions. To replace the safe_mode
argument, we now have a new EscapeHTMLExtension, which makes use of
Python-Markdown's recommended way of enabling escape mode (with some
small changes to prevent problems when using both the extension and
safe_mode in code that still needs to be migrated).

The WYSIWYG extension was seeing regressions in newline handling. The
extension overrides Python-Markdown's postprocessor for replacing
internal HTML placeholder markers with stashed HTML (needed by
extensions and certain Markdown directives) and attempts to prevent
trailing newlines from being injected. The implementation of
Python-Markdown's version changed, breaking the method we used to
override the behavior. We now have a re-implementation of this processor
that does an even better job of working around the newline issues, and
is actually faster than the original version.

Markdown.ESCAPE_CHARS was also no longer available. It's defined only
when an instance is created, which is a fairly heavy-weight operation
(for these purposes). Since the list has not changed since it was
introduced, it should be safe for us to define this ourselves.

2.7 will also need to now specify the full module path for all
extensions, including Python-Markdown's built-in extensions. Djblets
only specifies extension names in the tests, so this is a simple fix.

With these changes, clients will be able to use any version of Python
Markdown from 2.4 through 2.7, and likely future versions as well.

Unit tests ran against Python-Markdown 2.4 (our currently supported
version) and 2.6.

Tested with my real-world and crazy Markdown tests on Review Board with
both versions of Python-Markdown.