File tree Expand file tree Collapse file tree 4 files changed +13
-5
lines changed Expand file tree Collapse file tree 4 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,10 @@ code_language
102102 should be annotated with `````python `` or similar.
103103 Defaults to ``'' `` (empty string) and can be any string.
104104
105+ escape_underscores
106+ If set to ``False ``, do not escape ``_ `` to ``\_ `` in text.
107+ Defaults to ``True ``.
108+
105109Options may be specified as kwargs to the ``markdownify `` function, or as a
106110nested ``Options `` class in ``MarkdownConverter `` subclasses.
107111
Original file line number Diff line number Diff line change 2525UNDERSCORE = '_'
2626
2727
28- def escape (text ):
28+ def escape (text , escape_underscores ):
2929 if not text :
3030 return ''
31- return text .replace ('_' , r'\_' )
31+ if escape_underscores :
32+ return text .replace ('_' , r'\_' )
33+ return text
3234
3335
3436def chomp (text ):
@@ -68,15 +70,16 @@ class MarkdownConverter(object):
6870 class DefaultOptions :
6971 autolinks = True
7072 bullets = '*+-' # An iterable of bullet types.
73+ code_language = ''
7174 convert = None
7275 default_title = False
76+ escape_underscores = True
7377 heading_style = UNDERLINED
7478 newline_style = SPACES
7579 strip = None
7680 strong_em_symbol = ASTERISK
7781 sub_symbol = ''
7882 sup_symbol = ''
79- code_language = ''
8083
8184 class Options (DefaultOptions ):
8285 pass
@@ -155,7 +158,7 @@ def process_text(self, el):
155158 text = whitespace_re .sub (' ' , text )
156159
157160 if el .parent .name != 'code' :
158- text = escape (text )
161+ text = escape (text , self . options [ 'escape_underscores' ] )
159162
160163 # remove trailing whitespaces if any of the following condition is true:
161164 # - current text node is the last node in li
Original file line number Diff line number Diff line change 1010pkgmeta = {
1111 '__title__' : 'markdownify' ,
1212 '__author__' : 'Matthew Tretter' ,
13- '__version__' : '0.10.1 ' ,
13+ '__version__' : '0.10.2 ' ,
1414}
1515
1616
Original file line number Diff line number Diff line change 33
44def test_underscore ():
55 assert md ('_hey_dude_' ) == r'\_hey\_dude\_'
6+ assert md ('_hey_dude_' , escape_underscores = False ) == r'_hey_dude_'
67
78
89def test_xml_entities ():
You can’t perform that action at this time.
0 commit comments