Skip to content

Commit afb92f7

Browse files
robinwhittletonacabal
authored andcommitted
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.
1 parent c3d57c2 commit afb92f7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

reorder-endnotes

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def main():
5454
note_range = range(target_endnote_number, endnote_count + 1, 1)
5555

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

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

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

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

0 commit comments

Comments
 (0)