Make UI data re-useable for I/O plugins

This commit is contained in:
Kovid Goyal 2018-07-04 12:07:48 +05:30
parent 970b485ba6
commit f198117f08
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 43 additions and 22 deletions

View File

@ -137,6 +137,7 @@ class InputFormatPlugin(Plugin):
can_be_disabled = False can_be_disabled = False
supported_platforms = ['windows', 'osx', 'linux'] supported_platforms = ['windows', 'osx', 'linux']
commit_name = None # unique name under which options for this plugin are saved commit_name = None # unique name under which options for this plugin are saved
ui_data = None
#: Set of file types for which this plugin should be run #: Set of file types for which this plugin should be run
#: For example: ``set(['azw', 'mobi', 'prc'])`` #: For example: ``set(['azw', 'mobi', 'prc'])``
@ -287,6 +288,7 @@ class OutputFormatPlugin(Plugin):
can_be_disabled = False can_be_disabled = False
supported_platforms = ['windows', 'osx', 'linux'] supported_platforms = ['windows', 'osx', 'linux']
commit_name = None # unique name under which options for this plugin are saved commit_name = None # unique name under which options for this plugin are saved
ui_data = None
#: The file type (extension without leading period) that this #: The file type (extension without leading period) that this
#: plugin outputs #: plugin outputs

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import print_function
__license__ = 'GPL 3' __license__ = 'GPL 3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>' __copyright__ = '2009, John Schember <john@nachtimwald.com>'
@ -32,32 +33,48 @@ class TXTInput(InputFormatPlugin):
description = 'Convert TXT files to HTML' description = 'Convert TXT files to HTML'
file_types = {'txt', 'txtz', 'text', 'md', 'textile', 'markdown'} file_types = {'txt', 'txtz', 'text', 'md', 'textile', 'markdown'}
commit_name = 'txt_input' commit_name = 'txt_input'
ui_data = {
'md_extensions': MD_EXTENSIONS,
'paragraph_types': {
'auto': _('Try to auto detect paragraph type'),
'block': _('Treat a blank line as a paragraph break'),
'single': _('Assume every line is a paragraph'),
'print': _('Assume every line starting with 2+ spaces or a tab starts a paragraph'),
'unformatted': _('Most lines have hard line breaks, few/no blank lines or indents'),
'off': _('Don\'t modify the paragraph structure'),
},
'formatting_types': {
'auto': _('Automatically decide which formatting processor to use'),
'plain': _('No formatting'),
'heuristic': _('Use heuristics to determine chapter headings, italics, etc.'),
'textile': _('Use the TexTile markup language'),
'markdown': _('Use the Markdown markup language')
},
}
options = set([ options = set([
OptionRecommendation(name='paragraph_type', recommended_value='auto',
choices=['auto', 'block', 'single', 'print', 'unformatted', 'off'],
help=_('Paragraph structure.\n'
'choices are [\'auto\', \'block\', \'single\', \'print\', \'unformatted\', \'off\']\n'
'* auto: Try to auto detect paragraph type.\n'
'* block: Treat a blank line as a paragraph break.\n'
'* single: Assume every line is a paragraph.\n'
'* print: Assume every line starting with 2+ spaces or a tab '
'starts a paragraph.\n'
'* unformatted: Most lines have hard line breaks, few/no blank lines or indents. '
'Tries to determine structure and reformat the differentiate elements.\n'
'* off: Don\'t modify the paragraph structure. This is useful when combined with '
'Markdown or Textile formatting to ensure no formatting is lost.')),
OptionRecommendation(name='formatting_type', recommended_value='auto', OptionRecommendation(name='formatting_type', recommended_value='auto',
choices=['auto', 'plain', 'heuristic', 'textile', 'markdown'], choices=list(ui_data['formatting_types']),
help=_('Formatting used within the document.\n' help=_('Formatting used within the document.\n'
'* auto: Automatically decide which formatting processor to use.\n' '* auto: {auto}\n'
'* plain: Do not process the document formatting. Everything is a ' '* plain: {plain}\n'
'paragraph and no styling is applied.\n' '* heuristic: {heuristic}\n'
'* heuristic: Process using heuristics to determine formatting such ' '* textile: {textile}\n'
'as chapter headings and italic text.\n' '* markdown: {markdown}\n'
'* textile: Processing using textile formatting.\n' 'To learn more about markdown see {url}').format(
'* markdown: Processing using markdown formatting. ' url='https://daringfireball.net/projects/markdown/', **ui_data['formatting_types'])
'To learn more about markdown see')+' https://daringfireball.net/projects/markdown/'), ),
OptionRecommendation(name='paragraph_type', recommended_value='auto',
choices=list(ui_data['paragraph_types']),
help=_('Paragraph structure to assume. The value of "off" is useful for formatted documents such as Markdown or Textile. '
'Choices are:\n'
'* auto: {auto}\n'
'* block: {block}\n'
'* single: {single}\n'
'* print: {print}\n'
'* unformatted: {unformatted}\n'
'* off: {off}').format(**ui_data['paragraph_types'])
),
OptionRecommendation(name='preserve_spaces', recommended_value=False, OptionRecommendation(name='preserve_spaces', recommended_value=False,
help=_('Normally extra spaces are condensed into a single space. ' help=_('Normally extra spaces are condensed into a single space. '
'With this option all spaces will be displayed.')), 'With this option all spaces will be displayed.')),

View File

@ -213,6 +213,8 @@ def get_conversion_options(input_fmt, output_fmt, book_id, db):
ans = {'options': {}, 'disabled': set(), 'defaults': {}, 'help': {}} ans = {'options': {}, 'disabled': set(), 'defaults': {}, 'help': {}}
ans['input_plugin_name'] = plumber.input_plugin.commit_name ans['input_plugin_name'] = plumber.input_plugin.commit_name
ans['output_plugin_name'] = plumber.output_plugin.commit_name ans['output_plugin_name'] = plumber.output_plugin.commit_name
ans['input_ui_data'] = plumber.input_plugin.ui_data
ans['output_ui_data'] = plumber.output_plugin.ui_data
def merge_group(group_name, option_names): def merge_group(group_name, option_names):
if not group_name or group_name in ('debug', 'metadata'): if not group_name or group_name in ('debug', 'metadata'):