首页 > 解决方案 > 如何在 EPUB 文件中的每个句子或文本行的末尾插入特定的 HTML 标记?

问题描述

我想在EPUB的源代码中插入这个HTML分页符:在标签<span style="page-break-after: always" />中包含的每一行代码,<pre>标签中的标题<h>或标签中的句子之后<p>,以便在阅读时显示每一句或每一行代码一次在屏幕上显示一个,如下所示:

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)

我相信我必须解压缩 .epub 文件并遍历解压缩目录中的所有文件。我必须导航到任何标签<h><pre>并且<p>。我可以在换行符和句子上的这些标签之间拆分文本,并NLTK.sent_tokenize在每个拆分之间插入上面的分页符标签,像这样吗?

这样:

<p>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.<a data-type="indexterm" data-primary="Objective-C" data-seealso="bridged types" id="idxobjectivecappendix"/></p>

变成这样:

<p>The APIs for Cocoa and its associated frameworks are written in Objective-C or its underlying base language, C. <span style="page-break-after: always" /> Messages that you send to Cocoa using Swift are being translated for you into Objective-C. <span style="page-break-after: always" /> Objects that you send and receive back and forth across the Swift/Objective-C bridge are Objective-C objects. <span style="page-break-after: always" /> Some objects that you send from Swift to Objective-C are even being translated for you into other object types, or into nonobject types. <span style="page-break-after: always" /> <a data-type="indexterm" data-primary="Objective-C" data-seealso="bridged types" id="idxobjectivecappendix"/></p>

或者是否有必要这样做:

<p>The APIs for Cocoa and its associated frameworks are written in Objective-C or its underlying base language, C. </p> <span style="page-break-after: always" /> <p> Messages that you send to Cocoa using Swift are being translated for you into Objective-C. </p> <span style="page-break-after: always" /> <p> Objects that you send and receive back and forth across the Swift/Objective-C bridge are Objective-C objects. </p> <span style="page-break-after: always" />

(ETC。)

谁能提供一个达到预期效果的脚本?非常感谢。

标签: htmlepub

解决方案


推荐阅读