Browse Source

added the ref number to the footnote

master
mb @ ts 6 years ago
parent
commit
abb64b784e
  1. 18
      complex_footnotes/simple_footnotes.py

18
complex_footnotes/simple_footnotes.py

@ -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:

Loading…
Cancel
Save