aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2011-05-04 11:43:52 -0400
committerWaylan Limberg <waylan@gmail.com>2011-05-04 11:43:52 -0400
commit97be232c58c1ee1395bdce09fb9f55bfad4bb42d (patch)
treee92a20523d9a249b909a57bb6b6166e507e74768
parent303048f9d0da1ba5f917a0abf1da4a090d7a3a49 (diff)
downloadmarkdown-97be232c58c1ee1395bdce09fb9f55bfad4bb42d.tar.gz
markdown-97be232c58c1ee1395bdce09fb9f55bfad4bb42d.tar.bz2
markdown-97be232c58c1ee1395bdce09fb9f55bfad4bb42d.zip
Extension.getConfigs returns a dict and is used by the extensions that use configs. No more self.config['name'][0] weirdness anymore.
-rw-r--r--markdown/extensions/__init__.py4
-rw-r--r--markdown/extensions/codehilite.py10
-rw-r--r--markdown/extensions/fenced_code.py14
-rw-r--r--markdown/extensions/headerid.py8
-rw-r--r--markdown/extensions/toc.py12
-rw-r--r--markdown/extensions/wikilinks.py10
6 files changed, 26 insertions, 32 deletions
diff --git a/markdown/extensions/__init__.py b/markdown/extensions/__init__.py
index 3f36bb3..0222c91 100644
--- a/markdown/extensions/__init__.py
+++ b/markdown/extensions/__init__.py
@@ -22,8 +22,8 @@ class Extension:
return default
def getConfigs(self):
- """ Return all configs settings as a list of tuples. """
- return [(key, self.getConfig(key)) for key in self.config.keys()]
+ """ Return all configs settings as a dict. """
+ return dict([(key, self.getConfig(key)) for key in self.config.keys()])
def getConfigInfo(self):
""" Return all config descriptions as a list of tuples. """
diff --git a/markdown/extensions/codehilite.py b/markdown/extensions/codehilite.py
index 4be1ad5..588d647 100644
--- a/markdown/extensions/codehilite.py
+++ b/markdown/extensions/codehilite.py
@@ -168,10 +168,10 @@ class HiliteTreeprocessor(markdown.treeprocessors.Treeprocessor):
children = block.getchildren()
if len(children) == 1 and children[0].tag == 'code':
code = CodeHilite(children[0].text,
- linenos=self.config['force_linenos'][0],
- css_class=self.config['css_class'][0],
- style=self.config['pygments_style'][0],
- noclasses=self.config['noclasses'][0],
+ linenos=self.config['force_linenos'],
+ css_class=self.config['css_class'],
+ style=self.config['pygments_style'],
+ noclasses=self.config['noclasses'],
tab_length=self.markdown.tab_length)
placeholder = self.markdown.htmlStash.store(code.hilite(),
safe=True)
@@ -203,7 +203,7 @@ class CodeHiliteExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):
""" Add HilitePostprocessor to Markdown instance. """
hiliter = HiliteTreeprocessor(md)
- hiliter.config = self.config
+ hiliter.config = self.getConfigs
md.treeprocessors.add("hilite", hiliter, "_begin")
md.registerExtension(self)
diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py
index 4bcb5be..55e1773 100644
--- a/markdown/extensions/fenced_code.py
+++ b/markdown/extensions/fenced_code.py
@@ -92,12 +92,6 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
self.checked_for_codehilite = False
self.codehilite_conf = {}
- def getConfig(self, key):
- if key in self.config:
- return self.config[key][0]
- else:
- return None
-
def run(self, lines):
""" Match and store Fenced Code Blocks in the HtmlStash. """
@@ -122,11 +116,11 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
# is enabled, so we call it to highlite the code
if self.codehilite_conf:
highliter = CodeHilite(m.group('code'),
- linenos=self.codehilite_conf['force_linenos'][0],
- css_class=self.codehilite_conf['css_class'][0],
- style=self.codehilite_conf['pygments_style'][0],
+ linenos=self.codehilite_conf['force_linenos'],
+ css_class=self.codehilite_conf['css_class'],
+ style=self.codehilite_conf['pygments_style'],
lang=(m.group('lang') or None),
- noclasses=self.codehilite_conf['noclasses'][0])
+ noclasses=self.codehilite_conf['noclasses'])
code = highliter.hilite()
else:
diff --git a/markdown/extensions/headerid.py b/markdown/extensions/headerid.py
index 390a8ba..2332abe 100644
--- a/markdown/extensions/headerid.py
+++ b/markdown/extensions/headerid.py
@@ -126,8 +126,8 @@ class HeaderIdProcessor(markdown.blockprocessors.BlockProcessor):
def _get_meta(self):
""" Return meta data suported by this ext as a tuple """
- level = int(self.config['level'][0]) - 1
- force = self._str2bool(self.config['forceid'][0])
+ level = int(self.config['level']) - 1
+ force = self._str2bool(self.config['forceid'])
if hasattr(self.md, 'Meta'):
if self.md.Meta.has_key('header_level'):
level = int(self.md.Meta['header_level'][0]) - 1
@@ -158,7 +158,7 @@ class HeaderIdProcessor(markdown.blockprocessors.BlockProcessor):
def _create_id(self, header):
""" Return ID from Header text. """
h = ''
- for c in header.lower().replace(' ', self.config['separator'][0]):
+ for c in header.lower().replace(' ', self.config['separator']):
if c in ID_CHARS:
h += c
elif c not in punctuation:
@@ -182,7 +182,7 @@ class HeaderIdExtension (markdown.Extension):
md.registerExtension(self)
self.processor = HeaderIdProcessor(md.parser)
self.processor.md = md
- self.processor.config = self.config
+ self.processor.config = self.getConfigs()
# Replace existing hasheader in place.
md.parser.blockprocessors['hashheader'] = self.processor
diff --git a/markdown/extensions/toc.py b/markdown/extensions/toc.py
index 7a93b0f..2aeab4c 100644
--- a/markdown/extensions/toc.py
+++ b/markdown/extensions/toc.py
@@ -25,10 +25,10 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
last_li = None
# Add title to the div
- if self.config["title"][0]:
+ if self.config["title"]:
header = etree.SubElement(div, "span")
header.attrib["class"] = "toctitle"
- header.text = self.config["title"][0]
+ header.text = self.config["title"]
level = 0
list_stack=[div]
@@ -51,7 +51,7 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
# would causes an enless loop of placing a new TOC
# inside previously generated TOC.
- if c.text.find(self.config["marker"][0]) > -1 and not header_rgx.match(c.tag):
+ if c.text.find(self.config["marker"]) > -1 and not header_rgx.match(c.tag):
for i in range(len(p)):
if p[i] == c:
p[i] = div
@@ -78,7 +78,7 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
# Do not override pre-existing ids
if not "id" in c.attrib:
- id = self.config["slugify"][0](c.text)
+ id = self.config["slugify"](c.text)
if id in used_ids:
ctr = 1
while "%s_%d" % (id, ctr) in used_ids:
@@ -95,7 +95,7 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
link.text = c.text
link.attrib["href"] = '#' + id
- if int(self.config["anchorlink"][0]):
+ if int(self.config["anchorlink"]):
anchor = etree.SubElement(c, "a")
anchor.text = c.text
anchor.attrib["href"] = "#" + id
@@ -132,7 +132,7 @@ class TocExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):
tocext = TocTreeprocessor(md)
- tocext.config = self.config
+ tocext.config = self.getConfigs()
md.treeprocessors.add("toc", tocext, "_begin")
def makeExtension(configs={}):
diff --git a/markdown/extensions/wikilinks.py b/markdown/extensions/wikilinks.py
index 2b8abde..cf4b633 100644
--- a/markdown/extensions/wikilinks.py
+++ b/markdown/extensions/wikilinks.py
@@ -106,7 +106,7 @@ class WikiLinkExtension(markdown.Extension):
# append to end of inline patterns
WIKILINK_RE = r'\[\[([\w0-9_ -]+)\]\]'
- wikilinkPattern = WikiLinks(WIKILINK_RE, self.config)
+ wikilinkPattern = WikiLinks(WIKILINK_RE, self.getConfigs())
wikilinkPattern.md = md
md.inlinePatterns.add('wikilink', wikilinkPattern, "<not_strong")
@@ -120,7 +120,7 @@ class WikiLinks(markdown.inlinepatterns.Pattern):
if m.group(2).strip():
base_url, end_url, html_class = self._getMeta()
label = m.group(2).strip()
- url = self.config['build_url'][0](label, base_url, end_url)
+ url = self.config['build_url'](label, base_url, end_url)
a = markdown.util.etree.Element('a')
a.text = label
a.set('href', url)
@@ -132,9 +132,9 @@ class WikiLinks(markdown.inlinepatterns.Pattern):
def _getMeta(self):
""" Return meta data or config data. """
- base_url = self.config['base_url'][0]
- end_url = self.config['end_url'][0]
- html_class = self.config['html_class'][0]
+ base_url = self.config['base_url']
+ end_url = self.config['end_url']
+ html_class = self.config['html_class']
if hasattr(self.md, 'Meta'):
if self.md.Meta.has_key('wiki_base_url'):
base_url = self.md.Meta['wiki_base_url'][0]