Skip to content

Commit 41cc055

Browse files
author
Waylan Limberg
committed
Footnote ids contain dashes when outputing HTML5.
Previously they contained colons - and they still do for HTML4 and XHTML. Fixes #180.
1 parent 28deb9b commit 41cc055

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

docs/release-2.3.txt

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ The whitelesited schemes are: 'http', 'https', 'ftp', 'ftps', 'mailto',
2323
'news'. Schemeless urls are also permitted, but are checked in other ways -
2424
as they have been for some time.
2525

26+
* The ids assigned to footnotes now contain a dash (`-`) rather than a colon
27+
(`:`) when `output_format` it set to "html5" or "xhtml5". If you are making
28+
reference to those ids in your JavaScript or CSS and using the HTML5 output,
29+
you will need to update your code accordingly. No changes are necessary if
30+
you are outputing XHTML (the default) or HTML4.
31+
2632
What's New in Python-Markdown 2.3
2733
---------------------------------
2834

markdown/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ def __init__(self, *args, **kwargs):
132132

133133
self.references = {}
134134
self.htmlStash = util.HtmlStash()
135+
self.set_output_format(kwargs.get('output_format', 'xhtml1'))
135136
self.registerExtensions(extensions=kwargs.get('extensions', []),
136137
configs=kwargs.get('extension_configs', {}))
137-
self.set_output_format(kwargs.get('output_format', 'xhtml1'))
138138
self.reset()
139139

140140
def build_parser(self):

markdown/extensions/footnotes.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ def extendMarkdown(self, md, md_globals):
6262
md.registerExtension(self)
6363
self.parser = md.parser
6464
self.md = md
65+
self.sep = ':'
66+
if self.md.output_format in ['html5', 'xhtml5']:
67+
self.sep = '-'
6568
# Insert a preprocessor before ReferencePreprocessor
6669
md.preprocessors.add("footnote", FootnotePreprocessor(self),
6770
"<reference")
@@ -106,16 +109,16 @@ def setFootnote(self, id, text):
106109
def makeFootnoteId(self, id):
107110
""" Return footnote link id. """
108111
if self.getConfig("UNIQUE_IDS"):
109-
return 'fn:%d-%s' % (self.unique_prefix, id)
112+
return 'fn%s%d-%s' % (self.sep, self.unique_prefix, id)
110113
else:
111-
return 'fn:%s' % id
114+
return 'fn%s%s' % (self.sep, id)
112115

113116
def makeFootnoteRefId(self, id):
114117
""" Return footnote back-link id. """
115118
if self.getConfig("UNIQUE_IDS"):
116-
return 'fnref:%d-%s' % (self.unique_prefix, id)
119+
return 'fnref%s%d-%s' % (self.sep, self.unique_prefix, id)
117120
else:
118-
return 'fnref:%s' % id
121+
return 'fnref%s%s' % (self.sep, id)
119122

120123
def makeFootnotesDiv(self, root):
121124
""" Return div of footnotes as et Element. """
@@ -171,7 +174,6 @@ def run(self, lines):
171174
"""
172175
newlines = []
173176
i = 0
174-
#import pdb; pdb.set_trace() #for i, line in enumerate(lines):
175177
while True:
176178
m = DEF_RE.match(lines[i])
177179
if m:

0 commit comments

Comments
 (0)