From fde7975a0b7c71396a4d2e603cfcbf6d0692a713 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 26 Oct 2019 23:05:12 +0200 Subject: [PATCH] No need for hardcoding line endings for windows. Python handles this by default --- nw/convert/file/concat.py | 8 ++------ nw/convert/file/html.py | 22 +++++++++++----------- nw/convert/file/latex.py | 10 +++++----- nw/convert/file/markdown.py | 2 +- nw/convert/file/text.py | 14 ++------------ nw/convert/tokenizer.py | 4 ---- 6 files changed, 21 insertions(+), 39 deletions(-) diff --git a/nw/convert/file/concat.py b/nw/convert/file/concat.py index ba51e1d7..cca2769b 100644 --- a/nw/convert/file/concat.py +++ b/nw/convert/file/concat.py @@ -51,13 +51,9 @@ class ConcatFile(TextFile): theResult = self.theConv.theText - if self.winEnding: - self.theConv.windowsEndings() - if theResult is not None and self.outFile is not None: self.outFile.write(theResult.rstrip()) - self.outFile.write(self.endLine) - self.outFile.write(self.endLine) + self.outFile.write("\n\n") return True @@ -67,7 +63,7 @@ class ConcatFile(TextFile): def _doOpenFile(self, filePath): try: - self.outFile = open(filePath,mode="w+") + self.outFile = open(filePath,mode="wt+") except Exception as e: self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR) return False diff --git a/nw/convert/file/html.py b/nw/convert/file/html.py index 72ed1e3f..aa15756e 100644 --- a/nw/convert/file/html.py +++ b/nw/convert/file/html.py @@ -34,15 +34,15 @@ class HtmlFile(TextFile): def _doOpenFile(self, filePath): try: - self.outFile = open(filePath,mode="w+") - self.outFile.write(""+self.endLine) - self.outFile.write(""+self.endLine) - self.outFile.write("
"+self.endLine) - self.outFile.write(""+self.endLine) - self.outFile.write(""+self.endLine) - self.outFile.write(""+self.endLine) + self.outFile = open(filePath,mode="wt+") + self.outFile.write("\n") + self.outFile.write("\n") + self.outFile.write("\n") + self.outFile.write("\n") + self.outFile.write("\n") + self.outFile.write("\n") except Exception as e: self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR) return False @@ -50,8 +50,8 @@ class HtmlFile(TextFile): def _doCloseFile(self): if self.outFile is not None: - self.outFile.write(""+self.endLine) - self.outFile.write(""+self.endLine) + self.outFile.write("\n") + self.outFile.write("\n") self.outFile.close() return True diff --git a/nw/convert/file/latex.py b/nw/convert/file/latex.py index 2fd2536c..10968a97 100644 --- a/nw/convert/file/latex.py +++ b/nw/convert/file/latex.py @@ -35,10 +35,10 @@ class LaTeXFile(TextFile): def _doOpenFile(self, filePath): try: - self.outFile = open(filePath,mode="w+") - self.outFile.write(r"\documentclass[12pt]{report}"+self.endLine) - self.outFile.write(r"\usepackage[utf8]{inputenc}"+self.endLine) - self.outFile.write(r"\begin{document}"+self.endLine) + self.outFile = open(filePath,mode="wt+") + self.outFile.write(r"\documentclass[12pt]{report}\n") + self.outFile.write(r"\usepackage[utf8]{inputenc}\n") + self.outFile.write(r"\begin{document}\n") except Exception as e: self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR) return False @@ -48,7 +48,7 @@ class LaTeXFile(TextFile): def _doCloseFile(self): if self.outFile is not None: - self.outFile.write(r"\end{document}"+self.endLine) + self.outFile.write(r"\end{document}\n") self.outFile.close() return True diff --git a/nw/convert/file/markdown.py b/nw/convert/file/markdown.py index b5d2c32c..ea4bf5c6 100644 --- a/nw/convert/file/markdown.py +++ b/nw/convert/file/markdown.py @@ -34,7 +34,7 @@ class MarkdownFile(TextFile): def _doOpenFile(self, filePath): try: - self.outFile = open(filePath,mode="w+") + self.outFile = open(filePath,mode="wt+") except Exception as e: self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR) return False diff --git a/nw/convert/file/text.py b/nw/convert/file/text.py index 95f8f7b4..e04036c1 100644 --- a/nw/convert/file/text.py +++ b/nw/convert/file/text.py @@ -34,7 +34,6 @@ class TextFile(): self.theText = "" self.expNovel = True self.expNotes = False - self.winEnding = self.mainConf.osWindows self.theConv = ToText(self.theProject, self.theParent) self.makeAlert = self.theParent.makeAlert @@ -43,11 +42,6 @@ class TextFile(): self.setMeta(False) self.setWordWrap(80) - if self.winEnding: - self.endLine = "\r\n" - else: - self.endLine = "\n" - return ## @@ -145,9 +139,6 @@ class TextFile(): self.theConv.doHeaders() self.theConv.doConvert() - if self.winEnding: - self.theConv.windowsEndings() - if self.theConv.theResult is not None and self.outFile is not None: self.outFile.write(self.theConv.theResult) @@ -162,9 +153,8 @@ class TextFile(): that uses a different file format that requires a different approach. """ try: - self.outFile = open(filePath,mode="w+") - self.outFile.write(self.endLine) - self.outFile.write(self.endLine) + self.outFile = open(filePath,mode="wt+") + self.outFile.write("\n\n") except Exception as e: self.makeAlert(["Failed to open file.",str(e)], nwAlert.ERROR) return False diff --git a/nw/convert/tokenizer.py b/nw/convert/tokenizer.py index a59b4f13..78aa5754 100644 --- a/nw/convert/tokenizer.py +++ b/nw/convert/tokenizer.py @@ -276,10 +276,6 @@ class Tokenizer(): return - def windowsEndings(self): - self.theResult = self.theResult.replace("\n","\r\n") - return - ## # Internal Functions ##