Permalink
Browse files

After replacing endnote move immediately to the next

We know there’s only one endnote we care about, so we can move directly to the next after amending, rather than keeping on scanning the file.

On Pepys endnotes on my machine this shaves a second off the overall time.
  • Loading branch information...
robinwhittleton authored and acabal committed Sep 28, 2018
1 parent c3d57c2 commit afb92f74933c2c67effae0b0c986d7fe263a3c30
Showing with 4 additions and 4 deletions.
  1. +4 −4 reorder-endnotes
@@ -54,8 +54,8 @@ def main():
note_range = range(target_endnote_number, endnote_count + 1, 1)

for endnote_number in note_range:
xhtml = xhtml.replace("id=\"note-{}\"".format(endnote_number), "id=\"note-{}\"".format(endnote_number + step))
xhtml = xhtml.replace("#noteref-{}\"".format(endnote_number), "#noteref-{}\"".format(endnote_number + step))
xhtml = xhtml.replace("id=\"note-{}\"".format(endnote_number), "id=\"note-{}\"".format(endnote_number + step), 1)
xhtml = xhtml.replace("#noteref-{}\"".format(endnote_number), "#noteref-{}\"".format(endnote_number + step), 1)

file.seek(0)
file.write(xhtml)
@@ -77,8 +77,8 @@ def main():

for endnote_number in note_range:
processed_xhtml = regex.sub(r"(<a[^>]*?>){}</a>".format(endnote_number), r"\g<1>{}</a>".format(endnote_number + step), processed_xhtml, flags=regex.DOTALL)
processed_xhtml = processed_xhtml.replace("id=\"noteref-{}\"".format(endnote_number), "id=\"noteref-{}\"".format(endnote_number + step))
processed_xhtml = processed_xhtml.replace("#note-{}\"".format(endnote_number), "#note-{}\"".format(endnote_number + step))
processed_xhtml = processed_xhtml.replace("id=\"noteref-{}\"".format(endnote_number), "id=\"noteref-{}\"".format(endnote_number + step), 1)
processed_xhtml = processed_xhtml.replace("#note-{}\"".format(endnote_number), "#note-{}\"".format(endnote_number + step), 1)

if processed_xhtml != xhtml:
file.seek(0)

0 comments on commit afb92f7

Please sign in to comment.