From 6ee07d2735d86d7a3d0b31c3409d42d31997a96c Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Fri, 27 Jul 2018 10:23:55 -0400 Subject: 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. --- markdown/preprocessors.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'markdown/preprocessors.py') diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py index 8c87ecf..cac0037 100644 --- a/markdown/preprocessors.py +++ b/markdown/preprocessors.py @@ -9,16 +9,15 @@ complicated. from __future__ import absolute_import from __future__ import unicode_literals from . import util -from . import odict import re def build_preprocessors(md_instance, **kwargs): """ Build the default set of preprocessors used by Markdown. """ - preprocessors = odict.OrderedDict() - preprocessors['normalize_whitespace'] = NormalizeWhitespace(md_instance) - preprocessors["html_block"] = HtmlBlockPreprocessor(md_instance) - preprocessors["reference"] = ReferencePreprocessor(md_instance) + preprocessors = util.Registry() + preprocessors.register(NormalizeWhitespace(md_instance), 'normalize_whitespace', 30) + preprocessors.register(HtmlBlockPreprocessor(md_instance), 'html_block', 20) + preprocessors.register(ReferencePreprocessor(md_instance), 'reference', 10) return preprocessors -- cgit v1.2.3