mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix bug #3084: text input handle single line paragraphs.
This commit is contained in:
parent
80ad190657
commit
072974bedf
@ -16,6 +16,11 @@ class TXTInput(InputFormatPlugin):
|
|||||||
description = 'Convert TXT files to HTML'
|
description = 'Convert TXT files to HTML'
|
||||||
file_types = set(['txt'])
|
file_types = set(['txt'])
|
||||||
|
|
||||||
|
options = set([
|
||||||
|
OptionRecommendation(name='single_line_paras', recommended_value=False,
|
||||||
|
help=_('Each line is a paragraph.')),
|
||||||
|
])
|
||||||
|
|
||||||
def convert(self, stream, options, file_ext, log,
|
def convert(self, stream, options, file_ext, log,
|
||||||
accelerators):
|
accelerators):
|
||||||
ienc = stream.encoding if stream.encoding else 'utf-8'
|
ienc = stream.encoding if stream.encoding else 'utf-8'
|
||||||
@ -24,6 +29,11 @@ class TXTInput(InputFormatPlugin):
|
|||||||
log.debug('Reading text from file...')
|
log.debug('Reading text from file...')
|
||||||
txt = stream.read().decode(ienc, 'replace')
|
txt = stream.read().decode(ienc, 'replace')
|
||||||
|
|
||||||
|
if options.single_line_paras:
|
||||||
|
txt = txt.replace('\r\n', '\n')
|
||||||
|
txt = txt.replace('\r', '\n')
|
||||||
|
txt = txt.replace('\n', '\n\n')
|
||||||
|
|
||||||
log.debug('Running text though markdown conversion...')
|
log.debug('Running text though markdown conversion...')
|
||||||
try:
|
try:
|
||||||
html = txt_to_markdown(txt)
|
html = txt_to_markdown(txt)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user