From 9908750a0f20df809007927decd6ec0fe30404b6 Mon Sep 17 00:00:00 2001 From: jywhy6 Date: Sun, 3 Jul 2022 22:51:13 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BD=93epub=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=AD=98=E5=9C=A8=E6=97=B6=E5=BF=BD=E7=95=A5=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Program.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Program.cs b/src/Program.cs index c80d61d..74dbe2a 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -14,6 +14,7 @@ class Program static bool append_log = false; static bool overwrite = false; static bool rename_when_exist = false; + static bool ignore_when_exist = false; static bool rename_xhtml_with_id = false; static void Main(string[] args) { @@ -54,6 +55,10 @@ static void Main(string[] args) { rename_when_exist = true; } + if (a.ToLower() == "--ignore-when-exist") + { + ignore_when_exist = true; + } if (a.ToLower() == "--rename-xhtml-with-id") { rename_xhtml_with_id = true; @@ -228,6 +233,11 @@ static void ProcPath(string[] args) } Log.log("[Warn]Save as..."); } + else if (ignore_when_exist) + { + Log.log("[Warn]Output ignored."); + output_path = ""; + } else if (!overwrite) { Console.WriteLine("Output file already exist. N(Abort,Defualt)/y(Overwrite)/r(Rename)?"); @@ -256,7 +266,7 @@ static void ProcPath(string[] args) } else { - Log.log("[Error]Operation aborted. You can use --overwrite or --rename-when-exist to avoid pause."); + Log.log("[Error]Operation aborted. You can use --overwrite or --rename-when-exist or --ignore-when-exist to avoid pause."); output_path = ""; } From ce3abdcc2d6406e81de86a8566c397062c13b0ce Mon Sep 17 00:00:00 2001 From: jywhy6 Date: Sun, 3 Jul 2022 22:58:14 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E4=BD=BF=E7=94=A8Path.Combine=E4=BB=A3?= =?UTF-8?q?=E6=9B=BF=E7=A1=AC=E7=BC=96=E7=A0=81=E7=9A=84=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E4=BB=A3=E7=A0=81=E8=B7=A8=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/EpubBuilder.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/EpubBuilder.cs b/src/EpubBuilder.cs index 035f84b..8cd3c17 100644 --- a/src/EpubBuilder.cs +++ b/src/EpubBuilder.cs @@ -338,7 +338,7 @@ string ProcEmbed(string uri) string name = "embed" + Util.Number(resid) + font_Section.ext; if (font_Section.ext == null) { - Log.log("[Warn] The referred font file is unrecognized: "+name); + Log.log("[Warn] The referred font file is unrecognized: " + name); } link = "../Fonts/" + name; font_Section.comment = name; @@ -451,7 +451,7 @@ void CreateIndexDoc() CreateIndexDoc_Helper(root, temp_epub3, temp_epub2); //Create NAV { - string t = File.ReadAllText("template\\template_nav.txt"); + string t = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "template", "template_nav.txt")); t = t.Replace("{❕toc}", temp_epub3.ToString()); string guide = ""; if (azw3.guide_table != null) @@ -475,7 +475,7 @@ void CreateIndexDoc() nav = t; } { - string t = File.ReadAllText("template\\template_ncx.txt"); + string t = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "template", "template_ncx.txt")); t = t.Replace("{❕navMap}", temp_epub2.ToString()); t = t.Replace("{❕Title}", azw3.title); @@ -501,7 +501,7 @@ void SetCover()//等KindlePosToUri不再使用后 关系到xhtml相关变量 { Log.log("[Info]Adding a cover document."); - string t = File.ReadAllText("template\\template_cover.txt"); + string t = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "template", "template_cover.txt")); var (w, h) = Util.GetImageSize(imgs[img_names.IndexOf(cover_name)]); cover = t.Replace("{❕image}", cover_name).Replace("{❕w}", w.ToString()).Replace("{❕h}", h.ToString()); @@ -535,7 +535,7 @@ void CreateOPF() { if (azw3.resc != null) { - string t = File.ReadAllText("template\\template_opf.txt"); + string t = File.ReadAllText(Path.Combine(Environment.CurrentDirectory, "template", "template_opf.txt")); XmlDocument manifest = new XmlDocument(); XmlElement mani_root = manifest.CreateElement("manifest"); manifest.AppendChild(mani_root); From b07f72367839a556183a4fbc47d48ee66b1c7133 Mon Sep 17 00:00:00 2001 From: jywhy6 Date: Sun, 3 Jul 2022 23:09:05 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BD=BF=E7=94=A8Path.Combine=E4=BB=A3?= =?UTF-8?q?=E6=9B=BF=E7=A1=AC=E7=BC=96=E7=A0=81=E7=9A=84=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=EF=BC=8C=E4=BD=BF=E4=BB=A3=E7=A0=81=E8=B7=A8=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 74dbe2a..d83858e 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -75,10 +75,10 @@ static void Main(string[] args) if (!end_of_proc) ProcPath(args); if (append_log) { - Log.Append("..\\lastrun.log"); + Log.Append(Path.Combine(Environment.CurrentDirectory, "..", "lastrun.log")); } else - Log.Save("..\\lastrun.log"); + Log.Save(Path.Combine(Environment.CurrentDirectory, "..", "lastrun.log")); Environment.CurrentDirectory = temp_environment_dir; } From b76fe72f571b436f7e9cf947bd3479b3c4e19fb8 Mon Sep 17 00:00:00 2001 From: jywhy6 Date: Mon, 4 Jul 2022 22:34:26 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=BD=AC=E4=B9=89xhtml?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=97=A0=E6=95=88=E5=AD=97=E7=AC=A6=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8Depub=E8=BD=AC=E6=8D=A2=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/EpubBuilder.cs | 6 ++++-- src/utils.cs | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/EpubBuilder.cs b/src/EpubBuilder.cs index 8cd3c17..073ee06 100644 --- a/src/EpubBuilder.cs +++ b/src/EpubBuilder.cs @@ -116,7 +116,7 @@ public void Save(string path) { string p = "OEBPS/Text/" + xhtml_names[i]; string ss; - var xmlSettings = new XmlWriterSettings { Indent = true, NewLineChars = "\n" }; + var xmlSettings = new XmlWriterSettings { Indent = true, NewLineChars = "\n", CheckCharacters = false }; using (var stringWriter = new StringWriter()) using (var xmlTextWriter = XmlWriter.Create(stringWriter, xmlSettings)) { @@ -854,8 +854,10 @@ XmlDocument LoadXhtml(string xhtml) { int htmlstart = xhtml.IndexOf("= 0x0020 && ch <= 0xD7FF) || + (ch >= 0xE000 && ch <= 0xFFFD) || + ch == 0x0009 || + ch == 0x000A || + ch == 0x000D) + { + str_buf.Append(ch); + } + else + { + byte[] bytes = Encoding.UTF8.GetBytes(Char.ToString(ch)); + + str_buf.Append("&#x" + Convert.ToHexString(bytes) + ";"); + } + } + return str_buf.ToString(); + } + public static (int, int) GetImageSize(byte[] data) { using (var img = Image.FromStream(new MemoryStream(data)))