|
@@ -7,7 +7,8 @@ import six
|
|
|
|
|
|
RAW_FOOTNOTE_CONTAINERS = ["code"]
|
|
RAW_FOOTNOTE_CONTAINERS = ["code"]
|
|
|
|
|
|
-def getText(node, recursive = False):
|
|
|
|
|
|
+
|
|
|
|
+def getText(node, recursive=False):
|
|
"""Get all the text associated with this node.
|
|
"""Get all the text associated with this node.
|
|
With recursive == True, all text from child nodes is retrieved."""
|
|
With recursive == True, all text from child nodes is retrieved."""
|
|
L = [u'']
|
|
L = [u'']
|
|
@@ -17,9 +18,10 @@ def getText(node, recursive = False):
|
|
else:
|
|
else:
|
|
if not recursive:
|
|
if not recursive:
|
|
return None
|
|
return None
|
|
- L.append(getText(n) )
|
|
|
|
|
|
+ L.append(getText(n))
|
|
return u''.join(L)
|
|
return u''.join(L)
|
|
|
|
|
|
|
|
+
|
|
def sequence_gen(genlist):
|
|
def sequence_gen(genlist):
|
|
for gen in genlist:
|
|
for gen in genlist:
|
|
for elem in gen:
|
|
for elem in gen:
|
|
@@ -28,12 +30,13 @@ def sequence_gen(genlist):
|
|
|
|
|
|
def parse_for_footnotes(article_or_page_generator):
|
|
def parse_for_footnotes(article_or_page_generator):
|
|
all_content = [
|
|
all_content = [
|
|
- getattr(article_or_page_generator, attr, None) \
|
|
|
|
- for attr in [u'articles',u'drafts',u'pages'] ]
|
|
|
|
- all_content = [ x for x in all_content if x is not None ]
|
|
|
|
|
|
+ getattr(article_or_page_generator, attr, None) \
|
|
|
|
+ for attr in [u'articles', u'drafts', u'pages']]
|
|
|
|
+ all_content = [x for x in all_content if x is not None]
|
|
for article in sequence_gen(all_content):
|
|
for article in sequence_gen(all_content):
|
|
if u"[ref]" in article._content and u"[/ref]" in article._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"))
|
|
parser = html5lib.HTMLParser(tree=html5lib.getTreeBuilder(u"dom"))
|
|
dom = parser.parse(content)
|
|
dom = parser.parse(content)
|
|
endnotes = []
|
|
endnotes = []
|
|
@@ -80,8 +83,9 @@ def parse_for_footnotes(article_or_page_generator):
|
|
e.parentNode.removeChild(e)
|
|
e.parentNode.removeChild(e)
|
|
dom.getElementsByTagName(u"body")[0].appendChild(ol)
|
|
dom.getElementsByTagName(u"body")[0].appendChild(ol)
|
|
s = html5lib.serializer.HTMLSerializer(omit_optional_tags=False, quote_attr_values='legacy')
|
|
s = html5lib.serializer.HTMLSerializer(omit_optional_tags=False, quote_attr_values='legacy')
|
|
- output_generator = s.serialize(html5lib.treewalkers.getTreeWalker(u"dom")(dom.getElementsByTagName(u"body")[0]))
|
|
|
|
- article._content = u"".join(list(output_generator)).replace(
|
|
|
|
|
|
+ output_generator = s.serialize(
|
|
|
|
+ html5lib.treewalkers.getTreeWalker(u"dom")(dom.getElementsByTagName(u"body")[0]))
|
|
|
|
+ article._content = u"".join(list(output_generator)).replace(
|
|
u"<x-simple-footnote>", u"[ref]").replace(u"</x-simple-footnote>", u"[/ref]").replace(
|
|
u"<x-simple-footnote>", u"[ref]").replace(u"</x-simple-footnote>", u"[/ref]").replace(
|
|
u"<body>", u"").replace(u"</body>", u"")
|
|
u"<body>", u"").replace(u"</body>", u"")
|
|
|
|
|