1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-04-21 05:31:30 +02:00

Added txt related modules

This commit is contained in:
2020-04-19 13:50:42 +02:00
parent 0f628900f3
commit 69d2e536c5
7 changed files with 2311 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL 3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import os
class TxtNewlines(object):
NEWLINE_TYPES = {
'system' : os.linesep,
'unix' : '\n',
'old_mac' : '\r',
'windows' : '\r\n'
}
def __init__(self, newline_type):
self.newline = self.NEWLINE_TYPES.get(newline_type.lower(), os.linesep)
def specified_newlines(newline, text):
# Convert all newlines to \n
text = text.replace('\r\n', '\n')
text = text.replace('\r', '\n')
if newline == '\n':
return text
return text.replace('\n', newline)