aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/blockparser.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/blockparser.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/blockparser.py')
-rw-r--r--markdown/blockparser.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/markdown/blockparser.py b/markdown/blockparser.py
index 32d3254..5e9d567 100644
--- a/markdown/blockparser.py
+++ b/markdown/blockparser.py
@@ -1,7 +1,6 @@
from __future__ import unicode_literals
from __future__ import absolute_import
from . import util
-from . import odict
class State(list):
@@ -46,7 +45,7 @@ class BlockParser:
"""
def __init__(self, markdown):
- self.blockprocessors = odict.OrderedDict()
+ self.blockprocessors = util.Registry()
self.state = State()
self.markdown = markdown
@@ -93,7 +92,7 @@ class BlockParser:
"""
while blocks:
- for processor in self.blockprocessors.values():
+ for processor in self.blockprocessors:
if processor.test(parent, blocks[0]):
if processor.run(parent, blocks) is not False:
# run returns True or None