aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmarkdown.py9
-rw-r--r--mdx/__init__.py0
-rw-r--r--mdx/mdx_codehilite.py (renamed from mdx_codehilite.py)0
-rw-r--r--mdx/mdx_extra.py (renamed from mdx_extra.py)0
-rw-r--r--mdx/mdx_fenced_code.py (renamed from mdx_fenced_code.py)0
-rw-r--r--mdx/mdx_footnotes.py (renamed from mdx_footnotes.py)0
-rw-r--r--mdx/mdx_headerid.py (renamed from mdx_headerid.py)37
-rw-r--r--mdx/mdx_imagelinks.py (renamed from mdx_imagelinks.py)0
-rw-r--r--mdx/mdx_meta.py (renamed from mdx_meta.py)0
-rw-r--r--mdx/mdx_rss.py (renamed from mdx_rss.py)0
-rw-r--r--mdx/mdx_tables.py (renamed from mdx_tables.py)0
-rw-r--r--mdx/mdx_wikilink.py (renamed from mdx_wikilink.py)0
12 files changed, 38 insertions, 8 deletions
diff --git a/markdown.py b/markdown.py
index 707b89c..38923ac 100755
--- a/markdown.py
+++ b/markdown.py
@@ -2135,11 +2135,14 @@ def load_extension(ext_name, configs = []):
module = __import__(extension_module_name)
except ImportError:
- message(WARN,
+ try:
+ module = __import__('.'.join(['mdx', extension_module_name]), {}, {}, ['mdx'])
+ except:
+ message(WARN,
"Couldn't load extension '%s' from \"%s\" - continuing without."
% (ext_name, extension_module_name) )
- # Return a dummy (do nothing) Extension as silent failure
- return Extension(configs={})
+ # Return a dummy (do nothing) Extension as silent failure
+ return Extension(configs={})
return module.makeExtension(configs.items())
diff --git a/mdx/__init__.py b/mdx/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/mdx/__init__.py
diff --git a/mdx_codehilite.py b/mdx/mdx_codehilite.py
index 73c1a79..73c1a79 100644
--- a/mdx_codehilite.py
+++ b/mdx/mdx_codehilite.py
diff --git a/mdx_extra.py b/mdx/mdx_extra.py
index e99bec4..e99bec4 100644
--- a/mdx_extra.py
+++ b/mdx/mdx_extra.py
diff --git a/mdx_fenced_code.py b/mdx/mdx_fenced_code.py
index c3d9f7f..c3d9f7f 100644
--- a/mdx_fenced_code.py
+++ b/mdx/mdx_fenced_code.py
diff --git a/mdx_footnotes.py b/mdx/mdx_footnotes.py
index b46efbb..b46efbb 100644
--- a/mdx_footnotes.py
+++ b/mdx/mdx_footnotes.py
diff --git a/mdx_headerid.py b/mdx/mdx_headerid.py
index 2360071..8947338 100644
--- a/mdx_headerid.py
+++ b/mdx/mdx_headerid.py
@@ -87,7 +87,9 @@ class HeaderIdExtension (markdown.Extension) :
# set defaults
self.config = {
'level' : ['1', 'Base level for headers.'],
- 'forceid' : ['True', 'Force all headers to have an id.']
+ 'forceid' : ['True', 'Force all headers to have an id.'],
+ 'toc_id' : ['toc', 'Set html id of wrapper div for TOC.'],
+ 'toc_marker': ['///TOC///', 'Marker to identify position of TOC.']
}
for key, value in configs:
@@ -97,6 +99,7 @@ class HeaderIdExtension (markdown.Extension) :
def extendMarkdown(self, md, md_globals) :
md.IDs = []
+ md.toc = Toc(self.getConfig('toc_id'), self.getConfig('toc_marker'))
def _processHeaderId(parent_elem, paragraph) :
'''
@@ -113,10 +116,14 @@ class HeaderIdExtension (markdown.Extension) :
parent_elem.append(h)
inline = etree.SubElement(h, "inline")
inline.text = m.group(2).strip()
- if m.group(3) :
- h.set('id', _unique_id(m.group(3)))
+ i = ''
+ if m.group(3):
+ i = _unique_id(m.group(3))
elif force_id:
- h.set('id', _create_id(m.group(2).strip()))
+ i = _create_id(m.group(2).strip())
+ if i:
+ h.set('id', i)
+ md.toc.append(i, inline.text)
else :
message(CRITICAL, "We've got a problem header!")
@@ -164,7 +171,27 @@ class HeaderIdExtension (markdown.Extension) :
h += '+'
return _unique_id(h)
-
+class Toc():
+ """ Store a Table of Contents from a documents Headers. """
+ def __init__(self, html_id, marker):
+ self.html_id = html_id
+ self.marker = marker
+ self.ids = []
+ self.labels = []
+
+ def append(self, id, label):
+ """ Append an item to the store. """
+ self.ids.append(id)
+ self.labels.append(label)
+
+ def render(self):
+ """ Render the TOC as HTML and return unicode. """
+ out = u'<div id="%s"><ul>\n' % self.html_id
+ for c in range(len(self.ids)):
+ out += u'<li><a href="#%s">%s</a></li>\n'%(self.ids[c], self.labels[c])
+ out += u'</ul></div>'
+ return out
+
def makeExtension(configs=None) :
return HeaderIdExtension(configs=configs)
diff --git a/mdx_imagelinks.py b/mdx/mdx_imagelinks.py
index e545b24..e545b24 100644
--- a/mdx_imagelinks.py
+++ b/mdx/mdx_imagelinks.py
diff --git a/mdx_meta.py b/mdx/mdx_meta.py
index 30dea8a..30dea8a 100644
--- a/mdx_meta.py
+++ b/mdx/mdx_meta.py
diff --git a/mdx_rss.py b/mdx/mdx_rss.py
index b88b9b5..b88b9b5 100644
--- a/mdx_rss.py
+++ b/mdx/mdx_rss.py
diff --git a/mdx_tables.py b/mdx/mdx_tables.py
index 829044c..829044c 100644
--- a/mdx_tables.py
+++ b/mdx/mdx_tables.py
diff --git a/mdx_wikilink.py b/mdx/mdx_wikilink.py
index 47037a6..47037a6 100644
--- a/mdx_wikilink.py
+++ b/mdx/mdx_wikilink.py