Merge pull request #37 from andredelft/develop
Add `strong_em_symbol` and `newline` options to the converter
This commit is contained in:
@@ -15,6 +15,14 @@ ATX_CLOSED = 'atx_closed'
|
||||
UNDERLINED = 'underlined'
|
||||
SETEXT = UNDERLINED
|
||||
|
||||
# Newline style
|
||||
SPACES = 'spaces'
|
||||
BACKSLASH = 'backslash'
|
||||
|
||||
# Strong and emphasis style
|
||||
ASTERISK = '*'
|
||||
UNDERSCORE = '_'
|
||||
|
||||
|
||||
def escape(text):
|
||||
if not text:
|
||||
@@ -46,6 +54,8 @@ class MarkdownConverter(object):
|
||||
autolinks = True
|
||||
heading_style = UNDERLINED
|
||||
bullets = '*+-' # An iterable of bullet types.
|
||||
strong_em_symbol = ASTERISK
|
||||
newline_style = SPACES
|
||||
|
||||
class Options(DefaultOptions):
|
||||
pass
|
||||
@@ -154,19 +164,23 @@ class MarkdownConverter(object):
|
||||
if convert_as_inline:
|
||||
return ""
|
||||
|
||||
return ' \n'
|
||||
if self.options['newline_style'].lower() == BACKSLASH:
|
||||
return '\\\n'
|
||||
else:
|
||||
return ' \n'
|
||||
|
||||
def convert_em(self, el, text, convert_as_inline):
|
||||
em_tag = self.options['strong_em_symbol']
|
||||
prefix, suffix, text = chomp(text)
|
||||
if not text:
|
||||
return ''
|
||||
return '%s*%s*%s' % (prefix, text, suffix)
|
||||
return '%s%s%s%s%s' % (prefix, em_tag, text, em_tag, suffix)
|
||||
|
||||
def convert_hn(self, n, el, text, convert_as_inline):
|
||||
if convert_as_inline:
|
||||
return text
|
||||
|
||||
style = self.options['heading_style']
|
||||
style = self.options['heading_style'].lower()
|
||||
text = text.rstrip()
|
||||
if style == UNDERLINED and n <= 2:
|
||||
line = '=' if n == 1 else '-'
|
||||
@@ -222,10 +236,11 @@ class MarkdownConverter(object):
|
||||
return '%s\n\n' % text if text else ''
|
||||
|
||||
def convert_strong(self, el, text, convert_as_inline):
|
||||
strong_tag = 2 * self.options['strong_em_symbol']
|
||||
prefix, suffix, text = chomp(text)
|
||||
if not text:
|
||||
return ''
|
||||
return '%s**%s**%s' % (prefix, text, suffix)
|
||||
return '%s%s%s%s%s' % (prefix, strong_tag, text, strong_tag, suffix)
|
||||
|
||||
def convert_img(self, el, text, convert_as_inline):
|
||||
alt = el.attrs.get('alt', None) or ''
|
||||
|
||||
Reference in New Issue
Block a user