TXT Output: change remove links to keep links and remove links by default with Markdown format output. TXT Output: Add keep image references option and remove images by default with Markdown format output.

This commit is contained in:
John Schember 2010-12-02 06:54:36 -05:00
parent f078aceb6c
commit d744fb698b
4 changed files with 25 additions and 10 deletions

View File

@ -31,9 +31,12 @@ class MarkdownMLizer(object):
for item in self.oeb_book.spine: for item in self.oeb_book.spine:
self.log.debug('Converting %s to Markdown formatted TXT...' % item.href) self.log.debug('Converting %s to Markdown formatted TXT...' % item.href)
html = unicode(etree.tostring(item.data, encoding=unicode)) html = unicode(etree.tostring(item.data, encoding=unicode))
if self.opts.remove_links: if not self.opts.keep_links:
html = re.sub(r'<\s*a[^>]*>', '', html) html = re.sub(r'<\s*a[^>]*>', '', html)
html = re.sub(r'<\s*/\s*a\s*>', '', html) html = re.sub(r'<\s*/\s*a\s*>', '', html)
if not self.opts.keep_image_references:
html = re.sub(r'<\s*img[^>]*>', '', html)
html = re.sub(r'<\s*img\s*>', '', html)
output += html2text(html) output += html2text(html)
output = u''.join(output) output = u''.join(output)

View File

@ -48,11 +48,16 @@ class TXTOutput(OutputFormatPlugin):
OptionRecommendation(name='markdown_format', OptionRecommendation(name='markdown_format',
recommended_value=False, level=OptionRecommendation.LOW, recommended_value=False, level=OptionRecommendation.LOW,
help=_('Produce Markdown formatted text.')), help=_('Produce Markdown formatted text.')),
OptionRecommendation(name='remove_links', OptionRecommendation(name='keep_links',
recommended_value=False, level=OptionRecommendation.LOW, recommended_value=False, level=OptionRecommendation.LOW,
help=_('Remove links within the document. This is only ' \ help=_('Do not remove links within the document. This is only ' \
'useful when paried with the markdown-format option because' \ 'useful when paired with the markdown-format option because' \
'links are removed with plain text output.')), 'links are always removed with plain text output.')),
OptionRecommendation(name='keep_image_references',
recommended_value=False, level=OptionRecommendation.LOW,
help=_('Do not remove image references within the document. This is only ' \
'useful when paired with the markdown-format option because' \
'image references are always removed with plain text output.')),
]) ])
def convert(self, oeb_book, output_path, input_plugin, opts, log): def convert(self, oeb_book, output_path, input_plugin, opts, log):

View File

@ -21,7 +21,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, Widget.__init__(self, parent,
['newline', 'max_line_length', 'force_max_line_length', ['newline', 'max_line_length', 'force_max_line_length',
'inline_toc', 'markdown_format', 'remove_links']) 'inline_toc', 'markdown_format', 'keep_links', 'keep_image_references'])
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)

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>470</width> <width>477</width>
<height>300</height> <height>300</height>
</rect> </rect>
</property> </property>
@ -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="7" column="0">
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -75,9 +75,16 @@
</widget> </widget>
</item> </item>
<item row="5" column="0"> <item row="5" column="0">
<widget class="QCheckBox" name="opt_remove_links"> <widget class="QCheckBox" name="opt_keep_links">
<property name="text"> <property name="text">
<string>Remove links (&lt;a&gt; tags) before processing</string> <string>Do not remove links (&lt;a&gt; tags) before processing</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="opt_keep_image_references">
<property name="text">
<string>Do not remove image references before processing</string>
</property> </property>
</widget> </widget>
</item> </item>