Skip to content

Commit 9c3c3d6

Browse files
Add strong_symbol option
Fixes #251
1 parent add391a commit 9c3c3d6

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

README.rst

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

87+
strong_symbol
88+
Like ``strong_em_symbol``, but only affects **strong** texts. Allows setting
89+
a different symbol from ``em``. Can be chosen by the options ``ASTERISK``
90+
or ``UNDERSCORE`` respectively, or ``None`` (default) to use
91+
``strong_em_symbol`` for both strong and emphasized texts.
92+
8793
sub_symbol, sup_symbol
8894
Define the chars that surround ``<sub>`` and ``<sup>`` text. Defaults to an
8995
empty string, because this is non-standard behavior. Could be something like

markdownify/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ class DefaultOptions:
192192
strip_document = STRIP
193193
strip_pre = STRIP
194194
strong_em_symbol = ASTERISK
195+
strong_symbol = None
195196
sub_symbol = ''
196197
sup_symbol = ''
197198
table_infer_header = False
@@ -455,7 +456,7 @@ def convert_a(self, el, text, parent_tags):
455456
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
456457
return '%s[%s](%s%s)%s' % (prefix, text, href, title_part, suffix) if href else text
457458

458-
convert_b = abstract_inline_conversion(lambda self: 2 * self.options['strong_em_symbol'])
459+
convert_b = abstract_inline_conversion(lambda self: 2 * (self.options['strong_symbol'] or self.options['strong_em_symbol']))
459460

460461
def convert_blockquote(self, el, text, parent_tags):
461462
# handle some early-exit scenarios

markdownify/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def markdownify(
3434
strip_document: Union[str, None] = ...,
3535
strip_pre: str = ...,
3636
strong_em_symbol: str = ...,
37+
strong_symbol: str = ...,
3738
sub_symbol: str = ...,
3839
sup_symbol: str = ...,
3940
table_infer_header: bool = ...,
@@ -62,6 +63,7 @@ class MarkdownConverter:
6263
strip_document: Union[str, None] = ...,
6364
strip_pre: str = ...,
6465
strong_em_symbol: str = ...,
66+
strong_symbol: str = ...,
6567
sub_symbol: str = ...,
6668
sup_symbol: str = ...,
6769
table_infer_header: bool = ...,

tests/test_conversions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ def test_strong_em_symbol():
338338
assert md('<b>Hello</b>', strong_em_symbol=UNDERSCORE) == '__Hello__'
339339
assert md('<em>Hello</em>', strong_em_symbol=UNDERSCORE) == '_Hello_'
340340
assert md('<i>Hello</i>', strong_em_symbol=UNDERSCORE) == '_Hello_'
341+
assert md('<b>He</b><em>llo</em>', strong_em_symbol=UNDERSCORE, strong_symbol=ASTERISK) == '**He**_llo_'
341342

342343

343344
def test_sub():

tests/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
strip_document=STRIP,
2828
strip_pre=STRIP,
2929
strong_em_symbol=ASTERISK,
30+
strong_symbol=ASTERISK,
3031
sub_symbol='',
3132
sup_symbol='',
3233
table_infer_header=False,
@@ -50,6 +51,7 @@
5051
wrap=True,
5152
wrap_width=80,
5253
strong_em_symbol=UNDERSCORE,
54+
strong_symbol=UNDERSCORE,
5355
code_language='python',
5456
code_language_callback=None
5557
).convert("")

0 commit comments

Comments
 (0)