diff --git a/README.rst b/README.rst index 059a68f..0331660 100644 --- a/README.rst +++ b/README.rst @@ -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 ```` and ```` text. Defaults to an empty string, because this is non-standard behavior. Could be something like diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 148d340..60f4524 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -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 @@ -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 diff --git a/markdownify/__init__.pyi b/markdownify/__init__.pyi index 5f9b852..455b1d0 100644 --- a/markdownify/__init__.pyi +++ b/markdownify/__init__.pyi @@ -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 = ..., @@ -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 = ..., diff --git a/tests/test_conversions.py b/tests/test_conversions.py index dd99dfb..850af3c 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -338,6 +338,7 @@ def test_strong_em_symbol(): assert md('Hello', strong_em_symbol=UNDERSCORE) == '__Hello__' assert md('Hello', strong_em_symbol=UNDERSCORE) == '_Hello_' assert md('Hello', strong_em_symbol=UNDERSCORE) == '_Hello_' + assert md('Hello', strong_em_symbol=UNDERSCORE, strong_symbol=ASTERISK) == '**He**_llo_' def test_sub(): diff --git a/tests/types.py b/tests/types.py index 7424978..edde90c 100644 --- a/tests/types.py +++ b/tests/types.py @@ -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, @@ -50,6 +51,7 @@ wrap=True, wrap_width=80, strong_em_symbol=UNDERSCORE, + strong_symbol=UNDERSCORE, code_language='python', code_language_callback=None ).convert("")