Introduce OPTIONs for strong_em_symbol

This commit is contained in:
André van Delft
2021-04-18 18:13:29 +02:00
parent e877602a5e
commit 29c794e17d
3 changed files with 18 additions and 8 deletions

View File

@@ -76,10 +76,16 @@ bullets
level. Defaults to ``'*+-'``.
strong_em_symbol
In markdown, both ``*`` and ``_`` are used to encode **strong** or *emphasized* texts. The preferred symbol can be passed through this argument, that defaults to ``*``.
In markdown, both ``*`` and ``_`` are used to encode **strong** or
*emphasized* texts. Either of these symbols can be chosen by the options
``ASTERISK`` (default) or ``UNDERSCORE`` respectively.
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, while ``BACKSLASH`` will convert a linebreak to ``\\n`` (a backslash an a newline). While the latter convention is non-standard, it is commonly preferred and supported by a lot of interpreters.
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,
while ``BACKSLASH`` will convert a linebreak to ``\\n`` (a backslash an a
newline). While the latter convention is non-standard, it is commonly
preferred and supported by a lot of interpreters.
Options may be specified as kwargs to the ``markdownify`` function, or as a
nested ``Options`` class in ``MarkdownConverter`` subclasses.

View File

@@ -19,6 +19,10 @@ SETEXT = UNDERLINED
SPACES = 'spaces'
BACKSLASH = 'backslash'
# Strong and emphasis style
ASTERISK = '*'
UNDERSCORE = '_'
def escape(text):
if not text:
@@ -50,7 +54,7 @@ class MarkdownConverter(object):
autolinks = True
heading_style = UNDERLINED
bullets = '*+-' # An iterable of bullet types.
strong_em_symbol = '*'
strong_em_symbol = ASTERISK
newline_style = SPACES
class Options(DefaultOptions):

View File

@@ -1,4 +1,4 @@
from markdownify import markdownify as md, ATX, ATX_CLOSED, BACKSLASH
from markdownify import markdownify as md, ATX, ATX_CLOSED, BACKSLASH, UNDERSCORE
import re
@@ -219,10 +219,10 @@ def test_div():
def test_strong_em_symbol():
assert md('<strong>Hello</strong>', strong_em_symbol='_') == '__Hello__'
assert md('<b>Hello</b>', strong_em_symbol='_') == '__Hello__'
assert md('<em>Hello</em>', strong_em_symbol='_') == '_Hello_'
assert md('<i>Hello</i>', strong_em_symbol='_') == '_Hello_'
assert md('<strong>Hello</strong>', strong_em_symbol=UNDERSCORE) == '__Hello__'
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_newline_style():