aboutsummaryrefslogtreecommitdiffstats
path: root/markdown.py
diff options
context:
space:
mode:
authorArtem Yunusov <nedrlab@gmail.com>2008-10-16 14:55:37 +0500
committerArtem Yunusov <nedrlab@gmail.com>2008-10-16 14:55:37 +0500
commitcf1ab89854cdf75a8f658861a7c0133158737385 (patch)
treece4f18402b9177b2bf02ee3fe5f7dc44f5055759 /markdown.py
parent4af326cf16d60da0ee6c7c15bfe3f8d7fe745f04 (diff)
downloadmarkdown-cf1ab89854cdf75a8f658861a7c0133158737385.tar.gz
markdown-cf1ab89854cdf75a8f658861a7c0133158737385.tar.bz2
markdown-cf1ab89854cdf75a8f658861a7c0133158737385.zip
Made third argument of Treap.add function optional.
Diffstat (limited to 'markdown.py')
-rwxr-xr-xmarkdown.py76
1 files changed, 30 insertions, 46 deletions
diff --git a/markdown.py b/markdown.py
index d9bd938..972e827 100755
--- a/markdown.py
+++ b/markdown.py
@@ -1637,6 +1637,7 @@ class Treap(dict):
def __init__(self, default='end'):
self.default = '_'+('begin',default)[default in ('begin','end')]
self.priority = None
+ self._lastItem = "_begin"
self._tree = {
'_begin' : {'heap':('_begin','B'),'kids' : {},'prio' : 'B'}
,'_end' : {'heap':('_end','E'),'kids' : {},'prio' : 'E'}
@@ -1666,9 +1667,12 @@ class Treap(dict):
self._reset()
dict.__setitem__(self, key, val)
- def add(self, k, v, p):
+ def add(self, k, v, p=None):
"""Adds key/value to dict and sets priority."""
+ if p is None:
+ p = self._lastItem
self.__setitem__(k, v, p)
+ self._lastItem = ">%s" % k
def _reset(self): self._heap=[];self._keys=[];self._vals=[];self._items=[];
@@ -1787,67 +1791,47 @@ class Markdown:
self.textPreprocessors = Treap()
self.textPreprocessors.add("html_block",
- HtmlBlockPreprocessor(self), "_begin")
+ HtmlBlockPreprocessor(self))
self.preprocessors = Treap()
- self.preprocessors.add("header", HeaderPreprocessor(self), "_begin")
- self.preprocessors.add("line", LinePreprocessor(self), ">header")
- self.preprocessors.add("reference", ReferencePreprocessor(self),
- ">line")
+ self.preprocessors.add("header", HeaderPreprocessor(self))
+
+ self.preprocessors.add("line", LinePreprocessor(self))
+ self.preprocessors.add("reference", ReferencePreprocessor(self))
# footnote preprocessor will be inserted with "<reference"
self.postprocessors = Treap()
- self.postprocessors.add("prettify", PrettifyPostprocessor(self),
- "_begin")
+ self.postprocessors.add("prettify", PrettifyPostprocessor(self))
self.textPostprocessors = Treap()
- self.textPostprocessors.add("raw_html", RawHtmlTextPostprocessor(self),
- "_begin")
- self.textPostprocessors.add("amp_substitute", AndSubstitutePostprocessor(),
- ">raw_html")
+ self.textPostprocessors.add("raw_html", RawHtmlTextPostprocessor(self))
+ self.textPostprocessors.add("amp_substitute", AndSubstitutePostprocessor())
# footnote postprocessor will be inserted with ">amp_substitute"
self.prePatterns = []
self.inlinePatterns = Treap()
- self.inlinePatterns.add("backtick", BacktickPattern(BACKTICK_RE),
- "_begin")
- self.inlinePatterns.add("escape", SimpleTextPattern(ESCAPE_RE),
- ">backtick")
- self.inlinePatterns.add("reference",
- ReferencePattern(REFERENCE_RE, self), ">escape")
- self.inlinePatterns.add("link", LinkPattern(LINK_RE, self),
- ">reference")
- self.inlinePatterns.add("image_link", ImagePattern(IMAGE_LINK_RE, self),
- ">link")
+ self.inlinePatterns.add("backtick", BacktickPattern(BACKTICK_RE))
+ self.inlinePatterns.add("escape", SimpleTextPattern(ESCAPE_RE))
+ self.inlinePatterns.add("reference", ReferencePattern(REFERENCE_RE, self))
+ self.inlinePatterns.add("link", LinkPattern(LINK_RE, self))
+ self.inlinePatterns.add("image_link", ImagePattern(IMAGE_LINK_RE, self))
self.inlinePatterns.add("image_reference",
- ImageReferencePattern(IMAGE_REFERENCE_RE, self),
- ">image_link")
- self.inlinePatterns.add("autolink", AutolinkPattern(AUTOLINK_RE, self),
- ">image_reference")
- self.inlinePatterns.add("automail", AutomailPattern(AUTOMAIL_RE, self),
- ">autolink")
+ ImageReferencePattern(IMAGE_REFERENCE_RE, self))
+ self.inlinePatterns.add("autolink", AutolinkPattern(AUTOLINK_RE, self))
+ self.inlinePatterns.add("automail", AutomailPattern(AUTOMAIL_RE, self))
self.inlinePatterns.add("linebreak2",
- SubstituteTagPattern(LINE_BREAK_2_RE, 'br'),
- ">automail")
+ SubstituteTagPattern(LINE_BREAK_2_RE, 'br'))
self.inlinePatterns.add("linebreak",
- SubstituteTagPattern(LINE_BREAK_RE, 'br'),
- ">linebreak2")
- self.inlinePatterns.add("html", HtmlPattern(HTML_RE, self),
- ">linebreak")
- self.inlinePatterns.add("entity", HtmlPattern(ENTITY_RE, self),
- ">html")
- self.inlinePatterns.add("not_strong", SimpleTextPattern(NOT_STRONG_RE),
- ">entity")
+ SubstituteTagPattern(LINE_BREAK_RE, 'br'))
+ self.inlinePatterns.add("html", HtmlPattern(HTML_RE, self))
+ self.inlinePatterns.add("entity", HtmlPattern(ENTITY_RE, self))
+ self.inlinePatterns.add("not_strong", SimpleTextPattern(NOT_STRONG_RE))
self.inlinePatterns.add("strong_em",
- DoubleTagPattern(STRONG_EM_RE, 'strong,em'),
- ">not_strong")
- self.inlinePatterns.add("strong", SimpleTagPattern(STRONG_RE, 'strong'),
- ">strong_em")
- self.inlinePatterns.add("emphasis", SimpleTagPattern(EMPHASIS_RE, 'em'),
- ">strong")
+ DoubleTagPattern(STRONG_EM_RE, 'strong,em'))
+ self.inlinePatterns.add("strong", SimpleTagPattern(STRONG_RE, 'strong'))
+ self.inlinePatterns.add("emphasis", SimpleTagPattern(EMPHASIS_RE, 'em'))
self.inlinePatterns.add("emphasis2",
- SimpleTagPattern(EMPHASIS_2_RE, 'em'),
- ">emphasis")
+ SimpleTagPattern(EMPHASIS_2_RE, 'em'))
# The order of the handlers matters!!!
self.references = {}