mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove TXT specific options for indent and flush paragraphs, use the look and feel remove paragraph spacing option instead.
This commit is contained in:
commit
0ac629a5cc
@ -801,33 +801,29 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
fname = sanitize(fname)
|
fname = sanitize(fname)
|
||||||
ext = os.path.splitext(fname)[1]
|
ext = os.path.splitext(fname)[1]
|
||||||
|
|
||||||
if special_tag is None:
|
from calibre.library.save_to_disk import get_components
|
||||||
from calibre.library.save_to_disk import get_components
|
extra_components = get_components(template, mdata, fname)
|
||||||
extra_components = get_components(template, mdata, fname)
|
if not extra_components:
|
||||||
|
extra_components.append(sanitize(self.filename_callback(fname,
|
||||||
|
mdata)))
|
||||||
else:
|
else:
|
||||||
|
extra_components[-1] = sanitize(self.filename_callback(extra_components[-1]+ext, mdata))
|
||||||
|
|
||||||
|
if special_tag is not None:
|
||||||
|
name = extra_components[-1]
|
||||||
|
extra_components = []
|
||||||
tag = special_tag
|
tag = special_tag
|
||||||
if tag.startswith(_('News')):
|
if tag.startswith(_('News')):
|
||||||
extra_components.append('News')
|
extra_components.append('News')
|
||||||
c = sanitize(mdata.title if mdata.title else '')
|
|
||||||
#c = c.split('[')[0].strip()
|
|
||||||
if c:
|
|
||||||
extra_components.append(c)
|
|
||||||
else:
|
else:
|
||||||
for c in tag.split('/'):
|
for c in tag.split('/'):
|
||||||
c = sanitize(c)
|
c = sanitize(c)
|
||||||
if not c: continue
|
if not c: continue
|
||||||
extra_components.append(c)
|
extra_components.append(c)
|
||||||
|
extra_components.append(name)
|
||||||
|
|
||||||
if not use_subdirs:
|
if not use_subdirs:
|
||||||
extra_components = extra_components[:1]
|
extra_components = extra_components[-1:]
|
||||||
|
|
||||||
if not extra_components:
|
|
||||||
fname = sanitize(self.filename_callback(fname, mdata))
|
|
||||||
extra_components.append(fname)
|
|
||||||
extra_components = [str(x) for x in extra_components]
|
|
||||||
else:
|
|
||||||
extra_components[-1] += ext
|
|
||||||
|
|
||||||
def remove_trailing_periods(x):
|
def remove_trailing_periods(x):
|
||||||
ans = x
|
ans = x
|
||||||
|
@ -47,10 +47,8 @@ class PDBOutput(OutputFormatPlugin):
|
|||||||
if Writer is None:
|
if Writer is None:
|
||||||
raise PDBError('No writer available for format %s.' % format)
|
raise PDBError('No writer available for format %s.' % format)
|
||||||
|
|
||||||
setattr(opts, 'flush_paras', False)
|
|
||||||
setattr(opts, 'max_line_length', 0)
|
setattr(opts, 'max_line_length', 0)
|
||||||
setattr(opts, 'force_max_line_length', False)
|
setattr(opts, 'force_max_line_length', False)
|
||||||
setattr(opts, 'indent_paras', False)
|
|
||||||
|
|
||||||
writer = Writer(opts, log)
|
writer = Writer(opts, log)
|
||||||
|
|
||||||
|
@ -71,8 +71,8 @@ class PML_HTMLizer(object):
|
|||||||
'ra': ('<span id="r%s"></span><a href="#%s">', '</a>'),
|
'ra': ('<span id="r%s"></span><a href="#%s">', '</a>'),
|
||||||
'c': ('<div style="text-align: center; margin: auto;">', '</div>'),
|
'c': ('<div style="text-align: center; margin: auto;">', '</div>'),
|
||||||
'r': ('<div style="text-align: right;">', '</div>'),
|
'r': ('<div style="text-align: right;">', '</div>'),
|
||||||
't': ('<div style="text-indent: 1.5em;">', '</div>'),
|
't': ('<div style="margin-left: 5%;">', '</div>'),
|
||||||
'T': ('<div style="text-indent: %s;">', '</div>'),
|
'T': ('<div style="margin-left: %s;">', '</div>'),
|
||||||
'i': ('<span style="font-style: italic;">', '</span>'),
|
'i': ('<span style="font-style: italic;">', '</span>'),
|
||||||
'u': ('<span style="text-decoration: underline;">', '</span>'),
|
'u': ('<span style="text-decoration: underline;">', '</span>'),
|
||||||
'd': ('<span style="text-decoration: line-through;">', '</span>'),
|
'd': ('<span style="text-decoration: line-through;">', '</span>'),
|
||||||
|
@ -182,9 +182,14 @@ class PMLMLizer(object):
|
|||||||
# Remove excessive spaces
|
# Remove excessive spaces
|
||||||
text = re.sub('[ ]{2,}', ' ', text)
|
text = re.sub('[ ]{2,}', ' ', text)
|
||||||
|
|
||||||
# Remove excessive newlines
|
# Remove excessive newlines.
|
||||||
text = re.sub('\n[ ]+\n', '\n\n', text)
|
text = re.sub('\n[ ]+\n', '\n\n', text)
|
||||||
text = re.sub('\n\n\n+', '\n\n', text)
|
if self.opts.remove_paragraph_spacing:
|
||||||
|
text = re.sub('\n{2,}', '\n', text)
|
||||||
|
text = re.sub('(?imu)^(?P<text>.+)$', lambda mo: mo.group('text') if re.search(r'\\[XxCm]', mo.group('text')) else ' %s' % mo.group('text'), text)
|
||||||
|
else:
|
||||||
|
text = re.sub('\n{4,}', '\n\n\n', text)
|
||||||
|
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@ -204,12 +209,10 @@ class PMLMLizer(object):
|
|||||||
tag_count = 0
|
tag_count = 0
|
||||||
|
|
||||||
# Are we in a paragraph block?
|
# Are we in a paragraph block?
|
||||||
if tag in BLOCK_TAGS:# or style['display'] in BLOCK_STYLES:
|
if tag in BLOCK_TAGS: # or style['display'] in BLOCK_STYLES:
|
||||||
if 'block' not in tag_stack:
|
if 'block' not in tag_stack:
|
||||||
tag_count += 1
|
tag_count += 1
|
||||||
tag_stack.append('block')
|
tag_stack.append('block')
|
||||||
if self.opts.remove_paragraph_spacing:
|
|
||||||
text.append('\\t')
|
|
||||||
|
|
||||||
# Process tags that need special processing and that do not have inner
|
# Process tags that need special processing and that do not have inner
|
||||||
# text. Usually these require an argument
|
# text. Usually these require an argument
|
||||||
@ -289,14 +292,10 @@ class PMLMLizer(object):
|
|||||||
close_tag_list.insert(0, tag_stack.pop())
|
close_tag_list.insert(0, tag_stack.pop())
|
||||||
text += self.close_tags(close_tag_list)
|
text += self.close_tags(close_tag_list)
|
||||||
if tag in SEPARATE_TAGS:
|
if tag in SEPARATE_TAGS:
|
||||||
text.append('\n')
|
text.append('\n\n')
|
||||||
if not self.opts.remove_paragraph_spacing:
|
|
||||||
text.append('\n')
|
|
||||||
|
|
||||||
if 'block' not in tag_stack and text and text[-1] != '\n':
|
if 'block' not in tag_stack:
|
||||||
text.append('\n')
|
text.append('\n\n')
|
||||||
if not self.opts.remove_paragraph_spacing:
|
|
||||||
text.append('\n')
|
|
||||||
|
|
||||||
#if style['page-break-after'] == 'always':
|
#if style['page-break-after'] == 'always':
|
||||||
# text.append('\\p')
|
# text.append('\\p')
|
||||||
|
@ -33,9 +33,6 @@ class TXTOutput(OutputFormatPlugin):
|
|||||||
OptionRecommendation(name='inline_toc',
|
OptionRecommendation(name='inline_toc',
|
||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
help=_('Add Table of Contents to beginning of the book.')),
|
help=_('Add Table of Contents to beginning of the book.')),
|
||||||
OptionRecommendation(name='flush_paras',
|
|
||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
|
||||||
help=_('Do not add a blank line between paragraphs.')),
|
|
||||||
OptionRecommendation(name='max_line_length',
|
OptionRecommendation(name='max_line_length',
|
||||||
recommended_value=0, level=OptionRecommendation.LOW,
|
recommended_value=0, level=OptionRecommendation.LOW,
|
||||||
help=_('The maximum number of characters per line. This splits on '
|
help=_('The maximum number of characters per line. This splits on '
|
||||||
@ -47,9 +44,6 @@ class TXTOutput(OutputFormatPlugin):
|
|||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
help=_('Force splitting on the max-line-length value when no space '
|
help=_('Force splitting on the max-line-length value when no space '
|
||||||
'is present. Also allows max-line-length to be below the minimum')),
|
'is present. Also allows max-line-length to be below the minimum')),
|
||||||
OptionRecommendation(name='indent_paras',
|
|
||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
|
||||||
help=_('Add a tab at the beginning of each paragraph.')),
|
|
||||||
])
|
])
|
||||||
|
|
||||||
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
||||||
|
@ -98,18 +98,16 @@ class TXTMLizer(object):
|
|||||||
|
|
||||||
# Remove excessive newlines.
|
# Remove excessive newlines.
|
||||||
text = re.sub('\n[ ]+\n', '\n\n', text)
|
text = re.sub('\n[ ]+\n', '\n\n', text)
|
||||||
if self.opts.flush_paras:
|
if self.opts.remove_paragraph_spacing:
|
||||||
text = re.sub('\n{2,}', '\n', text)
|
text = re.sub('\n{2,}', '\n', text)
|
||||||
|
text = re.sub('(?imu)^(?=.)', '\t', text)
|
||||||
else:
|
else:
|
||||||
text = re.sub('\n{3,}', '\n\n', text)
|
text = re.sub('\n{4,}', '\n\n\n', text)
|
||||||
|
|
||||||
# Replace spaces at the beginning and end of lines
|
# Replace spaces at the beginning and end of lines
|
||||||
text = re.sub('(?imu)^[ ]+', '', text)
|
text = re.sub('(?imu)^[ ]+', '', text)
|
||||||
text = re.sub('(?imu)[ ]+$', '', text)
|
text = re.sub('(?imu)[ ]+$', '', text)
|
||||||
|
|
||||||
if self.opts.indent_paras:
|
|
||||||
text = re.sub('(?imu)^(?=.)', '\t', text)
|
|
||||||
|
|
||||||
if self.opts.max_line_length:
|
if self.opts.max_line_length:
|
||||||
max_length = self.opts.max_line_length
|
max_length = self.opts.max_line_length
|
||||||
if self.opts.max_line_length < 25 and not self.opts.force_max_line_length:
|
if self.opts.max_line_length < 25 and not self.opts.force_max_line_length:
|
||||||
|
@ -19,7 +19,7 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||||
Widget.__init__(self, parent, 'txt_output',
|
Widget.__init__(self, parent, 'txt_output',
|
||||||
['newline', 'max_line_length', 'force_max_line_length',
|
['newline', 'max_line_length', 'force_max_line_length',
|
||||||
'inline_toc', 'flush_paras', 'indent_paras'])
|
'inline_toc'])
|
||||||
self.db, self.book_id = db, book_id
|
self.db, self.book_id = db, book_id
|
||||||
self.initialize_options(get_option, get_help, db, book_id)
|
self.initialize_options(get_option, get_help, db, book_id)
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QComboBox" name="opt_newline"/>
|
<widget class="QComboBox" name="opt_newline"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="6" column="0">
|
<item row="4" column="0">
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
@ -47,20 +47,6 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="opt_flush_paras">
|
|
||||||
<property name="text">
|
|
||||||
<string>Do not add a blank line between paragraphs.</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0" colspan="2">
|
|
||||||
<widget class="QCheckBox" name="opt_indent_paras">
|
|
||||||
<property name="text">
|
|
||||||
<string>Add a tab at the beginning of each paragraph</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QSpinBox" name="opt_max_line_length"/>
|
<widget class="QSpinBox" name="opt_max_line_length"/>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user