summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfacelessuser <faceless.shop@gmail.com>2017-11-18 09:11:45 -0700
committerfacelessuser <faceless.shop@gmail.com>2017-11-18 09:11:45 -0700
commita5fb7dcbf6bc7dd67ef41e41653e8b34093a714b (patch)
treec2c8f15afc15fb694ddf93ffba809a340df89572
parent6a69ddd9d9f161367385ee7f8b2cdaefc5568b47 (diff)
downloadpython-markdown-a5fb7dcbf6bc7dd67ef41e41653e8b34093a714b.tar.gz
Change excludes from method to class attribute
Remove `getExcludes` and replace with a class attribute `ANCESTOR_EXCLUDES`.
-rw-r--r--docs/extensions/api.txt10
-rw-r--r--markdown/inlinepatterns.py6
-rw-r--r--markdown/treeprocessors.py3
-rw-r--r--tests/test_apis.py4
4 files changed, 9 insertions, 14 deletions
diff --git a/docs/extensions/api.txt b/docs/extensions/api.txt
index 29bf83f..246bb27 100644
--- a/docs/extensions/api.txt
+++ b/docs/extensions/api.txt
@@ -53,7 +53,7 @@ A pseudo example:
Inline Patterns {: #inlinepatterns }
------------------------------------
-Inline Patterns implement the inline HTML element syntax for Markdown such as
+Inline Patterns implement the inline HTML element syntax for Markdown such as
`*emphasis*` or `[links](http://example.com)`. Pattern objects should be
instances of classes that inherit from `markdown.inlinepatterns.Pattern` or
one of its children. Each pattern object uses a single regular expression and
@@ -68,11 +68,9 @@ must have the following methods:
Accepts a match object and returns an ElementTree element of a plain
Unicode string.
-* **`getExcludes()`**:
-
- Returns an array of tag names that are undesirable ancestors. The pattern
- should not match if it would cause the content to be a descendant of one
- of the tag names in the list.
+Also, Inline Patterns can define the property `ANCESTOR_EXCLUDES` with either
+a list or tuple of undesirable ancestors. The pattern should not match if it
+would cause the content to be a descendant of one of the defined tag names.
Note that any regular expression returned by `getCompiledRegExp` must capture
the whole block. Therefore, they should all start with `r'^(.*?)'` and end
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py
index f483f99..2f00b3d 100644
--- a/markdown/inlinepatterns.py
+++ b/markdown/inlinepatterns.py
@@ -189,6 +189,8 @@ The pattern classes
class Pattern(object):
"""Base class that inline patterns subclass. """
+ ANCESTOR_EXCLUDES = tuple()
+
def __init__(self, pattern, markdown_instance=None):
"""
Create an instant of an inline pattern.
@@ -207,10 +209,6 @@ class Pattern(object):
if markdown_instance:
self.markdown = markdown_instance
- def getExcludes(self):
- """Get tag to exclude."""
- return []
-
def getCompiledRegExp(self):
""" Return a compiled regular expression. """
return self.compiled_re
diff --git a/markdown/treeprocessors.py b/markdown/treeprocessors.py
index ab31dd6..f159a8a 100644
--- a/markdown/treeprocessors.py
+++ b/markdown/treeprocessors.py
@@ -231,7 +231,8 @@ class InlineProcessor(Treeprocessor):
Returns: String with placeholders instead of ElementTree elements.
"""
- for exclude in pattern.getExcludes():
+
+ for exclude in pattern.ANCESTOR_EXCLUDES:
if exclude.lower() in self.ancestors:
return data, False, 0
diff --git a/tests/test_apis.py b/tests/test_apis.py
index cbcb989..48e79e8 100644
--- a/tests/test_apis.py
+++ b/tests/test_apis.py
@@ -778,9 +778,7 @@ class TestAncestorExclusion(unittest.TestCase):
class AncestorExample(markdown.inlinepatterns.SimpleTagPattern):
""" Ancestor Test. """
- def getExcludes(self):
- """ Tags to exclude. """
- return ['a']
+ ANCESTOR_EXCLUDES = ('a',)
def handleMatch(self, m):
""" Handle match. """