aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/__init__.py2
-rw-r--r--markdown/extensions/footnotes.py16
-rw-r--r--tests/test_apis.py18
3 files changed, 28 insertions, 8 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py
index 3fd5efa..275ed2e 100644
--- a/markdown/__init__.py
+++ b/markdown/__init__.py
@@ -133,9 +133,9 @@ class Markdown(object):
self.references = {}
self.htmlStash = util.HtmlStash()
- self.set_output_format(kwargs.get('output_format', 'xhtml1'))
self.registerExtensions(extensions=kwargs.get('extensions', []),
configs=kwargs.get('extension_configs', {}))
+ self.set_output_format(kwargs.get('output_format', 'xhtml1'))
self.reset()
def build_parser(self):
diff --git a/markdown/extensions/footnotes.py b/markdown/extensions/footnotes.py
index 65ed597..9f93ad1 100644
--- a/markdown/extensions/footnotes.py
+++ b/markdown/extensions/footnotes.py
@@ -69,9 +69,6 @@ class FootnoteExtension(Extension):
md.registerExtension(self)
self.parser = md.parser
self.md = md
- self.sep = ':'
- if self.md.output_format in ['html5', 'xhtml5']:
- self.sep = '-'
# Insert a preprocessor before ReferencePreprocessor
md.preprocessors.add("footnote", FootnotePreprocessor(self),
"<reference")
@@ -113,19 +110,24 @@ class FootnoteExtension(Extension):
""" Store a footnote for later retrieval. """
self.footnotes[id] = text
+ def get_separator(self):
+ if self.md.output_format in ['html5', 'xhtml5']:
+ return '-'
+ return ':'
+
def makeFootnoteId(self, id):
""" Return footnote link id. """
if self.getConfig("UNIQUE_IDS"):
- return 'fn%s%d-%s' % (self.sep, self.unique_prefix, id)
+ return 'fn%s%d-%s' % (self.get_separator(), self.unique_prefix, id)
else:
- return 'fn%s%s' % (self.sep, id)
+ return 'fn%s%s' % (self.get_separator(), id)
def makeFootnoteRefId(self, id):
""" Return footnote back-link id. """
if self.getConfig("UNIQUE_IDS"):
- return 'fnref%s%d-%s' % (self.sep, self.unique_prefix, id)
+ return 'fnref%s%d-%s' % (self.get_separator(), self.unique_prefix, id)
else:
- return 'fnref%s%s' % (self.sep, id)
+ return 'fnref%s%s' % (self.get_separator(), id)
def makeFootnotesDiv(self, root):
""" Return div of footnotes as et Element. """
diff --git a/tests/test_apis.py b/tests/test_apis.py
index 4a7c7c7..bbe165d 100644
--- a/tests/test_apis.py
+++ b/tests/test_apis.py
@@ -358,6 +358,24 @@ class testSerializers(unittest.TestCase):
'<MixedCase>not valid <EMPHASIS>html</EMPHASIS><HR /></MixedCase>')
+ def buildExtension(self):
+ """ Build an extension which registers fakeSerializer. """
+ def fakeSerializer(elem):
+ # Ignore input and return hardcoded output
+ return '<div><p>foo</p></div>'
+
+ class registerFakeSerializer(markdown.extensions.Extension):
+ def extendMarkdown(self, md, md_globals):
+ md.output_formats['fake'] = fakeSerializer
+
+ return registerFakeSerializer()
+
+ def testRegisterSerializer(self):
+ self.assertEqual(markdown.markdown('baz',
+ extensions=[self.buildExtension()], output_format='fake'),
+ '<p>foo</p>')
+
+
class testAtomicString(unittest.TestCase):
""" Test that AtomicStrings are honored (not parsed). """