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. should be annotated with `````python`` or similar.
Defaults to ``''`` (empty string) and can be any string. 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 Options may be specified as kwargs to the ``markdownify`` function, or as a
nested ``Options`` class in ``MarkdownConverter`` subclasses. nested ``Options`` class in ``MarkdownConverter`` subclasses.

View File

@@ -25,10 +25,12 @@ ASTERISK = '*'
UNDERSCORE = '_' UNDERSCORE = '_'
def escape(text): def escape(text, escape_underscores):
if not text: if not text:
return '' return ''
return text.replace('_', r'\_') if escape_underscores:
return text.replace('_', r'\_')
return text
def chomp(text): def chomp(text):
@@ -68,15 +70,16 @@ class MarkdownConverter(object):
class DefaultOptions: class DefaultOptions:
autolinks = True autolinks = True
bullets = '*+-' # An iterable of bullet types. bullets = '*+-' # An iterable of bullet types.
code_language = ''
convert = None convert = None
default_title = False default_title = False
escape_underscores = True
heading_style = UNDERLINED heading_style = UNDERLINED
newline_style = SPACES newline_style = SPACES
strip = None strip = None
strong_em_symbol = ASTERISK strong_em_symbol = ASTERISK
sub_symbol = '' sub_symbol = ''
sup_symbol = '' sup_symbol = ''
code_language = ''
class Options(DefaultOptions): class Options(DefaultOptions):
pass pass
@@ -155,7 +158,7 @@ class MarkdownConverter(object):
text = whitespace_re.sub(' ', text) text = whitespace_re.sub(' ', text)
if el.parent.name != 'code': 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: # remove trailing whitespaces if any of the following condition is true:
# - current text node is the last node in li # - 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 = { pkgmeta = {
'__title__': 'markdownify', '__title__': 'markdownify',
'__author__': 'Matthew Tretter', '__author__': 'Matthew Tretter',
'__version__': '0.10.0', '__version__': '0.10.2',
} }
@@ -70,7 +70,7 @@ setup(
zip_safe=False, zip_safe=False,
include_package_data=True, include_package_data=True,
setup_requires=[ setup_requires=[
'flake8>=3.8,<4', 'flake8>=3.8,<5',
], ],
tests_require=[ tests_require=[
'pytest>=6.2,<7', 'pytest>=6.2,<7',

View File

@@ -3,6 +3,7 @@ from markdownify import markdownify as md
def test_underscore(): def test_underscore():
assert md('_hey_dude_') == r'\_hey\_dude\_' assert md('_hey_dude_') == r'\_hey\_dude\_'
assert md('_hey_dude_', escape_underscores=False) == r'_hey_dude_'
def test_xml_entities(): def test_xml_entities():