No need for hardcoding line endings for windows. Python handles this by default

This commit is contained in:
Veronica K. B. Olsen
2019-10-26 23:05:12 +02:00
parent f38e770402
commit fde7975a0b
6 changed files with 21 additions and 39 deletions
+2 -6
View File
@@ -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
+11 -11
View File
@@ -34,15 +34,15 @@ class HtmlFile(TextFile):
def _doOpenFile(self, filePath):
try:
self.outFile = open(filePath,mode="w+")
self.outFile.write("<!DOCTYPE html>"+self.endLine)
self.outFile.write("<html>"+self.endLine)
self.outFile.write("<head>"+self.endLine)
self.outFile.write("<style>"+self.endLine)
self.outFile.write(" pre {background-color: #ffff99;}"+self.endLine)
self.outFile.write("</style>"+self.endLine)
self.outFile.write("</head>"+self.endLine)
self.outFile.write("<body>"+self.endLine)
self.outFile = open(filePath,mode="wt+")
self.outFile.write("<!DOCTYPE html>\n")
self.outFile.write("<html>\n")
self.outFile.write("<head>\n")
self.outFile.write("<style>\n")
self.outFile.write(" pre {background-color: #ffff99;}\n")
self.outFile.write("</style>\n")
self.outFile.write("</head>\n")
self.outFile.write("<body>\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("</body>"+self.endLine)
self.outFile.write("</html>"+self.endLine)
self.outFile.write("</body>\n")
self.outFile.write("</html>\n")
self.outFile.close()
return True
+5 -5
View File
@@ -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
+1 -1
View File
@@ -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
+2 -12
View File
@@ -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
-4
View File
@@ -276,10 +276,6 @@ class Tokenizer():
return
def windowsEndings(self):
self.theResult = self.theResult.replace("\n","\r\n")
return
##
# Internal Functions
##