Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ strong_em_symbol
*emphasized* texts. Either of these symbols can be chosen by the options
``ASTERISK`` (default) or ``UNDERSCORE`` respectively.

strong_symbol
Like ``strong_em_symbol``, but only affects **strong** texts. Allows setting
a different symbol from ``em``. Can be chosen by the options ``ASTERISK``
or ``UNDERSCORE`` respectively, or ``None`` (default) to use
``strong_em_symbol`` for both strong and emphasized texts.

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
Expand Down
3 changes: 2 additions & 1 deletion markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class DefaultOptions:
strip_document = STRIP
strip_pre = STRIP
strong_em_symbol = ASTERISK
strong_symbol = None
sub_symbol = ''
sup_symbol = ''
table_infer_header = False
Expand Down Expand Up @@ -455,7 +456,7 @@ def convert_a(self, el, text, parent_tags):
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
return '%s[%s](%s%s)%s' % (prefix, text, href, title_part, suffix) if href else text

convert_b = abstract_inline_conversion(lambda self: 2 * self.options['strong_em_symbol'])
convert_b = abstract_inline_conversion(lambda self: 2 * (self.options['strong_symbol'] or self.options['strong_em_symbol']))

def convert_blockquote(self, el, text, parent_tags):
# handle some early-exit scenarios
Expand Down
2 changes: 2 additions & 0 deletions markdownify/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def markdownify(
strip_document: Union[str, None] = ...,
strip_pre: str = ...,
strong_em_symbol: str = ...,
strong_symbol: str = ...,
sub_symbol: str = ...,
sup_symbol: str = ...,
table_infer_header: bool = ...,
Expand Down Expand Up @@ -62,6 +63,7 @@ class MarkdownConverter:
strip_document: Union[str, None] = ...,
strip_pre: str = ...,
strong_em_symbol: str = ...,
strong_symbol: str = ...,
sub_symbol: str = ...,
sup_symbol: str = ...,
table_infer_header: bool = ...,
Expand Down
1 change: 1 addition & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ 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_'
assert md('<b>He</b><em>llo</em>', strong_em_symbol=UNDERSCORE, strong_symbol=ASTERISK) == '**He**_llo_'


def test_sub():
Expand Down
2 changes: 2 additions & 0 deletions tests/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
strip_document=STRIP,
strip_pre=STRIP,
strong_em_symbol=ASTERISK,
strong_symbol=ASTERISK,
sub_symbol='',
sup_symbol='',
table_infer_header=False,
Expand All @@ -50,6 +51,7 @@
wrap=True,
wrap_width=80,
strong_em_symbol=UNDERSCORE,
strong_symbol=UNDERSCORE,
code_language='python',
code_language_callback=None
).convert("")
Expand Down