Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28793ac0b3 | ||
|
|
d3eff11617 | ||
|
|
bd6b581122 | ||
|
|
9231704988 | ||
|
|
c8f7cf63e3 | ||
|
|
12a68a7d14 |
@@ -102,6 +102,10 @@ code_language
|
||||
should be annotated with `````python`` or similar.
|
||||
Defaults to ``''`` (empty string) and can be any string.
|
||||
|
||||
escape_underscores
|
||||
If set to ``False``, do not escape ``_`` to ``\_`` in text.
|
||||
Defaults to ``True``.
|
||||
|
||||
Options may be specified as kwargs to the ``markdownify`` function, or as a
|
||||
nested ``Options`` class in ``MarkdownConverter`` subclasses.
|
||||
|
||||
|
||||
@@ -25,10 +25,12 @@ ASTERISK = '*'
|
||||
UNDERSCORE = '_'
|
||||
|
||||
|
||||
def escape(text):
|
||||
def escape(text, escape_underscores):
|
||||
if not text:
|
||||
return ''
|
||||
return text.replace('_', r'\_')
|
||||
if escape_underscores:
|
||||
return text.replace('_', r'\_')
|
||||
return text
|
||||
|
||||
|
||||
def chomp(text):
|
||||
@@ -68,15 +70,16 @@ class MarkdownConverter(object):
|
||||
class DefaultOptions:
|
||||
autolinks = True
|
||||
bullets = '*+-' # An iterable of bullet types.
|
||||
code_language = ''
|
||||
convert = None
|
||||
default_title = False
|
||||
escape_underscores = True
|
||||
heading_style = UNDERLINED
|
||||
newline_style = SPACES
|
||||
strip = None
|
||||
strong_em_symbol = ASTERISK
|
||||
sub_symbol = ''
|
||||
sup_symbol = ''
|
||||
code_language = ''
|
||||
|
||||
class Options(DefaultOptions):
|
||||
pass
|
||||
@@ -155,7 +158,7 @@ class MarkdownConverter(object):
|
||||
text = whitespace_re.sub(' ', text)
|
||||
|
||||
if el.parent.name != 'code':
|
||||
text = escape(text)
|
||||
text = escape(text, self.options['escape_underscores'])
|
||||
|
||||
# remove trailing whitespaces if any of the following condition is true:
|
||||
# - current text node is the last node in li
|
||||
|
||||
4
setup.py
4
setup.py
@@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
||||
pkgmeta = {
|
||||
'__title__': 'markdownify',
|
||||
'__author__': 'Matthew Tretter',
|
||||
'__version__': '0.10.0',
|
||||
'__version__': '0.10.2',
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ setup(
|
||||
zip_safe=False,
|
||||
include_package_data=True,
|
||||
setup_requires=[
|
||||
'flake8>=3.8,<4',
|
||||
'flake8>=3.8,<5',
|
||||
],
|
||||
tests_require=[
|
||||
'pytest>=6.2,<7',
|
||||
|
||||
@@ -3,6 +3,7 @@ from markdownify import markdownify as md
|
||||
|
||||
def test_underscore():
|
||||
assert md('_hey_dude_') == r'\_hey\_dude\_'
|
||||
assert md('_hey_dude_', escape_underscores=False) == r'_hey_dude_'
|
||||
|
||||
|
||||
def test_xml_entities():
|
||||
|
||||
Reference in New Issue
Block a user