Compare commits

..

6 Commits

Author SHA1 Message Date
AlexVonB
28793ac0b3 Merge branch 'develop' 2022-01-18 08:56:33 +01:00
AlexVonB
d3eff11617 bump to v0.10.2 2022-01-18 08:53:33 +01:00
AlexVonB
bd6b581122 add option to not escape underscores
closes #59
2022-01-18 08:51:44 +01:00
AlexVonB
9231704988 Merge branch 'develop' 2021-12-11 14:44:58 +01:00
AlexVonB
c8f7cf63e3 bump to v0.10.1 2021-12-11 14:44:34 +01:00
AlexVonB
12a68a7d14 allow flake8 v4.x
closes #57
2021-12-11 14:43:14 +01:00
4 changed files with 14 additions and 6 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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',

View File

@@ -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():