epub模板增加ori_title

title: 标题有空格会自动分割,如:"第一章 楔子"会变成"<span class="chapter-sequence-number">第一章</span><br />楔子"
ori_title: 原始标题
pull/2309/head
celetor 2 years ago committed by GitHub
parent b22e1ffb34
commit da9fe5d8cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      epublib/src/main/java/me/ag2s/epublib/util/ResourceUtil.java

@ -36,14 +36,21 @@ public class ResourceUtil {
* @return 返回Resource
*/
public static Resource createChapterResource(String title, String txt, String model, String href) {
if (title.contains("\n")) {
title = "<span class=\"chapter-sequence-number\">" + title.replaceFirst("\\s*\\n\\s*", "</span><br />");
} else {
title = title.replaceFirst("\\s+", "</span><br />");
if (title.contains("</span>"))
title = "<span class=\"chapter-sequence-number\">" + title;
//String[] title_list = title.split("\\s+", 2);
//String title_part1 = title_list[0];
//String title_part2 = "";
//if (title_list.length == 2) {
// title_part2 = title_list[1];
//}
String ori_title = title;
title = title.replaceFirst("\\s+", "</span><br />");
if (title.contains("</span>")) {
title = "<span class=\"chapter-sequence-number\">" + title;
}
String html = model.replace("{title}", title)
.replace("{ori_title}", ori_title)
//.replace("{title_part1}", title_part1)
//.replace("{title_part2}", title_part2)
.replace("{content}", StringUtil.formatHtml(txt));
return new Resource(html.getBytes(), href);
}

Loading…
Cancel
Save