Skip to content

Commit a6a3162

Browse files
committed
add options for sub and sup tags
fixes matthewwithanm#44
1 parent 6f37323 commit a6a3162

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ strong_em_symbol
8484
*emphasized* texts. Either of these symbols can be chosen by the options
8585
``ASTERISK`` (default) or ``UNDERSCORE`` respectively.
8686

87+
sub_symbol, sup_symbol
88+
Define the chars that surround ``<sub>`` and ``<sup>`` text. Defaults to an
89+
empty string, because this is non-standard behavior. Could be something like
90+
``~`` and ``^`` to result in ``~sub~`` and ``^sup^``.
91+
8792
newline_style
8893
Defines the style of marking linebreaks (``<br>``) in markdown. The default
8994
value ``SPACES`` of this option will adopt the usual two spaces and a newline,

markdownify/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ def _todict(obj):
6666

6767
class MarkdownConverter(object):
6868
class DefaultOptions:
69-
strip = None
70-
convert = None
7169
autolinks = True
70+
bullets = '*+-' # An iterable of bullet types.
71+
convert = None
7272
default_title = False
7373
heading_style = UNDERLINED
74-
bullets = '*+-' # An iterable of bullet types.
75-
strong_em_symbol = ASTERISK
7674
newline_style = SPACES
75+
strip = None
76+
strong_em_symbol = ASTERISK
77+
sub_symbol = ''
78+
sup_symbol = ''
7779

7880
class Options(DefaultOptions):
7981
pass
@@ -325,6 +327,10 @@ def convert_pre(self, el, text, convert_as_inline):
325327

326328
convert_samp = convert_code
327329

330+
convert_sub = abstract_inline_conversion(lambda self: self.options['sub_symbol'])
331+
332+
convert_sup = abstract_inline_conversion(lambda self: self.options['sup_symbol'])
333+
328334
def convert_table(self, el, text, convert_as_inline):
329335
return '\n\n' + text + '\n'
330336

tests/test_conversions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,13 @@ def test_strong_em_symbol():
201201
assert md('<b>Hello</b>', strong_em_symbol=UNDERSCORE) == '__Hello__'
202202
assert md('<em>Hello</em>', strong_em_symbol=UNDERSCORE) == '_Hello_'
203203
assert md('<i>Hello</i>', strong_em_symbol=UNDERSCORE) == '_Hello_'
204+
205+
206+
def test_sub():
207+
assert md('<sub>foo</sub>') == 'foo'
208+
assert md('<sub>foo</sub>', sub_symbol='~') == '~foo~'
209+
210+
211+
def test_sup():
212+
assert md('<sup>foo</sup>') == 'foo'
213+
assert md('<sup>foo</sup>', sup_symbol='^') == '^foo^'

0 commit comments

Comments
 (0)