ordering functions alphabetically
This commit is contained in:
@@ -198,6 +198,12 @@ class MarkdownConverter(object):
|
|||||||
else:
|
else:
|
||||||
return ' \n'
|
return ' \n'
|
||||||
|
|
||||||
|
def convert_code(self, el, text, convert_as_inline):
|
||||||
|
prefix, suffix, text = chomp(text)
|
||||||
|
if not text:
|
||||||
|
return ''
|
||||||
|
return '%s`%s`%s' % (prefix, text, suffix)
|
||||||
|
|
||||||
def convert_em(self, el, text, convert_as_inline):
|
def convert_em(self, el, text, convert_as_inline):
|
||||||
em_tag = self.options['strong_em_symbol']
|
em_tag = self.options['strong_em_symbol']
|
||||||
prefix, suffix, text = chomp(text)
|
prefix, suffix, text = chomp(text)
|
||||||
@@ -205,17 +211,7 @@ class MarkdownConverter(object):
|
|||||||
return ''
|
return ''
|
||||||
return '%s%s%s%s%s' % (prefix, em_tag, text, em_tag, suffix)
|
return '%s%s%s%s%s' % (prefix, em_tag, text, em_tag, suffix)
|
||||||
|
|
||||||
def convert_code(self, el, text, convert_as_inline):
|
convert_kbd = convert_code
|
||||||
prefix, suffix, text = chomp(text)
|
|
||||||
if not text:
|
|
||||||
return ''
|
|
||||||
return '%s`%s`%s' % (prefix, text, suffix)
|
|
||||||
|
|
||||||
def convert_samp(self, el, text, convert_as_inline):
|
|
||||||
return self.convert_code(el, text, convert_as_inline)
|
|
||||||
|
|
||||||
def convert_kbd(self, el, text, convert_as_inline):
|
|
||||||
return self.convert_code(el, text, convert_as_inline)
|
|
||||||
|
|
||||||
def convert_hn(self, n, el, text, convert_as_inline):
|
def convert_hn(self, n, el, text, convert_as_inline):
|
||||||
if convert_as_inline:
|
if convert_as_inline:
|
||||||
@@ -231,9 +227,22 @@ class MarkdownConverter(object):
|
|||||||
return '%s %s %s\n\n' % (hashes, text, hashes)
|
return '%s %s %s\n\n' % (hashes, text, hashes)
|
||||||
return '%s %s\n\n' % (hashes, text)
|
return '%s %s\n\n' % (hashes, text)
|
||||||
|
|
||||||
|
def convert_hr(self, el, text, convert_as_inline):
|
||||||
|
return '\n\n---\n\n'
|
||||||
|
|
||||||
def convert_i(self, el, text, convert_as_inline):
|
def convert_i(self, el, text, convert_as_inline):
|
||||||
return self.convert_em(el, text, convert_as_inline)
|
return self.convert_em(el, text, convert_as_inline)
|
||||||
|
|
||||||
|
def convert_img(self, el, text, convert_as_inline):
|
||||||
|
alt = el.attrs.get('alt', None) or ''
|
||||||
|
src = el.attrs.get('src', None) or ''
|
||||||
|
title = el.attrs.get('title', None) or ''
|
||||||
|
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
|
||||||
|
if convert_as_inline:
|
||||||
|
return alt
|
||||||
|
|
||||||
|
return '' % (alt, src, title_part)
|
||||||
|
|
||||||
def convert_list(self, el, text, convert_as_inline):
|
def convert_list(self, el, text, convert_as_inline):
|
||||||
|
|
||||||
# Converting a list to inline is undefined.
|
# Converting a list to inline is undefined.
|
||||||
@@ -286,19 +295,17 @@ class MarkdownConverter(object):
|
|||||||
return ''
|
return ''
|
||||||
return '%s%s%s%s%s' % (prefix, strong_tag, text, strong_tag, suffix)
|
return '%s%s%s%s%s' % (prefix, strong_tag, text, strong_tag, suffix)
|
||||||
|
|
||||||
def convert_img(self, el, text, convert_as_inline):
|
convert_samp = convert_code
|
||||||
alt = el.attrs.get('alt', None) or ''
|
|
||||||
src = el.attrs.get('src', None) or ''
|
|
||||||
title = el.attrs.get('title', None) or ''
|
|
||||||
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
|
|
||||||
if convert_as_inline:
|
|
||||||
return alt
|
|
||||||
|
|
||||||
return '' % (alt, src, title_part)
|
|
||||||
|
|
||||||
def convert_table(self, el, text, convert_as_inline):
|
def convert_table(self, el, text, convert_as_inline):
|
||||||
return '\n\n' + text + '\n'
|
return '\n\n' + text + '\n'
|
||||||
|
|
||||||
|
def convert_td(self, el, text, convert_as_inline):
|
||||||
|
return ' ' + text + ' |'
|
||||||
|
|
||||||
|
def convert_th(self, el, text, convert_as_inline):
|
||||||
|
return ' ' + text + ' |'
|
||||||
|
|
||||||
def convert_tr(self, el, text, convert_as_inline):
|
def convert_tr(self, el, text, convert_as_inline):
|
||||||
cells = el.find_all(['td', 'th'])
|
cells = el.find_all(['td', 'th'])
|
||||||
is_headrow = all([cell.name == 'th' for cell in cells])
|
is_headrow = all([cell.name == 'th' for cell in cells])
|
||||||
@@ -314,15 +321,6 @@ class MarkdownConverter(object):
|
|||||||
overline += '| ' + ' | '.join(['---'] * len(cells)) + ' |' + '\n'
|
overline += '| ' + ' | '.join(['---'] * len(cells)) + ' |' + '\n'
|
||||||
return overline + '|' + text + '\n' + underline
|
return overline + '|' + text + '\n' + underline
|
||||||
|
|
||||||
def convert_th(self, el, text, convert_as_inline):
|
|
||||||
return ' ' + text + ' |'
|
|
||||||
|
|
||||||
def convert_td(self, el, text, convert_as_inline):
|
|
||||||
return ' ' + text + ' |'
|
|
||||||
|
|
||||||
def convert_hr(self, el, text, convert_as_inline):
|
|
||||||
return '\n\n---\n\n'
|
|
||||||
|
|
||||||
|
|
||||||
def markdownify(html, **options):
|
def markdownify(html, **options):
|
||||||
return MarkdownConverter(**options).convert(html)
|
return MarkdownConverter(**options).convert(html)
|
||||||
|
|||||||
Reference in New Issue
Block a user