aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/postprocessors.py
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2018-07-27 10:23:55 -0400
committerGitHub <noreply@github.com>2018-07-27 10:23:55 -0400
commit6ee07d2735d86d7a3d0b31c3409d42d31997a96c (patch)
tree3e7827f8ef4581c321a4a53ccc05d46e9975823f /markdown/postprocessors.py
parent5d2cde235c9ad17cdc3678ed51e1d693967b5a5a (diff)
downloadmarkdown-6ee07d2735d86d7a3d0b31c3409d42d31997a96c.tar.gz
markdown-6ee07d2735d86d7a3d0b31c3409d42d31997a96c.tar.bz2
markdown-6ee07d2735d86d7a3d0b31c3409d42d31997a96c.zip
Replace homegrown OrderedDict with purpose-built Registry. (#688)
All processors and patterns now get "registered" to a Registry. Each item is given a name (string) and a priority. The name is for later reference and the priority can be either an integer or float and is used to sort. Priority is sorted from highest to lowest. A Registry instance is a list-like iterable with the items auto-sorted by priority. If two items have the same priority, then they are listed in the order there were "registered". Registering a new item with the same name as an already registered item replaces the old item with the new item (however, the new item is sorted by its newly assigned priority). To remove an item, "deregister" it by name or index. A backwards compatible shim is included so that existing simple extensions should continue to work. DeprecationWarnings will be raised for any code which calls the old API. Fixes #418.
Diffstat (limited to 'markdown/postprocessors.py')
-rw-r--r--markdown/postprocessors.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/markdown/postprocessors.py b/markdown/postprocessors.py
index f59e070..0fb4406 100644
--- a/markdown/postprocessors.py
+++ b/markdown/postprocessors.py
@@ -12,16 +12,15 @@ from __future__ import absolute_import
from __future__ import unicode_literals
from collections import OrderedDict
from . import util
-from . import odict
import re
def build_postprocessors(md_instance, **kwargs):
""" Build the default postprocessors for Markdown. """
- postprocessors = odict.OrderedDict()
- postprocessors["raw_html"] = RawHtmlPostprocessor(md_instance)
- postprocessors["amp_substitute"] = AndSubstitutePostprocessor()
- postprocessors["unescape"] = UnescapePostprocessor()
+ postprocessors = util.Registry()
+ postprocessors.register(RawHtmlPostprocessor(md_instance), 'raw_html', 30)
+ postprocessors.register(AndSubstitutePostprocessor(), 'amp_substitute', 20)
+ postprocessors.register(UnescapePostprocessor(), 'unescape', 10)
return postprocessors