Markdown Output: Don't escape special characters in code blocks.

This commit is contained in:
John Schember 2011-09-04 13:03:52 -04:00
parent adcf2a0cb6
commit 8a689cf3b6

View File

@ -22,6 +22,7 @@ class MarkdownMLizer(OEB2HTML):
def extract_content(self, oeb_book, opts): def extract_content(self, oeb_book, opts):
self.log.info('Converting XHTML to Markdown formatted TXT...') self.log.info('Converting XHTML to Markdown formatted TXT...')
self.opts = opts self.opts = opts
self.in_code = False
self.in_pre = False self.in_pre = False
self.list = [] self.list = []
self.blockquotes = 0 self.blockquotes = 0
@ -158,6 +159,7 @@ class MarkdownMLizer(OEB2HTML):
if not self.in_pre: if not self.in_pre:
text.append('`') text.append('`')
tags.append('`') tags.append('`')
self.in_code = True
elif tag == 'pre': elif tag == 'pre':
if not self.in_pre: if not self.in_pre:
text.append('\n') text.append('\n')
@ -207,6 +209,8 @@ class MarkdownMLizer(OEB2HTML):
txt = elem.text txt = elem.text
if self.in_pre: if self.in_pre:
txt = self.prepare_string_for_pre(txt) txt = self.prepare_string_for_pre(txt)
elif self.in_code:
txt = self.remove_newlines(txt)
else: else:
txt = self.prepare_string_for_markdown(self.remove_newlines(txt)) txt = self.prepare_string_for_markdown(self.remove_newlines(txt))
text.append(txt) text.append(txt)
@ -234,6 +238,8 @@ class MarkdownMLizer(OEB2HTML):
self.style_bold = False self.style_bold = False
elif t == '*': elif t == '*':
self.style_italic = False self.style_italic = False
elif t == '`':
self.in_code = False
text.append('%s' % t) text.append('%s' % t)
# Soft scene breaks. # Soft scene breaks.
@ -247,6 +253,8 @@ class MarkdownMLizer(OEB2HTML):
tail = elem.tail tail = elem.tail
if self.in_pre: if self.in_pre:
tail = self.prepare_string_for_pre(tail) tail = self.prepare_string_for_pre(tail)
elif self.in_code:
tail = self.remove_newlines(tail)
else: else:
tail = self.prepare_string_for_markdown(self.remove_newlines(tail)) tail = self.prepare_string_for_markdown(self.remove_newlines(tail))
text.append(tail) text.append(tail)