aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/extensions
diff options
context:
space:
mode:
authorWaylan Limberg <waylan.limberg@icloud.com>2018-07-27 10:55:41 -0400
committerGitHub <noreply@github.com>2018-07-27 10:55:41 -0400
commit25482261a494ad12c108435580ed13927bdc417c (patch)
tree5b108a5923322d5ceb3fa47d5f05d27a1039de7c /markdown/extensions
parent55d69f408cfabed6bd5953a4e7bfc926df2ac25b (diff)
downloadmarkdown-25482261a494ad12c108435580ed13927bdc417c.tar.gz
markdown-25482261a494ad12c108435580ed13927bdc417c.tar.bz2
markdown-25482261a494ad12c108435580ed13927bdc417c.zip
All Markdown instances are now 'md'. (#691)
Previously, instances of the Markdown class were represented as any one of 'md', 'md_instance', or 'markdown'. This inconsistency made it difficult when developing extensions, or just maintaining the existing code. Now, all instances are consistently represented as 'md'. The old attributes on class instances still exist, but raise a DeprecationWarning when accessed. Also on classes where the instance was optional, the attribute always exists now and is simply None if no instance was provided (previously the attribute wouldn't exist).
Diffstat (limited to 'markdown/extensions')
-rw-r--r--markdown/extensions/abbr.py2
-rw-r--r--markdown/extensions/codehilite.py4
-rw-r--r--markdown/extensions/extra.py2
-rw-r--r--markdown/extensions/fenced_code.py4
-rw-r--r--markdown/extensions/meta.py2
-rw-r--r--markdown/extensions/smarty.py14
-rw-r--r--markdown/extensions/toc.py12
7 files changed, 23 insertions, 17 deletions
diff --git a/markdown/extensions/abbr.py b/markdown/extensions/abbr.py
index a3d456f..e16043f 100644
--- a/markdown/extensions/abbr.py
+++ b/markdown/extensions/abbr.py
@@ -51,7 +51,7 @@ class AbbrPreprocessor(Preprocessor):
if m:
abbr = m.group('abbr').strip()
title = m.group('title').strip()
- self.markdown.inlinePatterns.register(
+ self.md.inlinePatterns.register(
AbbrInlineProcessor(self._generate_pattern(abbr), title), 'abbr-%s' % abbr, 2
)
# Preserve the line to prevent raw HTML indexing issue.
diff --git a/markdown/extensions/codehilite.py b/markdown/extensions/codehilite.py
index 8b9cd8f..ff2b845 100644
--- a/markdown/extensions/codehilite.py
+++ b/markdown/extensions/codehilite.py
@@ -212,10 +212,10 @@ class HiliteTreeprocessor(Treeprocessor):
css_class=self.config['css_class'],
style=self.config['pygments_style'],
noclasses=self.config['noclasses'],
- tab_length=self.markdown.tab_length,
+ tab_length=self.md.tab_length,
use_pygments=self.config['use_pygments']
)
- placeholder = self.markdown.htmlStash.store(code.hilite())
+ placeholder = self.md.htmlStash.store(code.hilite())
# Clear codeblock in etree instance
block.clear()
# Change to p element which will later
diff --git a/markdown/extensions/extra.py b/markdown/extensions/extra.py
index da4cb38..19b9db0 100644
--- a/markdown/extensions/extra.py
+++ b/markdown/extensions/extra.py
@@ -96,7 +96,7 @@ class MarkdownInHtmlProcessor(BlockProcessor):
block[nest_index[-1][1]:], True) # nest
def run(self, parent, blocks, tail=None, nest=False):
- self._tag_data = self.parser.markdown.htmlStash.tag_data
+ self._tag_data = self.parser.md.htmlStash.tag_data
self.parser.blockprocessors.tag_counter += 1
tag = self._tag_data[self.parser.blockprocessors.tag_counter]
diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py
index c38dabf..6b20ee9 100644
--- a/markdown/extensions/fenced_code.py
+++ b/markdown/extensions/fenced_code.py
@@ -55,7 +55,7 @@ class FencedBlockPreprocessor(Preprocessor):
# Check for code hilite extension
if not self.checked_for_codehilite:
- for ext in self.markdown.registeredExtensions:
+ for ext in self.md.registeredExtensions:
if isinstance(ext, CodeHiliteExtension):
self.codehilite_conf = ext.config
break
@@ -90,7 +90,7 @@ class FencedBlockPreprocessor(Preprocessor):
code = self.CODE_WRAP % (lang,
self._escape(m.group('code')))
- placeholder = self.markdown.htmlStash.store(code)
+ placeholder = self.md.htmlStash.store(code)
text = '%s\n%s\n%s' % (text[:m.start()],
placeholder,
text[m.end():])
diff --git a/markdown/extensions/meta.py b/markdown/extensions/meta.py
index 27adcb2..7af1f2d 100644
--- a/markdown/extensions/meta.py
+++ b/markdown/extensions/meta.py
@@ -73,7 +73,7 @@ class MetaPreprocessor(Preprocessor):
else:
lines.insert(0, line)
break # no meta data - done
- self.markdown.Meta = meta
+ self.md.Meta = meta
return lines
diff --git a/markdown/extensions/smarty.py b/markdown/extensions/smarty.py
index d25620b..c57d835 100644
--- a/markdown/extensions/smarty.py
+++ b/markdown/extensions/smarty.py
@@ -85,7 +85,7 @@ from __future__ import unicode_literals
from . import Extension
from ..inlinepatterns import HtmlInlineProcessor, HTML_RE
from ..treeprocessors import InlineProcessor
-from ..util import Registry
+from ..util import Registry, deprecated
# Constants for quote education.
@@ -151,11 +151,17 @@ HTML_STRICT_RE = HTML_RE + r'(?!\>)'
class SubstituteTextPattern(HtmlInlineProcessor):
- def __init__(self, pattern, replace, markdown_instance):
+ def __init__(self, pattern, replace, md):
""" Replaces matches with some text. """
HtmlInlineProcessor.__init__(self, pattern)
self.replace = replace
- self.markdown = markdown_instance
+ self.md = md
+
+ @property
+ @deprecated("Use 'md' instead.")
+ def markdown(self):
+ # TODO: remove this later
+ return self.md
def handleMatch(self, m, data):
result = ''
@@ -163,7 +169,7 @@ class SubstituteTextPattern(HtmlInlineProcessor):
if isinstance(part, int):
result += m.group(part)
else:
- result += self.markdown.htmlStash.store(part)
+ result += self.md.htmlStash.store(part)
return result, m.start(0), m.end(0)
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py
index f5f2b2e..babf956 100644
--- a/markdown/extensions/toc.py
+++ b/markdown/extensions/toc.py
@@ -219,8 +219,8 @@ class TocTreeprocessor(Treeprocessor):
build_etree_ul(toc_list, div)
- if 'prettify' in self.markdown.treeprocessors:
- self.markdown.treeprocessors['prettify'].run(div)
+ if 'prettify' in self.md.treeprocessors:
+ self.md.treeprocessors['prettify'].run(div)
return div
@@ -241,7 +241,7 @@ class TocTreeprocessor(Treeprocessor):
# Do not override pre-existing ids
if "id" not in el.attrib:
- innertext = stashedHTML2text(text, self.markdown)
+ innertext = stashedHTML2text(text, self.md)
el.attrib["id"] = unique(self.slugify(innertext, self.sep), used_ids)
toc_tokens.append({
@@ -260,10 +260,10 @@ class TocTreeprocessor(Treeprocessor):
self.replace_marker(doc, div)
# serialize and attach to markdown instance.
- toc = self.markdown.serializer(div)
- for pp in self.markdown.postprocessors:
+ toc = self.md.serializer(div)
+ for pp in self.md.postprocessors:
toc = pp.run(toc)
- self.markdown.toc = toc
+ self.md.toc = toc
class TocExtension(Extension):