Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 Oct 1, 2018
1 parent c3d57c2 commit afb92f7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions reorder-endnotes
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit afb92f7

Please sign in to comment.