就,我读网文习惯自制epub,从 zxcs.me 下载完之前一直手动做正则,今天兴致上来了写了个python小脚本,没做路径输入,每次都要改读取那里(今晚的兴致没支持做完这部分),做完需要微调下metadata,然后就可以愉快扔给 pandoc 了
关联阅读:
import re
old=open(r'pathToNovel.txt',encoding="utf-8")
content=old.read()
old.close()
h1=re.compile(r'\n([第序终][〇零一两二三四五六七八九十百千\d]*?[卷部篇].*|卷[〇零一两二三四五六七八九十百千\d]*?.*)')
h2=re.compile(r'\n([第序终][〇零一二两三四五六七八九十百千\d]*?[章节].*)')
p1=re.compile(' (.+)')
p2=re.compile(r'\n{3,}')
p3=re.compile(r'==========================================================\n更多精校小说尽在知轩藏书下载:http://www.zxcs.me/\n==========================================================')
a=h1.sub(r'\n* \1\n',content)
b=h2.sub(r'\n** \1\n',a)
c=p1.sub(r'\1\n',b)
d=p3.sub('',e)
e=p2.sub(r'\n\n',d)
new=open(r'Novel.org','w',encoding="utf-8")
new.write(e)
new.close()
/* This defines styles and classes used in the book */
body {
text-align: justify;
}
code {
font-family: monospace;
}
h1 {
text-align: center;
font-size: 1.5em;
}
h2 {
text-align: left;
font-size: 1.2em;
}
h3 { text-align: left; }
h4 { text-align: left; }
h5 { text-align: left; }
h6 { text-align: left; }
p {
margin:0em;
/*font-family: ; 标准的正文字体*/
font-size: 14px; /*正文字体大小,默认是16px*/
text-indent: 2em; /*首行缩进2个汉字空间*/
text-align: justify; /*两端对齐*/
text-justify: inter-ideograph; /*用表意文本来排齐内容。*/
}
/* For title, author, and date on the cover page */
h1.title { }
p.author { }
p.date { }
nav#toc ol,
nav#landmarks ol {
padding: 0;
margin-left: 1em;
}
nav#toc ol li,
nav#landmarks ol li { list-style-type: none; margin: 0; padding: 0; }
a.footnote-ref { vertical-align: super; }
em, em em em, em em em em em { font-style: italic;}
em em, em em em em { font-style: normal; }
code{ white-space: pre-wrap; }
span.smallcaps{ font-variant: small-caps; }
span.underline{ text-decoration: underline; }
q { quotes: "“" "”" "‘" "’"; }
div.column{ display: inline-block; vertical-align: top; width: 50%; }
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
@media screen { /* Workaround for iBooks issue; see #6242 */
.sourceCode {
overflow: visible !important;
white-space: pre-wrap !important;
}
}