Introduce OPTIONs for strong_em_symbol
This commit is contained in:
10
README.rst
10
README.rst
@@ -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.
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user