wiki: Fix table of contents links in some browsers.

This commit is contained in:
Andre D
2013-01-28 16:21:14 -05:00
committed by Neil Williams
parent cd88393fa6
commit 02191efe6d

View File

@@ -270,7 +270,7 @@ def wikimarkdown(text):
return SC_OFF + WIKI_MD_START + text + WIKI_MD_END + SC_ON
title_re = re.compile('\w|-')
title_re = re.compile('[^\w-]')
header_re = re.compile('^h[1-6]$')
def inject_table_of_contents(soup, prefix):
header_ids = Counter()
@@ -293,8 +293,8 @@ def inject_table_of_contents(soup, prefix):
aid = unicode(BeautifulSoup(contents, convertEntities=BeautifulSoup.XML_ENTITIES))
# Prefix with PREFIX_ to avoid ID conflict with the rest of the page
aid = u'%s_%s' % (prefix, aid.replace(" ", "_").lower())
# Convert down to ascii by url encoding
aid = urllib.quote(aid.encode('utf-8'))
# Convert down to ascii replacing special characters with hex
aid = str(title_re.sub(lambda c: '.%X' % ord(c.group()), aid))
# Check to see if a tag with the same ID exists
id_num = header_ids[aid] + 1