title: How can I insert a specific HTML tag at the end of every sentence or line of text in an EPUB file?
body: <p>I would like to insert this HTML page break tag: <code>&lt;span style=&quot;page-break-after: always&quot; /&gt;</code> after every line of code enclosed in <code>&lt;pre&gt;</code> tags, header in <code>&lt;h&gt;</code> tags, or sentence in <code>&lt;p&gt;</code> tags, in an EPUB's source code, so that when it is read, every sentence or line of code is displayed on-screen one at a time, like this:</p>
  <pre><code>Chapter 1 (user navigates to next page)
  This is a story about something. (user navigates to next page)
  And it involves computer programs: (user navigates to next page)
  let x = y + 3 (user navigates to next page)
  </code></pre>
  <p>I believe I have to unzip the .epub file and iterate over all the files in the unzipped directory. I have to navigate to any tag <code>&lt;h&gt;</code>, <code>&lt;pre&gt;</code> and <code>&lt;p&gt;</code>. Can I split the text between those tags on newlines, and on sentences with <code>NLTK.sent_tokenize</code>, and insert the above page break tag between each split, like this?</p>
  <p>So that this:</p>
  <p><code>&lt;p&gt;The APIs for Cocoa and its associated frameworks are written in Objective-C or its underlying base language, C. Messages that you send to Cocoa using Swift are being translated for you into Objective-C. Objects that you send and receive back and forth across the Swift/Objective-C bridge are Objective-C objects. Some objects that you send from Swift to Objective-C are even being translated for you into other object types, or into nonobject types.&lt;a data-type=&quot;indexterm&quot; data-primary=&quot;Objective-C&quot; data-seealso=&quot;bridged types&quot; id=&quot;idxobjectivecappendix&quot;/&gt;&lt;/p&gt;</code></p>
  <p>Becomes this:</p>
  <p><code>&lt;p&gt;The APIs for Cocoa and its associated frameworks are written in Objective-C or its underlying base language, C. &lt;span style=&quot;page-break-after: always&quot; /&gt; Messages that you send to Cocoa using Swift are being translated for you into Objective-C. &lt;span style=&quot;page-break-after: always&quot; /&gt; Objects that you send and receive back and forth across the Swift/Objective-C bridge are Objective-C objects. &lt;span style=&quot;page-break-after: always&quot; /&gt; Some objects that you send from Swift to Objective-C are even being translated for you into other object types, or into nonobject types. &lt;span style=&quot;page-break-after: always&quot; /&gt; &lt;a data-type=&quot;indexterm&quot; data-primary=&quot;Objective-C&quot; data-seealso=&quot;bridged types&quot; id=&quot;idxobjectivecappendix&quot;/&gt;&lt;/p&gt;</code></p>
  <p>Or will it be necessary to do this:</p>
  <p><code>&lt;p&gt;The APIs for Cocoa and its associated frameworks are written in Objective-C or its underlying base language, C. &lt;/p&gt; &lt;span style=&quot;page-break-after: always&quot; /&gt; &lt;p&gt; Messages that you send to Cocoa using Swift are being translated for you into Objective-C. &lt;/p&gt; &lt;span style=&quot;page-break-after: always&quot; /&gt; &lt;p&gt; Objects that you send and receive back and forth across the Swift/Objective-C bridge are Objective-C objects. &lt;/p&gt; &lt;span style=&quot;page-break-after: always&quot; /&gt;</code></p>
  <p>(etc.)</p>
  <p>Could anyone please provide a script that achieves the intended effect? Thanks very much.</p>