added the ref number to the footnote

This commit is contained in:
mb @ ts 2018-03-06 12:01:42 +01:00
parent bdd673841b
commit abb64b784e

View File

@ -35,8 +35,7 @@ def parse_for_footnotes(article_or_page_generator):
all_content = [x for x in all_content if x is not None]
for article in sequence_gen(all_content):
if u"[ref]" in article._content and u"[/ref]" in article._content:
content = article._content.replace(u"[ref]", u"<x-simple-footnote>").replace(u"[/ref]",
u"</x-simple-footnote>")
content = article._content.replace(u"[ref]", u"<x-simple-footnote>").replace(u"[/ref]", u"</x-simple-footnote>")
parser = html5lib.HTMLParser(tree=html5lib.getTreeBuilder(u"dom"))
dom = parser.parse(content)
endnotes = []
@ -57,25 +56,20 @@ def parse_for_footnotes(article_or_page_generator):
endnotes.append((footnote, fnid, fnbackid))
number = dom.createElement(u"sup")
number.setAttribute(u"id", fnbackid)
numbera = dom.createElement(u"a")
numbera.setAttribute(u"href", u"#%s" % fnid)
numbera.setAttribute(u"class", u"simple-footnote")
numbera.appendChild(dom.createTextNode(six.text_type(count)))
number.setAttribute(u"class", u"simple-footnote")
number.appendChild(dom.createTextNode(six.text_type(count)))
txt = getText(footnote, recursive=True).replace(u"\n", u" ")
footnote_container = dom.createElement(u"span")
footnote_container.setAttribute(u"class", u"simple-footnote-container")
footnote_content = dom.createElement(u"span")
footnote_content.appendChild(dom.createTextNode('['+six.text_type(count)+'] '))
footnote_content.appendChild(footnote.firstChild)
footnote_content.setAttribute(u"class", u"simple-footnote-content")
footnote_container.appendChild(footnote_content)
print(footnote.firstChild)
numbera.setAttribute(u"title", txt)
number.appendChild(footnote_container)
number.appendChild(numbera)
# print(footnote.firstChild)
number.appendChild(footnote_container)
footnote.parentNode.insertBefore(number, footnote)
footnote.parentNode.insertBefore(footnote_container, footnote)
if endnotes: