add options for sub and sup tags

fixes #44
This commit is contained in:
AlexVonB
2021-05-30 19:07:43 +02:00
parent 6f3732307d
commit a6a31624ad
3 changed files with 25 additions and 4 deletions

View File

@@ -84,6 +84,11 @@ strong_em_symbol
*emphasized* texts. Either of these symbols can be chosen by the options
``ASTERISK`` (default) or ``UNDERSCORE`` respectively.
sub_symbol, sup_symbol
Define the chars that surround ``<sub>`` and ``<sup>`` text. Defaults to an
empty string, because this is non-standard behavior. Could be something like
``~`` and ``^`` to result in ``~sub~`` and ``^sup^``.
newline_style
Defines the style of marking linebreaks (``<br>``) in markdown. The default
value ``SPACES`` of this option will adopt the usual two spaces and a newline,

View File

@@ -66,14 +66,16 @@ def _todict(obj):
class MarkdownConverter(object):
class DefaultOptions:
strip = None
convert = None
autolinks = True
bullets = '*+-' # An iterable of bullet types.
convert = None
default_title = False
heading_style = UNDERLINED
bullets = '*+-' # An iterable of bullet types.
strong_em_symbol = ASTERISK
newline_style = SPACES
strip = None
strong_em_symbol = ASTERISK
sub_symbol = ''
sup_symbol = ''
class Options(DefaultOptions):
pass
@@ -325,6 +327,10 @@ class MarkdownConverter(object):
convert_samp = convert_code
convert_sub = abstract_inline_conversion(lambda self: self.options['sub_symbol'])
convert_sup = abstract_inline_conversion(lambda self: self.options['sup_symbol'])
def convert_table(self, el, text, convert_as_inline):
return '\n\n' + text + '\n'

View File

@@ -201,3 +201,13 @@ def test_strong_em_symbol():
assert md('<b>Hello</b>', strong_em_symbol=UNDERSCORE) == '__Hello__'
assert md('<em>Hello</em>', strong_em_symbol=UNDERSCORE) == '_Hello_'
assert md('<i>Hello</i>', strong_em_symbol=UNDERSCORE) == '_Hello_'
def test_sub():
assert md('<sub>foo</sub>') == 'foo'
assert md('<sub>foo</sub>', sub_symbol='~') == '~foo~'
def test_sup():
assert md('<sup>foo</sup>') == 'foo'
assert md('<sup>foo</sup>', sup_symbol='^') == '^foo^'